|
| 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