2022-12-31
VS Code debugger settings
Debugging with VS Code
Problem
VS Code debugger runs on the root directory of the file (default).
This default behavior of the debugger may cause following errors if the file you want to debug is not on the root directory.
Solution
Set cwd
in the debugger settings, .vscode/launch.json
"cwd": Absolute path to the working directory of the program being debugged. Default is the root directory of the file.
Values of cwd
-
${fileDirname}
- The current opened file's dirname
- This will run the debugger on the currently opened file instead of the root directory opened in VS Code
-
${workspaceFolder}
- Default value
- Root directory
- You can specify relative path from the root directory like so:
${workspaceFolder}/2022
Sample .vscode/launch.json
Pressing Control + Space
inside "configurations"
will show available options. This also works for the values inside double quotes.