Replies: 4 comments 11 replies
-
Nimskull debugging is very similar to Nim at the moment, save for slightly worse procedure names as we don't use C++-style mangling. There are no concrete plans to improve debugging at the moment. We are mostly focused on improving language stability and performance, so debugging is on the back seat. I do have plans to work on that eventually. One of the reasons why Nim(skull) debugging story is so bad is due to the fact C is used as an intermediary. All C compilers that we target do not allow for fine grained control over debug information, so there is a hard cap on what we can do. The best that can be done right now is to write debugger plugins to recognize our codegen patterns and internal structures to prettify them. Eventually we might port Nimskull to a proper code generator (i.e. LLVM), which then would give us full control over debug information and improve it further. For now, if you need to use a debugger, these flags would help with reducing weird jumps: |
Beta Was this translation helpful? Give feedback.
-
Many thanks for your informative response. :-) Re: debugger plugins: I can definitely see that helping to prettify variables, at the very least. A GCC plugin is, in fact, one of the things I've looked for hard in Nim-land, but "those who know how, haven't shared (that I can find), and those who need, don't know how.". Long term, LLVM seems a real step up. Great tips about debugger flags. I've tested with them and the number of weird jumps has dropped markedly. |
Beta Was this translation helpful? Give feedback.
-
Gentlemen, I've decided I Really Want to Make This Work (as well as it can for now). Any info shared with me will be shared with others (and I'm already workshopping how). Saem, Your offer of taking on some concrete tasks is happily accepted. That said, I do need to set things up on VSCode on WIndows to use gdb and nim-gdb.py like you have. Right now:
May I ask for a how-to? |
Beta Was this translation helpful? Give feedback.
-
Separate from what was discussed already, there is another approach to improve the debugging experience: implementing a simple debugger integration ourselves. At the core, this isn't overly complex. It boils down to:
Every call to a debugger runtime procedure not about variables is associated with source information, such as line/column number, source module, routine name, etc. . Variables would be associated with names and run-time type information. Both the database holding the aforementioned data and the debugger runtime would be embedded in the to-be-debugged executable itself. The debugger runtime handles external communication (e.g., listening on a socket) and command execution (e.g., step into, step over, show stack-trace, etc.). Debugger features possible with this approach are:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We begin with a question often asked in the Nim forum, in reddit r/Nim, and elsewhere: How to debug Nim code?
The poster has usually discovered that
a) they can't see the data they're looking for entirely (non-trivial data type), or
b) the variable is visible but garbled (trivial data type), or
c) it is listed alongside a bunch of low-level things like registers and frames.
What they're expecting - based on their experience with other programming languages - is the unmangled and automatic display of in-scope variables, including that organized in non-trivial data types. Nim, as best as I can tell from reading way too many posts and guides dating back to 2017, is that the Nim toolchain doesn't deliver this, and doesn't plan to deliver this. The Official Answer is "use print-outs".
Additionally, as experienced in post #6 in the thread https://forum.nim-lang.org/t/12704 (warning: post is lengthy), while Nim does provide step-by-step debugging, the way the compiler is implemented means that a debugger tracks destructors, stack winding and unwinding, and other highly granular actions triggered by, but not expressed by, the Nim code itself. This is ... quite a surprise to those expecting a debugger to track code more nearly as it is written.
For both issues, the result is the same: What Nim gives in simplicity of syntax, it too often takes away in complexity of tool usage. What it gives in readable code, it in part takes away in the lack of ability to efficiently debug that code.
So, the question! What are the plans and current state of debugging in Nimskull?
Beta Was this translation helpful? Give feedback.
All reactions