The steps below demonstrate how to debug Nim code from the command-line using GDB.
- Nim is installed.
- GDB is installed.
- Python 3 is installed (used for pretty-printing with GDB).
- Run
./build.shto build an executable. - Run
./debug.shto start a debugging session. - A GDB session should start, and allow you to set breakpoints and print variables, e.g.:
Loading Nim Runtime support.
(gdb) b main.nim:15
Breakpoint 1 at 0x10dd0: file /home/jason/projects/nim-debug-commandline-example/main.nim, line 15.
(gdb) r
Starting program: /home/jason/projects/nim-debug-commandline-example/bin/main
Breakpoint 1, main__9bQIWt54CdTNMd7hgR2Bl9cw () at /home/jason/projects/nim-debug-commandline-example/main.nim:15
15 echo name
(gdb) print name
$1 = "bob"
(gdb) n
bob
16 echo people[0].name
(gdb) print people[0].name
$2 = "John"
(gdb)
The nim-gdb.py script was copied from here,
and exists in this repository simply to reduce the number of steps in setting this up. It might be a good
idea to update your copy of this file with the official latest file from the repository.
See this guide for instructions.