Hi, I trying to ease my pain debugging Nim. Thinking if anyone already implemented GDB pretty printers for Nim basic types.
Visual studios natvis debug custrom visualizers will also work.
Thank you
Haven't seen any, good idea. Should be pretty easy for seqs, arrays, strings and pretty useful when debugging.
I'd also be interested if it's possible to demangle identifiers so that we can tell GDB what the mapping between original identifier and C identifier is, like the #line pragma.
I noticed nim compiler has --genMapping option that generates ndi files with useful mapping.
Unfortunately, compilation itself fails when --genMapping is enabled.
well, I once did an approach to this, feel free to use it.
This macro embeds the gdb python script into the executable, when it is build on Linux. Alternatively you can also load the script from gdb, but once this works there is no hassle involved anymore. https://github.com/krux02/opengl-sandbox/blob/master/fancyglpkg/debug.nim
Here is the gdb script, but I haven't used it for a time. https://github.com/krux02/opengl-sandbox/blob/master/fancyglpkg/nim-gdb.py
Thanks Krux02,
I have tried it, it works as intended for strings and I couldn't make it to work for anything else. Names of the types is not sufficient indicator to determine whether it is enum, union, set and etc. What is probably I am after is compiler generates some useful file that python script can consume.
It is hard to believe no one has done it so far, I quickly reached the point where putting renderTree,typeToString and debug everywhere in Nim compiler no longer helps understanding what is going on. I don't see how one can contribute without solving the debugging dilemma.
I totally agree with you, debugging is really a weak spot in Nim.
Things I just don't understand:
By default Nim does build in debug mode, but it does not provide debugging symbols (-g flag for the C compiler), so that you can't actually debug with gdb your debug build. When I complain that this is an issue, I get told, that it is in fact not an issue and I should just change my nim.cfg. Alternatively I can simply add the --debugger:native flag to the compiler.
The gdb integration I just showed, is something that could be done from the Nim compiler, so that all Nim applications, that are build in debug mode have already the gdb scripts self contained in the binary, so that they can be loaded from gdb automatically and work magically in any frontend for gdb. Meaning there would be nothing in the way for debug builds to work with zero configuration in every editor.
But yea, it's just me who thinks this way, and passing --debugger:native as an additional flag to a debug build in case someone wants to actually debug the debug build is a good default.
Hi Krux02,
I have seen your pull request has been merged. Great job. I immediately started testing. I see that string, seq and array pretty printing is now working great. Objects and Tuples were fine anyway.
I believe we still have some problems with: Enums, Discriminated Unions and Sets. Let's solve this problem once and for all. It is the most rewarding contribution for Nim community I can think of.
I suggest starting further discussions what changes are required to display Enums and Discriminated Unions properly.
P.S. It could be possible to introduce new $ command into gdb that will extract a type of the argument and will check if suitable dollar operator implementation exists in global symbol table. I have started looking into that.
For enums there is a useful function reprEnum that is always compiled into final executable. It accepts two arguments: enum value (good) and TNimType*.
Does anyone know how to get second argument in a generic way outside of Nim?
Many thanks
Hi,
I have prepared gdb python script that should ease a lot of debugging pain. If anyone interested to give it a try, location is https://github.com/cooldome/Nim-gdb. Currently this script requires latest devel Nim and also needs this pull request: https://github.com/nim-lang/Nim/pull/6240. Hopefully, it will get integrated in to devel branch soon.
GDB Commands definitely worth trying:
> whatis nim_variable
> $ nim_varible
> print $dollar(nim_variable)
> print nim_variable
I just wanted to mention a gdb frontend that is worth checking out.
https://github.com/cs01/gdbgui/
Most gdb frondends suffer one major flaw. Either they are very old, olmost unusable a bit broken and not maintained anymore. Or they are part of an IDE that tries to do everything, but the IDE doesn't support Nim. The frontend above is just a frontend for gdb, nothing more.
Yea and secondly I wanted to resurrect this thread. Better debugging support for Nim is really worth to mention.