Skip to content

jasonprogrammer/nim-debug-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to debug Nim code in VSCode

Below are some steps to help you debug Nim code in Visual Studio Code.

Prerequisites

  1. Nim is installed.
  2. GDB is installed.
  3. VSCode is installed.
  4. The Nim VSCode extension is installed.
  5. The Native Debug VSCode extension is installed.
  6. This example repository has been cloned with Git.

Steps to setup debugging

This repository contains some files to help setup debugging in VSCode.

  1. Open VSCode.
  2. File -> Open Folder -> Open the cloned repository folder in VSCode.
  3. Open main.nim.
  4. Set a breakpoint.
  5. Build the code (ctrl-shift-b), which should use the build definition in .vscode/tasks.json.
  6. Debug -> Start Debugging, which should use the launch config in .vscode/launch.json.
  7. 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:

mousing over a variable in the debugger and seeing the value contained in the variable

You'll notice, however, if you mouseover people[0].name, that it does not show the name of the first person (perhaps the nim3.py script could be modified to support this).

Notes

GDB can be extended with Python, and it seems that there are two scripts (written by others) for doing this:

  1. The nim-gdb project: nim-gdb
  2. From the Nim source:

nim-gdb bash script
nim-gdb.py file, Nim repository

References

Debug Nim with GDB
Nim GDB video
Nim Editor Support
repr method for debugging
Nim VSCode plugin debug feature request
Extending GDB using Python

About

A walkthrough for setting up debugging of Nim code in VSCode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published