Crashpad

Overview โ„น๏ธ

Crashpad is the latest open-source crash reporting tool built by Google and is the successor to the popular Breakpad crash reporter. Crashpad allows you to submit minidumps to a configured URL after a crash occurs in your product. Crashpad and Breakpad are 'wire compatible.' The crash reports created by both systems are processed similarly on our backend.

The official Crashpad documentation is available here.

Build Configuration ๐Ÿ—๏ธ

The first step to integrating Crashpad is to configure your build process. BugSplat provides pre-built versions of Crashpad that are updated monthly. You can find the prebuilt libraries on the Releases page in the bugsplat-crashpad repo. The bugsplat-crashpad repo also includes scripts that demonstrate how to build Crashpad on Windows, macOS, and Linux with Chromium's Depot Tools.

We also offer a detailed walkthrough that describes how to build Crashpad from scratch.

Binaries and Libraries

To add Crashpad to your application, you'll need to link with the client , common, util, and base libraries. Additionally, on macOS, you'll need to link with the mig_output library. On all platforms, you'll need to copy crashpad_handler to your build output directory and include it in your installer so that it is available at runtime.

The following example is a snippet from CMakeLists.txt for Windows - please see our sample for macOS and Linux.

# Library vars
set(CRASHPAD_LIBRARIES
    ${CRASHPAD_OUT_DIR}/obj/client/client.lib
    ${CRASHPAD_OUT_DIR}/obj/client/common.lib
    ${CRASHPAD_OUT_DIR}/obj/util/util.lib
    ${CRASHPAD_OUT_DIR}/obj/third_party/mini_chromium/mini_chromium/base/base.lib
)

# Handler var
set(CRASHPAD_HANDLER ${CRASHPAD_OUT_DIR}/crashpad_handler.exe)

# Link crashpad libs
target_link_libraries(MyCMakeCrasher ${CRASHPAD_LIBRARIES})

# Copy handler exe
add_custom_command(TARGET MyCMakeCrasher POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
    ${CRASHPAD_HANDLER}
    ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_CONFIG_DIR}/crashpad_handler${CMAKE_EXECUTABLE_SUFFIX}
)

Include Directories

You'll also need to add a few Crashpad directories to your app's includes list.

Code Integration ๐Ÿง‘โ€๐Ÿ’ป

The bugsplat-crashpad repo provides a my-cmake-crasher sample application that demonstrates how to configure Crashpad. The following code snippets are from the my-cmake-crasher example.

Includes and Namespaces

Add the following:

Initialization

Copy the initializeCrashpad and getExecutableDir methods from the BugSplat sample. The Crashpad url and parameters format, database, product and version are required to upload crash reports to BugSplat. You can optionally specify values for the parameters user, list_annotations, and key which will be tracked with each crash report.

The following snippet is for Windows. Please see my-cmake-crasher for macOS, and Linux compatible code changes.

Call initializeCrashpad using parameters specific to your application for dbName, appName, and appVersion.

Symbol Uploads ๐Ÿ—บ๏ธ

You will need to generate and upload .sym files to BugSplat to generate function names and line numbers in the stack traces of your crash reports. BugSplat's symbol-upload tool can be used conveniently to generate and upload .sym files with a single terminal command. Download a copy of symbol-upload from GitHub or install it via npm.

Once you have symbol-upload downloaded or installed, modify the following command to suit your needs.

Testing ๐Ÿงช

Trigger a crash in your application. The crash report should be available immediately on the BugSplat website. Click on the link in the ID column. If everything worked correctly, you should see something that resembles the following.

BugSplat Crash Details Page

Additional Considerations ๐Ÿค”

Databases

The BugSplat database for your crash reports is created on the Manage Database page in Settings. Typically, you will create a new database for each major release of your product.

Optimizations

Compiler optimizations can cause a mismatch between the line numbers in crash reports and the actual line numbers in your code. BugSplat recommends turning off compiler optimizations to ensure that the line numbers in your crash reports match the line numbers in your code. To turn off optimizations in Visual Studio, right-click your project and navigate to Properties > C/C++ > Optimization > Optimization, and set the value to Disabled (/Od).

Last updated

Was this helpful?