[crash] switch to async crash analysis

with the synchronous call, this actually blocks the Flutter component
from serving its out/directory and prevents the Inspect synchronous
discovery

DX-1568 #done #comment

TESTED=`fx shell run fuchsia-pkg://fuchsia.com/crasher_dart#meta/crasher_dart.cmx` (report id 0b59643af026bc37)
TESTED=`fx shell sessionctl add_mod fuchsia-pkg://fuchsia.com/crasher_flutter#meta/crasher_flutter.cmx` then clicked on "Th

Change-Id: I8b0abd1034dba66cd7bb1d6768322cab36ed453b

Ported from Topaz tree.
This commit is contained in:
Chris Bracken
2019-06-28 16:13:49 -07:00
parent c58d26f718
commit ab721c3db7
2 changed files with 30 additions and 39 deletions

View File

@@ -4,17 +4,16 @@
#include "runtime/dart/utils/handle_exception.h"
#include <string>
#include <fuchsia/crash/cpp/fidl.h>
#include <fuchsia/mem/cpp/fidl.h>
#include <lib/syslog/global.h>
#include <lib/zx/vmo.h>
#include <sys/types.h>
#include <third_party/tonic/converter/dart_converter.h>
#include <zircon/errors.h>
#include <zircon/status.h>
#include <string>
#include "runtime/dart/utils/logging.h"
namespace {
@@ -91,11 +90,11 @@ fuchsia::crash::ManagedRuntimeException BuildException(
namespace dart_utils {
zx_status_t HandleIfException(std::shared_ptr<::sys::ServiceDirectory> services,
const std::string& component_url,
Dart_Handle result) {
void HandleIfException(std::shared_ptr<::sys::ServiceDirectory> services,
const std::string& component_url,
Dart_Handle result) {
if (!Dart_IsError(result) || !Dart_ErrorHasException(result)) {
return ZX_OK;
return;
}
const std::string error =
@@ -106,34 +105,29 @@ zx_status_t HandleIfException(std::shared_ptr<::sys::ServiceDirectory> services,
return HandleException(services, component_url, error, stack_trace);
}
zx_status_t HandleException(std::shared_ptr<::sys::ServiceDirectory> services,
const std::string& component_url,
const std::string& error,
const std::string& stack_trace) {
void HandleException(std::shared_ptr<::sys::ServiceDirectory> services,
const std::string& component_url,
const std::string& error,
const std::string& stack_trace) {
fuchsia::crash::ManagedRuntimeException exception =
BuildException(error, stack_trace);
fuchsia::crash::AnalyzerSyncPtr analyzer;
services->Connect(analyzer.NewRequest());
fuchsia::crash::AnalyzerPtr analyzer =
services->Connect<fuchsia::crash::Analyzer>();
#ifndef NDEBUG
if (!analyzer) {
FX_LOG(FATAL, LOG_TAG, "Could not connect to analyzer service");
}
#endif
fuchsia::crash::Analyzer_OnManagedRuntimeException_Result out_result;
const zx_status_t status = analyzer->OnManagedRuntimeException(
component_url, std::move(exception), &out_result);
if (status != ZX_OK) {
FX_LOGF(ERROR, LOG_TAG, "Failed to connect to crash analyzer: %d (%s)",
status, zx_status_get_string(status));
return ZX_ERR_INTERNAL;
} else if (out_result.is_err()) {
FX_LOGF(ERROR, LOG_TAG, "Failed to handle Dart exception: %d (%s)",
out_result.err(), zx_status_get_string(out_result.err()));
return ZX_ERR_INTERNAL;
}
return ZX_OK;
analyzer->OnManagedRuntimeException(
component_url, std::move(exception),
[](fuchsia::crash::Analyzer_OnManagedRuntimeException_Result result) {
if (result.is_err()) {
FX_LOGF(ERROR, LOG_TAG, "Failed to handle Dart exception: %d (%s)",
result.err(), zx_status_get_string(result.err()));
}
});
}
} // namespace dart_utils

View File

@@ -5,29 +5,26 @@
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_HANDLE_EXCEPTION_H_
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_HANDLE_EXCEPTION_H_
#include <lib/sys/cpp/service_directory.h>
#include <third_party/dart/runtime/include/dart_api.h>
#include <memory>
#include <string>
#include <lib/sys/cpp/service_directory.h>
#include <sys/types.h>
#include <third_party/dart/runtime/include/dart_api.h>
namespace dart_utils {
// If |result| is a Dart Exception, passes the exception message and stack trace
// to the crash analyzer service for further handling.
//
// Otherwise early returns with OK status.
zx_status_t HandleIfException(std::shared_ptr<::sys::ServiceDirectory> services,
const std::string& component_url,
Dart_Handle result);
void HandleIfException(std::shared_ptr<::sys::ServiceDirectory> services,
const std::string& component_url,
Dart_Handle result);
// Passes the exception message and stack trace to the crash analyzer service
// for further handling.
zx_status_t HandleException(std::shared_ptr<::sys::ServiceDirectory> services,
const std::string& component_url,
const std::string& error,
const std::string& stack_trace);
void HandleException(std::shared_ptr<::sys::ServiceDirectory> services,
const std::string& component_url,
const std::string& error,
const std::string& stack_trace);
} // namespace dart_utils