X Tutup
Skip to content

Commit d836682

Browse files
authored
docs: add native c++ windows debugging method (electron#26286)
1 parent e193543 commit d836682

File tree

4 files changed

+102
-38
lines changed

4 files changed

+102
-38
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ an issue:
5959
* [Manually Enabling Accessibility Features](tutorial/accessibility.md#manually-enabling-accessibility-features)
6060
* [Testing and Debugging](tutorial/application-debugging.md)
6161
* [Debugging the Main Process](tutorial/debugging-main-process.md)
62-
* [Debugging the Main Process with Visual Studio Code](tutorial/debugging-main-process-vscode.md)
62+
* [Debugging with Visual Studio Code](tutorial/debugging-vscode.md)
6363
* [Using Selenium and WebDriver](tutorial/using-selenium-and-webdriver.md)
6464
* [Testing on Headless CI Systems (Travis, Jenkins)](tutorial/testing-on-headless-ci.md)
6565
* [DevTools Extension](tutorial/devtools-extension.md)

docs/tutorial/debugging-main-process-vscode.md

Lines changed: 0 additions & 36 deletions
This file was deleted.

docs/tutorial/debugging-main-process.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ You will need to use a debugger that supports the V8 inspector protocol.
3030

3131
- Connect Chrome by visiting `chrome://inspect` and selecting to inspect the
3232
launched Electron app present there.
33-
- [Debugging the Main Process in VSCode](debugging-main-process-vscode.md)
33+
- [Debugging in VSCode](debugging-vscode.md)

docs/tutorial/debugging-vscode.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Debugging in VSCode
2+
3+
This guide goes over how to set up VSCode debugging for both your own Electron project as well as the native Electron codebase.
4+
5+
## Debugging your Electron app
6+
7+
### Main process
8+
9+
#### 1. Open an Electron project in VSCode.
10+
11+
```sh
12+
$ git clone git@github.com:electron/electron-quick-start.git
13+
$ code electron-quick-start
14+
```
15+
16+
#### 2. Add a file `.vscode/launch.json` with the following configuration:
17+
18+
```json
19+
{
20+
"version": "0.2.0",
21+
"configurations": [
22+
{
23+
"name": "Debug Main Process",
24+
"type": "node",
25+
"request": "launch",
26+
"cwd": "${workspaceFolder}",
27+
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
28+
"windows": {
29+
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
30+
},
31+
"args" : ["."],
32+
"outputCapture": "std"
33+
}
34+
]
35+
}
36+
```
37+
38+
39+
#### 3. Debugging
40+
41+
Set some breakpoints in `main.js`, and start debugging in the [Debug View](https://code.visualstudio.com/docs/editor/debugging). You should be able to hit the breakpoints.
42+
43+
Here is a pre-configured project that you can download and directly debug in VSCode: https://github.com/octref/vscode-electron-debug/tree/master/electron-quick-start
44+
45+
## Debugging the Electron codebase
46+
47+
If you want to build Electron from source and modify the native Electron codebase, this section will help you in testing your modifications.
48+
49+
For those unsure where to acquire this code or how to build it, [Electron's Build Tools](https://github.com/electron/build-tools) automates and explains most of this process. If you wish to manually set up the environment, you can instead use these [build instructions](https://www.electronjs.org/docs/development/build-instructions-gn).
50+
51+
### Windows (C++)
52+
53+
#### 1. Open an Electron project in VSCode.
54+
55+
```sh
56+
$ git clone git@github.com:electron/electron-quick-start.git
57+
$ code electron-quick-start
58+
```
59+
60+
#### 2. Add a file `.vscode/launch.json` with the following configuration:
61+
62+
```json
63+
{
64+
"version": "0.2.0",
65+
"configurations": [
66+
{
67+
"name": "(Windows) Launch",
68+
"type": "cppvsdbg",
69+
"request": "launch",
70+
"program": "${workspaceFolder}\\out\\your-executable-location\\electron.exe",
71+
"args": ["your-electron-project-path"],
72+
"stopAtEntry": false,
73+
"cwd": "${workspaceFolder}",
74+
"environment": [
75+
{"name": "ELECTRON_ENABLE_LOGGING", "value": "true"},
76+
{"name": "ELECTRON_ENABLE_STACK_DUMPING", "value": "true"},
77+
{"name": "ELECTRON_RUN_AS_NODE", "value": ""},
78+
],
79+
"externalConsole": false,
80+
"sourceFileMap": {
81+
"o:\\": "${workspaceFolder}",
82+
},
83+
},
84+
]
85+
}
86+
```
87+
**Configuration Notes**
88+
89+
- `cppvsdbg` requires the [built-in C/C++ extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) be enabled.
90+
- `${workspaceFolder}` is the full path to Chromium's `src` directory.
91+
- `your-executable-location` will be one of the following depending on a few items:
92+
- `Testing`: If you are using the default settings of [Electron's Build-Tools](https://github.com/electron/build-tools) or the default instructions when [building from source](https://www.electronjs.org/docs/development/build-instructions-gn#building).
93+
- `Release`: If you built a Release build rather than a Testing build.
94+
- `your-directory-name`: If you modified this during your build process from the default, this will be whatever you specified.
95+
- The `args` array string `"your-electron-project-path"` should be the absolute path to either the directory or `main.js` file of the Electron project you are using for testing. In this example, it should be your path to `electron-quick-start`.
96+
97+
98+
#### 3. Debugging
99+
100+
Set some breakpoints in the .cc files of your choosing in the native Electron C++ code, and start debugging in the [Debug View](https://code.visualstudio.com/docs/editor/debugging).

0 commit comments

Comments
 (0)
X Tutup