Below are some steps to help you debug Nim code in Visual Studio Code.
- Nim is installed.
- GDB is installed.
- VSCode is installed.
- The Nim VSCode extension is installed.
- The Native Debug VSCode extension is installed.
- This example repository has been cloned with Git.
This repository contains some files to help setup debugging in VSCode.
- Open VSCode.
- File -> Open Folder -> Open the cloned repository folder in VSCode.
- Open
main.nim. - Set a breakpoint.
- Build the code (ctrl-shift-b), which should use the build definition in
.vscode/tasks.json. - Debug -> Start Debugging, which should use the launch config in
.vscode/launch.json. - Once the breakpoint is hit, let's enable pretty-printing. Otherwise, when you mouse over a symbol in the debugger, you'll see memory addresses instead of values.
Open the Debug Console (at the bottom) and type:
python exec(open("bin/nim3.py").read())
and press [enter], to run a Python script that sets up the symbols in GDB.
If this returns an error, try running the Python 2 version:
python execfile("bin/nim.py")
Note: The nim.py and nim3.py scripts were copied from nim-gdb,
and exist in the bin/ directory simply to reduce the number of steps in setting this up.
If running the Python pretty-printing script succeeds, you should be able to mouse over a variable, e.g. a string, and see the value:
GDB can be extended with Python, and it seems that there are two scripts (written by others) for doing this:
- The nim-gdb project: nim-gdb
- From the Nim source:
nim-gdb bash script
nim-gdb.py file, Nim repository
Debug Nim with GDB
Nim GDB video
Nim Editor Support
repr method for debugging
Nim VSCode plugin debug feature request
Extending GDB using Python
