@@ -40,7 +40,7 @@ extern "C" {
4040static bool
4141sentry__breakpad_backend_callback (const wchar_t *breakpad_dump_path,
4242 const wchar_t *minidump_id, void *UNUSED (context),
43- EXCEPTION_POINTERS *UNUSED( exinfo) , MDRawAssertionInfo *UNUSED(assertion),
43+ EXCEPTION_POINTERS *exinfo, MDRawAssertionInfo *UNUSED(assertion),
4444 bool succeeded)
4545#elif defined(SENTRY_PLATFORM_DARWIN)
4646static bool
@@ -92,45 +92,64 @@ sentry__breakpad_backend_callback(
9292 dump_path = sentry__path_new (descriptor.path ());
9393#endif
9494
95+ bool capture_crash = true ;
96+
9597 SENTRY_WITH_OPTIONS (options) {
9698 sentry__write_crash_marker (options);
9799
98- sentry_value_t event = sentry_value_new_event ();
99- sentry_envelope_t *envelope
100- = sentry__prepare_event (options, event, NULL );
101- // the event we just prepared is empty, so no error is recorded for it
102- sentry__record_errors_on_current_session (1 );
103- sentry_session_t *session = sentry__end_current_session_with_status (
104- SENTRY_SESSION_STATUS_CRASHED);
105- sentry__envelope_add_session (envelope, session);
106-
107- // the minidump is added as an attachment, with type `event.minidump`
108- sentry_envelope_item_t *item
109- = sentry__envelope_add_from_path (envelope, dump_path, " attachment" );
110- if (item) {
111- sentry__envelope_item_set_header (item, " attachment_type" ,
112- sentry_value_new_string (" event.minidump" ));
113-
114- sentry__envelope_item_set_header (item, " filename" ,
115100#ifdef SENTRY_PLATFORM_WINDOWS
116- sentry__value_new_string_from_wstr (
101+ if (options->on_crash_func ) {
102+ sentry_ucontext_t uctx;
103+ uctx.exception_ptrs = *exinfo;
104+
105+ SENTRY_TRACE (" invoking `on_crash` hook" );
106+ capture_crash
107+ = options->on_crash_func (&uctx, options->on_crash_data );
108+ }
109+ #endif
110+
111+ if (capture_crash) {
112+ sentry_value_t event = sentry_value_new_event ();
113+ sentry_envelope_t *envelope
114+ = sentry__prepare_event (options, event, NULL );
115+ // the event we just prepared is empty,
116+ // so no error is recorded for it
117+ sentry__record_errors_on_current_session (1 );
118+ sentry_session_t *session = sentry__end_current_session_with_status (
119+ SENTRY_SESSION_STATUS_CRASHED);
120+ sentry__envelope_add_session (envelope, session);
121+
122+ // the minidump is added as an attachment,
123+ // with type `event.minidump`
124+ sentry_envelope_item_t *item = sentry__envelope_add_from_path (
125+ envelope, dump_path, " attachment" );
126+ if (item) {
127+ sentry__envelope_item_set_header (item, " attachment_type" ,
128+ sentry_value_new_string (" event.minidump" ));
129+
130+ sentry__envelope_item_set_header (item, " filename" ,
131+ #ifdef SENTRY_PLATFORM_WINDOWS
132+ sentry__value_new_string_from_wstr (
117133#else
118- sentry_value_new_string (
134+ sentry_value_new_string (
119135#endif
120- sentry__path_filename (dump_path)));
121- }
136+ sentry__path_filename (dump_path)));
137+ }
122138
123- // capture the envelope with the disk transport
124- sentry_transport_t *disk_transport
125- = sentry_new_disk_transport (options->run );
126- sentry__capture_envelope (disk_transport, envelope);
127- sentry__transport_dump_queue (disk_transport, options->run );
128- sentry_transport_free (disk_transport);
129-
130- // now that the envelope was written, we can remove the temporary
131- // minidump file
132- sentry__path_remove (dump_path);
133- sentry__path_free (dump_path);
139+ // capture the envelope with the disk transport
140+ sentry_transport_t *disk_transport
141+ = sentry_new_disk_transport (options->run );
142+ sentry__capture_envelope (disk_transport, envelope);
143+ sentry__transport_dump_queue (disk_transport, options->run );
144+ sentry_transport_free (disk_transport);
145+
146+ // now that the envelope was written, we can remove the temporary
147+ // minidump file
148+ sentry__path_remove (dump_path);
149+ sentry__path_free (dump_path);
150+ } else {
151+ SENTRY_TRACE (" event was discarded by the `on_crash` hook" );
152+ }
134153
135154 // after capturing the crash event, try to dump all the in-flight
136155 // data of the previous transports
0 commit comments