Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
A walkthrough of how to debug Nim code using GDB on the command-line
Python Nim Shell
Branch: master
Clone or download
Cannot retrieve the latest commit at this time.
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images
.gitignore
LICENSE
README.md
build.sh
debug.sh
gdb-commands.txt
main.nim
nim-gdb.py
vim_breakpoints.md

README.md

How to debug Nim using command-line GDB

The steps below demonstrate how to debug Nim code from the command-line using GDB.

Prerequisites

  1. Nim is installed.
  2. GDB is installed.
  3. Python 3 is installed (used for pretty-printing with GDB).

Debugging

  1. Run ./build.sh to build an executable.
  2. Run ./debug.sh to start a debugging session.
  3. 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)

Notes

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.

How to save/load GDB breakpoints from Vim

See this guide for instructions.

References

Debug Nim with GDB

You can’t perform that action at this time.