Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 49 additions & 11 deletions src/backends/sentry_backend_crashpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,36 @@ crashpad_register_wer_module(
}
#endif

static int
write_attachment(crashpad_state_t *state, const sentry_path_t *path,
const char *data, size_t size)
{
if (!path || !state || !state->client) {
return 1;
}
return state->client->WriteAttachment(
base::FilePath(SENTRY_PATH_PLATFORM_STR(path)),
std::string(data, size))
? 0
: 1;
}

static int
append_attachment(crashpad_state_t *state, const sentry_path_t *path,
const char *data, size_t size)
{
if (!path || !state || !state->client) {
return 1;
}
return state->client->AppendAttachment(
base::FilePath(SENTRY_PATH_PLATFORM_STR(path)),
std::string(data, size))
? 0
: 1;
}
Comment thread
jpnurmi marked this conversation as resolved.

static void
flush_scope_to_event(const sentry_path_t *event_path,
flush_scope_to_event(crashpad_state_t *state, const sentry_path_t *event_path,
const sentry_options_t *options, sentry_value_t crash_event)
{
SENTRY_WITH_SCOPE (scope) {
Expand All @@ -231,7 +259,7 @@ flush_scope_to_event(const sentry_path_t *event_path,
return;
}

int rv = sentry__path_write_buffer(event_path, mpack, mpack_size);
int rv = write_attachment(state, event_path, mpack, mpack_size);
sentry_free(mpack);

if (rv != 0) {
Expand All @@ -242,8 +270,9 @@ flush_scope_to_event(const sentry_path_t *event_path,
// Prepares an envelope with DSN, event ID, and session if available, for an
// external crash reporter.
static void
flush_external_crash_report(
const sentry_options_t *options, const sentry_uuid_t *crash_event_id)
flush_external_crash_report(crashpad_state_t *state,
const sentry_path_t *external_report_path, const sentry_options_t *options,
const sentry_uuid_t *crash_event_id)
{
sentry_envelope_t *envelope = sentry__envelope_new();
if (!envelope) {
Expand All @@ -258,7 +287,13 @@ flush_external_crash_report(
sentry__envelope_set_header(envelope, "cache_dir",
sentry_value_new_string(options->run->cache_path->path));
}
sentry__run_write_external(options->run, envelope);

size_t size = 0;
char *serialized = sentry_envelope_serialize(envelope, &size);
if (serialized) {
write_attachment(state, external_report_path, serialized, size);
sentry_free(serialized);
}
Comment thread
jpnurmi marked this conversation as resolved.
sentry_envelope_free(envelope);
}

Expand Down Expand Up @@ -294,9 +329,10 @@ crashpad_backend_flush_scope(
sentry_value_set_by_key(
event, "level", sentry__value_new_level(SENTRY_LEVEL_FATAL));

flush_scope_to_event(data->event_path, options, event);
flush_scope_to_event(data, data->event_path, options, event);
if (data->external_report_path) {
flush_external_crash_report(options, &data->crash_event_id);
flush_external_crash_report(
data, data->external_report_path, options, &data->crash_event_id);
}
data->scope_flush.store(false, std::memory_order_release);
#endif
Expand All @@ -321,9 +357,10 @@ flush_scope_from_handler(
}

// now we are the sole flusher and can flush into the crash event
flush_scope_to_event(state->event_path, options, crash_event);
flush_scope_to_event(state, state->event_path, options, crash_event);
if (state->external_report_path) {
flush_external_crash_report(options, &state->crash_event_id);
flush_external_crash_report(state, state->external_report_path, options,
&state->crash_event_id);
}
}

Expand Down Expand Up @@ -722,6 +759,7 @@ crashpad_backend_startup(
sentry_free(filename);

if (data->external_report_path) {
sentry__path_create_dir_all(options->run->external_path);
crash_reporter = base::FilePath(
SENTRY_PATH_PLATFORM_STR(options->external_crash_reporter));
crash_envelope = base::FilePath(
Expand Down Expand Up @@ -897,8 +935,8 @@ crashpad_backend_add_breadcrumb(sentry_backend_t *backend,
}

int rv = first_breadcrumb
? sentry__path_write_buffer(breadcrumb_file, mpack, mpack_size)
: sentry__path_append_buffer(breadcrumb_file, mpack, mpack_size);
? write_attachment(data, breadcrumb_file, mpack, mpack_size)
: append_attachment(data, breadcrumb_file, mpack, mpack_size);
sentry_free(mpack);

if (rv != 0) {
Comment thread
jpnurmi marked this conversation as resolved.
Expand Down
Loading