Migrate from fuchsia.crash.Analyzer to fuchsia.feedback.CrashReporter (flutter/engine#12413)
Ported from Topaz
This commit is contained in:
@@ -27,7 +27,7 @@ source_set("utils") {
|
|||||||
]
|
]
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"$fuchsia_sdk_root/fidl:fuchsia.crash",
|
"$fuchsia_sdk_root/fidl:fuchsia.feedback",
|
||||||
"$fuchsia_sdk_root/fidl:fuchsia.mem",
|
"$fuchsia_sdk_root/fidl:fuchsia.mem",
|
||||||
"$fuchsia_sdk_root/pkg:async-loop",
|
"$fuchsia_sdk_root/pkg:async-loop",
|
||||||
"$fuchsia_sdk_root/pkg:async-loop-cpp",
|
"$fuchsia_sdk_root/pkg:async-loop-cpp",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "runtime/dart/utils/handle_exception.h"
|
#include "runtime/dart/utils/handle_exception.h"
|
||||||
|
|
||||||
#include <fuchsia/crash/cpp/fidl.h>
|
#include <fuchsia/feedback/cpp/fidl.h>
|
||||||
#include <fuchsia/mem/cpp/fidl.h>
|
#include <fuchsia/mem/cpp/fidl.h>
|
||||||
#include <lib/syslog/global.h>
|
#include <lib/syslog/global.h>
|
||||||
#include <lib/zx/vmo.h>
|
#include <lib/zx/vmo.h>
|
||||||
@@ -17,7 +17,8 @@
|
|||||||
#include "runtime/dart/utils/logging.h"
|
#include "runtime/dart/utils/logging.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static bool FillBuffer(const std::string& data, fuchsia::mem::Buffer* buffer) {
|
static bool SetStackTrace(const std::string& data,
|
||||||
|
fuchsia::feedback::RuntimeCrashReport* report) {
|
||||||
uint64_t num_bytes = data.size();
|
uint64_t num_bytes = data.size();
|
||||||
zx::vmo vmo;
|
zx::vmo vmo;
|
||||||
|
|
||||||
@@ -31,25 +32,16 @@ static bool FillBuffer(const std::string& data, fuchsia::mem::Buffer* buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->vmo = std::move(vmo);
|
fuchsia::mem::Buffer buffer;
|
||||||
buffer->size = num_bytes;
|
buffer.vmo = std::move(vmo);
|
||||||
|
buffer.size = num_bytes;
|
||||||
|
report->set_exception_stack_trace(std::move(buffer));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, size_t N>
|
fuchsia::feedback::CrashReport BuildCrashReport(
|
||||||
void CopyToArray(const std::string& s, std::array<T, N>* arr) {
|
const std::string& component_url,
|
||||||
const size_t max_size = arr->size();
|
|
||||||
auto end = s.end();
|
|
||||||
if (s.size() > max_size) {
|
|
||||||
FX_LOGF(WARNING, LOG_TAG, "truncating '%s' to %d characters", s.c_str(),
|
|
||||||
max_size);
|
|
||||||
end = s.begin() + max_size;
|
|
||||||
}
|
|
||||||
std::copy(s.begin(), end, arr->data());
|
|
||||||
}
|
|
||||||
|
|
||||||
fuchsia::crash::ManagedRuntimeException BuildException(
|
|
||||||
const std::string& error,
|
const std::string& error,
|
||||||
const std::string& stack_trace) {
|
const std::string& stack_trace) {
|
||||||
// The runtime type has already been pre-pended to the error message so we
|
// The runtime type has already been pre-pended to the error message so we
|
||||||
@@ -72,18 +64,19 @@ fuchsia::crash::ManagedRuntimeException BuildException(
|
|||||||
error.substr(delimiter_pos + 2 /*to get rid of the leading ': '*/);
|
error.substr(delimiter_pos + 2 /*to get rid of the leading ': '*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default-initialize to initialize the underlying arrays of characters with
|
fuchsia::feedback::RuntimeCrashReport dart_report;
|
||||||
// 0s and null-terminate the strings.
|
dart_report.set_exception_type(error_type);
|
||||||
fuchsia::crash::GenericException exception = {};
|
dart_report.set_exception_message(error_message);
|
||||||
CopyToArray(error_type, &exception.type);
|
if (!SetStackTrace(stack_trace, &dart_report)) {
|
||||||
CopyToArray(error_message, &exception.message);
|
|
||||||
if (!FillBuffer(stack_trace, &exception.stack_trace)) {
|
|
||||||
FX_LOG(ERROR, LOG_TAG, "Failed to convert Dart stack trace to VMO");
|
FX_LOG(ERROR, LOG_TAG, "Failed to convert Dart stack trace to VMO");
|
||||||
}
|
}
|
||||||
|
|
||||||
fuchsia::crash::ManagedRuntimeException dart_exception;
|
fuchsia::feedback::SpecificCrashReport specific_report;
|
||||||
dart_exception.set_dart(std::move(exception));
|
specific_report.set_dart(std::move(dart_report));
|
||||||
return dart_exception;
|
fuchsia::feedback::CrashReport report;
|
||||||
|
report.set_program_name(component_url);
|
||||||
|
report.set_specific_report(std::move(specific_report));
|
||||||
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -109,22 +102,16 @@ void HandleException(std::shared_ptr<::sys::ServiceDirectory> services,
|
|||||||
const std::string& component_url,
|
const std::string& component_url,
|
||||||
const std::string& error,
|
const std::string& error,
|
||||||
const std::string& stack_trace) {
|
const std::string& stack_trace) {
|
||||||
fuchsia::crash::ManagedRuntimeException exception =
|
fuchsia::feedback::CrashReport crash_report =
|
||||||
BuildException(error, stack_trace);
|
BuildCrashReport(component_url, error, stack_trace);
|
||||||
|
|
||||||
fuchsia::crash::AnalyzerPtr analyzer =
|
fuchsia::feedback::CrashReporterPtr crash_reporter =
|
||||||
services->Connect<fuchsia::crash::Analyzer>();
|
services->Connect<fuchsia::feedback::CrashReporter>();
|
||||||
#ifndef NDEBUG
|
crash_reporter->File(
|
||||||
if (!analyzer) {
|
std::move(crash_report),
|
||||||
FX_LOG(FATAL, LOG_TAG, "Could not connect to analyzer service");
|
[](fuchsia::feedback::CrashReporter_File_Result result) {
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
analyzer->OnManagedRuntimeException(
|
|
||||||
component_url, std::move(exception),
|
|
||||||
[](fuchsia::crash::Analyzer_OnManagedRuntimeException_Result result) {
|
|
||||||
if (result.is_err()) {
|
if (result.is_err()) {
|
||||||
FX_LOGF(ERROR, LOG_TAG, "Failed to handle Dart exception: %d (%s)",
|
FX_LOGF(ERROR, LOG_TAG, "Failed to report Dart exception: %d (%s)",
|
||||||
result.err(), zx_status_get_string(result.err()));
|
result.err(), zx_status_get_string(result.err()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user