Skip to content

jasonprogrammer/nim-debug-commandline-example

Repository files navigation

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

About

A walkthrough of how to debug Nim code using GDB on the command-line

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published