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();
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)
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 vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
std::string StdStringFromDart(Dart_Handle handle)
std::shared_ptr< const fml::Mapping > data