Proposal: official crashpad handler as application exe
We've recently updated from breakpad to crashpad. Our executable is signed and it keeps things simpler and reduces duplication on disk to minimize the number of executables in our application. So instead of having a separate crashpad_handler.exe, we were able to link the libraries that crashpad_handler uses into our main executable and call crashpad::HandlerMain when we detect we're being invoked to run as the crashpad_handler.
To get this working, we use this sentry-native repo as a submodule.
We use the corresponding CMake files, i.e.
add_subdirectory("vendor/sentry" ${CMAKE_CURRENT_BINARY_DIR}/sentry)
Then we link these libraries into our executable:
target_link_libraries(our_executable
PRIVATE
crashpad_client
crashpad_getopt
crashpad_handler_lib
crashpad_minidump
crashpad_snapshot
crashpad_tools
crashpad_util
mini_chromium
)
Then inside our application we add:
#include <handler/handler_main.h>
...
if (running_in_crashpad_mode) {
return crashpad::HandlerMain(argc, argv, NULL);
}
The last piece is how we detect we're running in "crashpad mode". We could have looked at the command-line parameters and likely inferred we're supposed to run in crashpad_handler mode, but to be more certain we still work across version updates, we employed a bit of a hack. We add a dummy "attachment" which gets passed on the command-line as --attachment=CrashpadMode. We then filter this extra dummy parameter when we forward argv to crashpad::HandlerMain.
We'd like to request sentry to consider this way of integrating crashpad as a new officially supported workflow. This should enable applications to upgrade to crashapd from the inproc/breakpad backends that weren't able to becuase of the extra executable requirement. Also note that this works today, but here's some things that would make it a bit easier:
1. CommandLine Identification
An officially supported mechanism for an application exe to know it should be running as the crashpad handler. Possibly something like this:
int sentry_cmdline_is_crashpad(int argc, char *argv[]);
int sentry_crashpad_main(int argc, char *argv[]);
#if _WIN32
int sentry_cmdline_is_crashpad_winmain(HINSTANCE, HINSTANCE, wchar_t*, int);
int sentry_crashpad_winmain(HINSTANCE, HINSTANCE, wchar_t*, int);
int sentry_cmdline_is_crashpadw(int argc, wchar_t *argv);
int sentry_crashpad_mainw(int argc, wchar_t *argv);
#endif
2. Only require linking against a single library to link in crashpad_handler
i.e.
target_link_libraries(our_exe PRIVATE crashpad_handler_libs)
I think this could be done with a bit of extra cmake.
3. Avoid conflicts with application headers by namespacing
#include <sentry/crashpad_handler/main.h>
Hey @marler8997, thanks for writing in and your suggestions! I'm putting this on our backlog as we don't have the bandwidth to tackle this atm. Happy to bump prio if we see demand for this.
I would love this