Skip to content

Commit c41c200

Browse files
authored
Rick/update Crashpad Visual Studio doc (#2613)
* Replace Backtrace VS extension guide with VS integration guide * Structured crashpad docs together, fixed sample code issue * Improving image resolution
1 parent 1c49e37 commit c41c200

File tree

14 files changed

+157
-71
lines changed

14 files changed

+157
-71
lines changed

docs/error-reporting/platform-integrations/crashpad.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
id: crashpad
33
title: Integrating Crashpad
4-
sidebar_label: Crashpad
4+
sidebar_label: Integration Guide
55
description: Integrate Crashpad in your Backtrace project.
66
---
77

Lines changed: 147 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,185 @@
11
---
22
id: visual-studio
3-
title: Visual Studio Extension Guide (C++ and Crashpad)
4-
sidebar_label: Visual Studio Extension Guide
5-
description: The Backtrace Extension for Visual Studio .
3+
title: Crashpad Integration Guide for Visual Studio 2022
4+
sidebar_label: Visual Studio
5+
description: Crashpad Integration Guide for Visual Studio 2022
66
---
77

88
import Tabs from '@theme/Tabs';
99
import TabItem from '@theme/TabItem';
1010
import useBaseUrl from '@docusaurus/useBaseUrl';
1111

12-
The Backtrace extension for Visual Studio simplifies the integration and configuration of Crashpad in your C++ based application, allowing you to capture and submit crashes to your Backtrace instance.
12+
## (C++ and Crashpad)
1313

14-
The extension installs a new item in the Project Menu (right-click on your project in the **Solution Explorer** to see **Add Crashpad support**). Selecting the menu item launches a wizard that allows the developer to download, configure, and integrate a supported Crashpad library into your application.
14+
Follow these steps to add Crashpad to a C++ project.
1515

16-
<img src={useBaseUrl('/img/error-reporting/vs-extension/5e601bc3cc2b5.png')} alt="Add crashpad support" width="450"/>
16+
## Build Crashpad binaries
1717

18-
## What You'll Need
18+
In a x64 Native Tools Command Prompt for VS 2022 run the following commands to build Crashpad binaries for both the Debug and Release configurations.
1919

20-
- A Backtrace account ([log in](https://backtrace.io/login) or sign up for a [free trial license](https://backtrace.io/sign-up)).
21-
- Your subdomain name (used to connect to your Backtrace instance). For example, `https://example-subdomain.sp.backtrace.io`.
22-
- A Backtrace project and a [submission token](/error-reporting/project-setup/submission-url).
23-
- Visual Studio 2017 or 2019 (Preview) with the Visual Studio Extensions plugin and WPF.
24-
- Windows (Win32 or x86_64) as the target build platform.
25-
26-
## Setup and Installation
20+
```powershell
21+
git clone https://github.com/backtrace-labs/crashpad.git
22+
cd crashpad
23+
cmake -B cbuild
24+
cmake --build cbuild --config Debug
25+
cmake --build cbuild --config Release
26+
```
2727

28-
1. Download the Backtrace Visual Studio Extension from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=Backtrace.VSPlugin2019-01-19).
29-
2. Open the .vsix file either using Windows Explorer or the "Developer Command Prompt" along with the VSIXInstaller.exe file to install the extension.
30-
3. Open a C++ project in Visual Studio.
31-
4. Right-click on the project in the Solution Explorer to open the project menu. You see the new **Add Crashpad support** menu item.
32-
5. Select the **Add Crashpad support** menu item to launch the wizard, which installs and configures the Crashpad library in the project.
28+
## Set up a Visual Studio project
3329

34-
## Wizard Overview
30+
### Set Language Standard
3531

36-
The wizard consists of three main steps:
32+
Crashpad requires C++17. In project properties, select `All Configurations` and change the C++ Language Standard in the General tab from the default `C++14` to `C++17 (/std:c++17)`, if necessary.
33+
<img src={useBaseUrl('/img/error-reporting/vs-extension/vs-lang.png')} alt="listeners"/>
3734

38-
**Step 1: Backtrace Server Information**
35+
### Set Additional Include Directories
3936

40-
- Enter the URL of your Backtrace server and the submission token.
41-
- The submission URL field provides an autocomplete feature based on the instance name you enter.
42-
- The submission token field to allow crashes to be submitted to the Backtrace instance. This field requires that the provided string has exactly 64 characters. If you don't have a Backtrace instance, you can create one by following the provided link.
43-
- Don't have an account?: This link will take the user to a web page where they can create a new Backtrace instance. Use this link if you don't already have a Backtrace instance provisioned for your project.
44-
- Click **Next** to proceed to the next page.
45-
<img src={useBaseUrl('/img/error-reporting/vs-extension/5e601bc4c83c1.png')} alt="step 1: backtrace server information"/>
37+
To simplify the paths, the following instructions assume that `$(CrashpadRoot)` is defined in a property sheet and points to the root directory of the cloned Backtrace Crashpad source code from the previous step.
4638

47-
**Step 2: Download or Use Existing Crashpad Library**
39+
Add the following include directories in your Visual Studio project for all configurations in C/C++, Additional Include Directories:
4840

49-
- This step allows you to choose the versions of Crashpad you want to download (from the get.backtrace.io/crashpad/builds page) or specify the directory of an already downloaded library.
50-
- Select the desired configuration and platform versions from the dropdown lists. Backtrace provides both Release and Debug configurations of Crashpad, and x64 & Win32 platforms.
51-
- Use the **Download Crashpad** to connect to the `get.backtrace.io` servers and download the specified versions. Select the destination directory, and the wizard downloads the latest Crashpad binaries. If you specify multiple Configurations or Platforms to download, the wizard will download each.
52-
- The **Backtrace Crashpad package directory** field is automatically filled if you use the **Download Crashpad**, but you can also provide a custom path by using the textbox or you can choose existing path by using **Browse**.
53-
- Proceed to the next step after making the appropriate selections.
54-
<img src={useBaseUrl('/img/error-reporting/vs-extension/5e601bc5af052.png')} alt="step 2: setup the configuration and platform versions"/>
55-
<img src={useBaseUrl('/img/error-reporting/vs-extension/5e601bc6e64ba.png')} alt="downloading the library"/>
41+
- `$(CrashpadRoot)`
42+
- `$(CrashpadRoot)\third_party\mini_chromium\mini_chromium`
5643

57-
**Step 3: Automated Symbol Upload**
44+
<img src={useBaseUrl('/img/error-reporting/vs-extension/vs-include.png')} alt="listeners"/>
5845

59-
- In this final step, you can enable debug symbols upload after debug or release builds types.
60-
- **Would you like to enable automated symbol upload for your project?** Tick this checkbox if you want the Wizard to configure post build steps to upload symbols to Backtrace after building your application.
61-
- Check the "Enable automated symbol upload" field to configure post-build steps for uploading symbols to Backtrace.
62-
- Select **Debug** and **Release** to configure Visual Studio to upload debug symbols as needed for different build types.
63-
- If you are uploading symbols, you will need a **Symbol Upload Token**. This allows you to upload Symbols to Backtrace. This is a different token from your Submission token.
64-
- Complete the wizard by clicking "Finish."
65-
<img src={useBaseUrl('/img/error-reporting/vs-extension/5e601bc7c676a.png')} alt="automated symbol upload"/>
46+
### Set Additional Library Directory
6647

67-
## Wizard Completion Tasks
48+
Add a library directory pointing to the build output directory from the previous step in the project's Linker, General, Additional Library Directories. This would be `$(CrashpadRoot)\cbuild`, for instance.
6849

69-
After finishing the wizard, the extension performs background tasks to configure your project properly. These tasks include creating and modifying files in your project:
50+
<img src={useBaseUrl('/img/error-reporting/vs-extension/vs-libdir.png')} alt="listeners"/>
7051

71-
<ul>
72-
<li>Add or replace the appropriate Crashpad libraries for your project.</li>
73-
<li>Update the settings for /MD and /MT.</li>
74-
<li>Add library paths, include paths, and libraries for the appropriate build configurations (x86_32, x64, debug, release).</li>
75-
</ul>
52+
### Add Additional Library Dependencies
7653

77-
You may see dialogs notifying you that files are being modified outside the Visual Studio environment. Choose **Reload All** as necessary.
78-
<img src={useBaseUrl('/img/error-reporting/vs-extension/5e601bc9156b3.png')} alt="Reload all button"/>
54+
Add the following libraries in the project's Linker, Input, Additional Dependencies.
7955

80-
A dialog about inconsistent line endings may appear. It's recommended to normalize the line endings according to your environment.
81-
<img src={useBaseUrl('/img/error-reporting/vs-extension/5e601bca1b4c4.png')} alt="inconsistent line endings dialog"/>
56+
For debug configuration(s):<br/>
57+
`client\Debug\client.lib`
8258

83-
The Visual Studio Extension modifies the vcxproj file (project definition file) to add Crashpad to your project. You can further customize each option in **Project Properties**.
59+
For release configuration(s):<br/>
60+
`client\Release\client.lib`
8461

85-
If you enable symbol upload, a post-build task is created. After each successful build, the extension sends the necessary files (.PDBs, .DLLs, .EXEs) as a zip archive to the Backtrace instance. You can disable this option in **Project Properties** under **Post-build** actions.
62+
Or, if the configurations are named `Debug` and `Release` then this can be simplified to the following for all configurations:<br/>
63+
`client\$(Configuration)\client.lib`
8664

87-
## Post Install Steps
65+
<img src={useBaseUrl('/img/error-reporting/vs-extension/vs-link.png')} alt="listeners"/>
8866

89-
After completing the wizard, make sure to open the CrashpadSetup.cpp file and specify the following values:
9067

91-
- **db_path**: Set the directory where crash reports should be locally stored before submitting to Backtrace.
92-
- **handler_path**: Configure the launch mechanism for Crashpad (for example., out-of-process).
68+
## Code Samples
9369

94-
Additionally, initialize Crashpad and check the result with a function call like the following in your main function:
70+
The following code can be added to your project and can be used to initialize Crashpad in your application.
9571

72+
Header, `bt_crashpad.h`
9673
```cpp
97-
bool result = backtrace::initializeCrashpad();
74+
#pragma once
75+
76+
namespace backtrace {
77+
bool startCrashHandler();
78+
}
9879
```
9980
100-
## FAQ
81+
Source file, `bt_crashpad.cpp`
82+
```cpp
83+
#include "bt_crashpad.h"
84+
85+
#include <algorithm>
86+
#include <map>
87+
#include <memory>
88+
#include <string>
89+
#include <vector>
90+
91+
92+
#define NOMINMAX // prevent Windows headers from defining min/max
93+
#include <client/crash_report_database.h>
94+
#include <client/settings.h>
95+
#include <client/crashpad_client.h>
96+
#include <client/crashpad_info.h>
97+
98+
99+
/*
100+
* ENSURE THIS VALUE IS CORRECT.
101+
*
102+
* This is the directory used to store and queue crash data for the application.
103+
*/
104+
static const wchar_t CRASHPAD_DATABASE_PATH[] = L".";
105+
106+
107+
/*
108+
* ENSURE THIS VALUE IS CORRECT.
109+
*
110+
* Crashpad has the ability to support crashes both in-process and out-of-process.
111+
* The out-of-process handler is significantly more robust than traditional in-process
112+
* crash handlers. This path may be relative. Point to the installed Crashpad handler
113+
* built from the Backtrace Crashpad source.
114+
*/
115+
static const wchar_t CRASHPAD_HANDLER_PATH[] = L".\\handler.exe";
116+
117+
118+
/*
119+
* YOU MUST CHANGE THIS VALUE.
120+
*
121+
* Replace "youruniverse" with the Backtrace universe name and replace the submission token.
122+
*/
123+
static const char BACKTRACE_SUBMIT_URL[] = "https://submit.backtrace.io/youruniverse/000000000000000000000000000000000000000000000000000000000000000/minidump";
124+
125+
126+
namespace backtrace {
127+
128+
129+
static std::unique_ptr<crashpad::CrashReportDatabase> database;
130+
101131
102-
Q1: What happens if the user doesn't specify a `db_path` variable in the `CrashpadSetup.cpp`?<br/>
103-
A1: The Crashpad initialization code returns `-1` (error), so Crashpad won't initialize.
132+
bool startCrashHandler()
133+
{
134+
using namespace crashpad;
104135
105-
Q2: What is `_rxid` in the build window?<br/>
106-
A2: That is the result from a server when we upload archive with symbols.
136+
137+
std::map<std::string, std::string> annotations;
138+
std::vector<std::string> arguments = { "--no-rate-limit" };
139+
140+
141+
/*
142+
* THE FOLLOWING ANNOTATIONS MUST BE SET.
143+
*
144+
* Backtrace supports many file formats. Set format to minidump
145+
* so it knows how to process the incoming dump.
146+
*/
147+
annotations["format"] = "minidump";
148+
149+
150+
base::FilePath db(CRASHPAD_DATABASE_PATH);
151+
base::FilePath handler(CRASHPAD_HANDLER_PATH);
152+
153+
154+
database = crashpad::CrashReportDatabase::Initialize(db);
155+
156+
157+
if (database == nullptr || database->GetSettings() == NULL)
158+
return false;
159+
160+
161+
/* Enable automated uploads. */
162+
database->GetSettings()->SetUploadsEnabled(true);
163+
164+
165+
return CrashpadClient{}.StartHandler(
166+
handler, db, db, BACKTRACE_SUBMIT_URL, annotations, arguments, false, false, {}
167+
);
168+
}
169+
170+
}
171+
```
172+
173+
In your initialization code,
174+
```cpp
175+
#include “bt_crashpad.h”
176+
177+
{
178+
179+
if (backtrace::startCrashHandler() == false)
180+
{
181+
// crashpad failed to start
182+
}
183+
184+
}
185+
```

sidebars.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,15 @@ module.exports = {
465465
'error-reporting/platform-integrations/coresnap/setup',
466466
],
467467
},
468-
'error-reporting/platform-integrations/visual-studio',
469-
'error-reporting/platform-integrations/crashpad',
468+
{
469+
type: 'category',
470+
label: 'Crashpad',
471+
collapsed: true,
472+
items: [
473+
'error-reporting/platform-integrations/crashpad',
474+
'error-reporting/platform-integrations/visual-studio',
475+
],
476+
},
470477
'error-reporting/platform-integrations/breakpad',
471478
'error-reporting/platform-integrations/http-submission',
472479
],
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)