Installing Crash Handlers in Cobalt

  • Partners can utilize Crashpad's crash handlers to generate crash reports within the cache directory.

  • Integrating Crashpad involves adding crash_handler.cc and crash_handler.h to the starboard_platform target's sources.

  • SbSystemGetExtension must handle kCobaltExtensionCrashHandlerName to enable crash handler functionality.

  • The InstallCrashpadHandler() hook should be invoked immediately following the installation of system crash handlers.

Partners can install Crashpad's crash handlers to create crash reports in the cache directory. This is done by:

  1. Adding the following files to the starboard_platform target's sources:
"//starboard/shared/starboard/crash_handler.cc",
"//starboard/shared/starboard/crash_handler.h",
  1. Handling kCobaltExtensionCrashHandlerName in the implementation of SbSystemGetExtension:
#include "starboard/system.h"

#include "starboard/extension/crash_handler.h"
#include "starboard/shared/starboard/crash_handler.h"

...

const void* SbSystemGetExtension(const char* name) {

  ...

  if (SbStringCompareAll(name, kCobaltExtensionCrashHandlerName) == 0) {
    return starboard::GetCrashHandlerApi();
  }
  return NULL;
}
  1. Calling the crashpad::InstallCrashpadHandler() hook directly after installing system crash handlers. On linux, for example, this could look like:
#include "starboard/crashpad_wrapper/wrapper.h"

int main(int argc, char** argv) {
  ...
  starboard::InstallCrashSignalHandlers();
  starboard::InstallSuspendSignalHandlers();

  std::string ca_certificates_path = starboard::GetCACertificatesPath();
  crashpad::InstallCrashpadHandler(ca_certificates_path);

  int result = application.Run(argc, argv);
  ...
}

NOTE: platforms using Evergreen should not call crashpad::InstallCrashpadHandler() from their own application code. Starting with Cobalt 26, this function is now called from shared Evergreen code linked into the loader_app.