-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debug support #65
Comments
I've already done some experiments with Since the latest major version of Nim, it supports generating a list of all symbols and their mangled names, which could be accesed to mangle or demangle the symbols. |
Just to be clear, setting a breakpoint in the nim file or the generated C ? |
I've set break points in the Nim file and it's completely independant from this extension. You simply have to debug the binary you've created just like you would debug it, if it was a C/C++ binary. |
Thanks, after an update many things work better, specifically setting break points, stopping at them, watching values. Looks like all is good with basic debug. |
@kobi2187, @RSDuck wich versions are you used? I'm tried with lldb-5.0, vscode 1.20.1, gdb 7.11.1 But can't read/evaluate variables/expressions: Here is sample for NativeDebug+LLDB:
tasks.json:
|
I think you have done everything correctly. However, the Nim variable names are mangled when generating c source and the mapping of the variable names to their mangled versions is not currently performed for you automatically by any debugging extension. If you look in the nimcache folder of your project you will find a file named main.ndi. This file contains the mappings of the original variable name to the mangled name. My main.ndi file contains the following lines (as well as other info):
The first line indicates that the variable 'a' found at location 6,4 (zero-based row,col) in file main.nim has been mangled to a_9cWLbw5tGuQDnREm7o4KXdA. So when debugging the program if you want to inspect the value of variable 'a' from the Nim source, you need to specify a_9cWLbw5tGuQDnREm7o4KXdA to the debugger. |
@brjohnsn Thanks for hint! I'll play with it |
@brjohnsn Btw, what is "Variables -> Local"? As I understand, there must be displayed two local variables with values 1 and 2, or no? |
Yes I would have expected the same thing, but I have not read the docs for the Native Debug extension (if there are any) to know for sure. If you wrap your code in a proc those variables do seem to appear in their unmangled form. Try debugging with code similar to the following...
|
@brjohnsn it works, I tried 2 extensions, here is results: --- vscode-lldb --- nativedebug Also I tried MSCppTools for VSCode, but unsuccessfull. It doesn't work with Nim. |
Note: plugin vscode-lldb doesn't support input stream. main.nim
output:
the plugin NativeDebug with GDB works fine. |
Hi,
Then I was able to set breakpoints in the .nim files, but all the syntax highlighting and all other nim language functionality obviously was gone. After setting the breakpoints, I commented the line in settings.json ... then I was able to start the debugger and it did hit the breakpoints in the .nim file 😄 Also all symbols that were not mangled by the nim compiler can be inspected via mouse-over or in the watch window. (but ofc with the limitations already mentioned above) Is there anything I could do to set breakpoints in the .nim files without the mentioned workarround ? PS: this trick even works while the debugger is already running, i.e. you can set new breakpoints while debugging. Thanks |
@kosz78 Nice, I will be checking it out |
How about this issue's progressing? |
Hello |
There is a nim-gdb.py script in tools which is supposed to help with this. On windows, I tried making a nim-gdb.bat file which calls nim-gdb.py and setting miDebuggerPath in launch.json to point to this instead of regular gdb. But I'm having some trouble installing gdb for python currently so the script isn't running. I think if i can get gdb python installed, it will work tho. nim-gdb.bat: python nim-gdb.py --debugger:native %* nim build command: nim c -d:debug --debuginfo --lineDir:on --debugger:native <file>.nim |
I always struggle with the next VS Code Setup ... in fact this time it was VSCodium (open source, MS not monitoring you). I'm including my full files in case it helps someone else :) My setup is for Linux; I run Mint 19 so it would suit Ubuntu & probably most other Linuxes + OSX. Two files needed for Nim. 1 For compilation you need to setup tasks.json. Here's my setup for compiling nim with cpp, c, and c + debug. Note that the command will need to target your nim compiler so /home/john/.local/bin/nim will probably change.
|
I have been able to use vscode to debug nim from wsl by
// tasks.json
{
"version": "2.0.0",
"tasks": [{
"label": "nimbuild",
"type": "shell",
"command": "~/.nimble/bin/nim",
"args": ["c", "--debugger:native", "${file}"],
}]
}
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"preLaunchTask": "nimbuild",
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "nim-gdb",
"setupCommands": [{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}],
}]
} After doing this I can debug nim and inspect variables from vscode. I hope I didn't leave any steps out. Don't forget to add |
@travisstaloch does it show variables properly for you? It doesnt work for me. |
Try it from inside in a function. I noticed the same thing until I moved the code into a function. |
Hah indeed that did the trick. Thanks 👍 |
@travisstaloch you forgot to mention that it also requires to download https://github.com/nim-lang/Nim/raw/devel/bin/nim-gdb into ~/.nimble/tools, then "chmod +x nim-gdb" and finally add ~/.nimble/tools to PATH. At least that's what was missing on my side :) |
I went through all the steps you describe, and I got this error when pressing F5 to run the debugger: Can I ask how you configured this? I see there is a line "miDebuggerPath": "nim-gdb" in launch.json. I'm not sure what nim-gdb is or how to get it. Is it related to this? https://github.com/cooldome/Nim-gdb I do have a file called nim-gdb.py (which I got from here) in the root of my project folder. Update
@size-1 Sorry, I didn't read your reply. But, I followed your instructions. Now I don't get the error complaining about not being able to find nim-gdb. Instead, what happens is that I set a breakpoint in my code, press F5, and this shows up in the TERMINAL window at the bottom of Visual Studio Code: The first thing is a compilation that appears to be successful with "Task - nimbuild": It then automatically switches that to another window, "cppdbg: lcs", with just this printed: The whole window looks like this: It's giving me the debug step buttons at the top of the screen. However, it has not stopped at the breakpoint to show me local variable names and values. |
- debugger works -- except top level symbols - add nim-gdb (tool in nim) to path setup hints: pragmagic/vscode-nim#65 (comment)
I have successfully debugged based on the above configurations. But the variable name is missing, and I don't know how to solve this problem. launch.json |
Hello, what would be needed for a good debug experience inside vscode? I start this issue as a discussion thread and cooperation.
I see an LLDB extension for c++ and rust. -- [link] that looks really nice.
I am hopeful that the same extension can be used by us
however, setting a breakpoint in nim mode, is not yet possible.
I am also not sure how to use debugging directly from the editor (tasks?)
These things need direct support from the nim extension.
Thanks!
The text was updated successfully, but these errors were encountered: