7#include <fuchsia/feedback/cpp/fidl.h>
8#include <fuchsia/mem/cpp/fidl.h>
11#include <zircon/status.h>
19static bool SetStackTrace(
const std::string&
data,
20 fuchsia::feedback::RuntimeCrashReport* report) {
21 uint64_t num_bytes =
data.size();
24 if (zx::vmo::create(num_bytes, 0u, &vmo) < 0) {
29 if (vmo.write(
data.data(), 0, num_bytes) < 0) {
34 fuchsia::mem::Buffer
buffer;
35 buffer.vmo = std::move(vmo);
37 report->set_exception_stack_trace(std::move(buffer));
42fuchsia::feedback::CrashReport BuildCrashReport(
43 const std::string& component_url,
44 const std::string&
error,
45 const std::string& stack_trace) {
48 std::string error_type;
49 std::string error_message;
50 const size_t delimiter_pos =
error.find_first_of(
':');
51 if (delimiter_pos == std::string::npos) {
52 FML_LOG(ERROR) <<
"error parsing Dart exception: expected format "
53 "'$RuntimeType: $Message', got '"
57 error_type =
"UnknownError";
58 error_message =
error;
60 error_type =
error.substr(0, delimiter_pos);
62 error.substr(delimiter_pos + 2 );
67 error_message = error_message.substr(
68 0, fuchsia::feedback::MAX_EXCEPTION_MESSAGE_LENGTH - 1);
70 fuchsia::feedback::RuntimeCrashReport dart_report;
71 dart_report.set_exception_type(error_type);
72 dart_report.set_exception_message(error_message);
73 if (!SetStackTrace(stack_trace, &dart_report)) {
74 FML_LOG(ERROR) <<
"Failed to convert Dart stack trace to VMO";
77 fuchsia::feedback::SpecificCrashReport specific_report;
78 specific_report.set_dart(std::move(dart_report));
79 fuchsia::feedback::CrashReport report;
80 report.set_program_name(component_url);
81 report.set_specific_report(std::move(specific_report));
82 report.set_is_fatal(
false);
91 const std::string& component_url,
93 if (!Dart_IsError(result) || !Dart_ErrorHasException(result)) {
97 const std::string
error =
99 const std::string stack_trace =
106 const std::string& component_url,
107 const std::string&
error,
108 const std::string& stack_trace) {
109 fuchsia::feedback::CrashReport crash_report =
110 BuildCrashReport(component_url,
error, stack_trace);
112 fuchsia::feedback::CrashReporterPtr crash_reporter =
113 services->Connect<fuchsia::feedback::CrashReporter>();
114 crash_reporter->FileReport(
115 std::move(crash_report),
116 [](fuchsia::feedback::CrashReporter_FileReport_Result result) {
117 if (result.is_err()) {
118 FML_LOG(ERROR) <<
"Failed to report Dart exception: "
119 <<
static_cast<uint32_t
>(result.err());
const uint8_t uint32_t uint32_t GError ** error
#define FML_LOG(severity)
void HandleIfException(std::shared_ptr<::sys::ServiceDirectory > services, const std::string &component_url, Dart_Handle result)
void HandleException(std::shared_ptr<::sys::ServiceDirectory > services, const std::string &component_url, const std::string &error, const std::string &stack_trace)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
std::string StdStringFromDart(Dart_Handle handle)
std::shared_ptr< const fml::Mapping > data