Skip to content

A walkthrough for setting up debugging of Nim code in VSCode

License

Notifications You must be signed in to change notification settings

russpowers/nim-debug-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 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. Python 3 is installed (used for pretty-printing with GDB).
  5. The Nim VSCode extension is installed.
  6. The Native Debug VSCode extension is installed.
  7. 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 on line 15 in the file:

setting a breakpoint in main.nim on line 15

  1. Debug -> Start Debugging, which should use the launch config in .vscode/launch.json. (This will automatically build the code)

Note: The nim-gdb.py script was copied from here, and exists in the tools/ directory simply to reduce the number of steps in setting this up. It might be a good idea to update your local copy of this file with the official latest file from the repository.

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 nim-gdb.py script could be modified to support this). Even though this functionality doesn't exist, you can type print people[0].name in the Debug Console to print the value:

type print variable in vscode debug console

Press [enter], and you should see the contents of the variable:

debug console showing variable contents

Notes

GDB can be extended with Python, and the nim-gdb.py script can be used from the command-line using this bash script.

The nim-gdb repository seems to be the predecessor to the nim-gdb script in the official 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

Languages

  • Python 98.4%
  • Nim 1.6%