7#include <fuchsia/feedback/cpp/fidl.h>
8#include <fuchsia/mem/cpp/fidl.h>
11#include <zircon/status.h>
15#include "flutter/fml/logging.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,
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) {
119 <<
static_cast<uint32_t
>(
result.err());
DART_EXPORT Dart_Handle Dart_ErrorGetStackTrace(Dart_Handle handle)
struct _Dart_Handle * Dart_Handle
DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle)
DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object)
static const uint8_t buffer[]
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 data
std::string StdStringFromDart(Dart_Handle handle)