Debugging Zig (with a debugger)

I agree with this sentiment, at the same time, there’s nothing stopping the next debugger from being written in Zig. It could support everything which GDB and LLDB cover already, as well as providing better hooks for languages those two aren’t doing as good a job with.

This would be many human-years of labor, of course, and just patching and extending LLDB might be easier. But a debugger is exactly the kind of low-level system-oriented programming which Zig excels at. Sometimes the right thing to do is start fresh, with a system which doesn’t fundamentally assume it will be looking at either C or C++, an architecture which lets languages register specifics in an extensible way which covers bases for the next language as well.

LLVM itself was Chris Lattner realizing that it would be more practical to re-engineer the entire C/C++ compilation chain from end to end, rather than try to get GCC to work the way he thought it should. There’s precedent.

2 Likes

better to start from

Visual Studio is not dedicated or specific to C#. It is a general IDE that supports many languages through extensions. This extensibility permeates all the functions of the IDE, from syntax highlighting to the project system, to the debugger. Anyone can add language support through the extensibility model. In its history, it has had support for C/C++, Pascal, Fortran, Cobol, Java, typescript, javascript, and others.

Jetbrains Rider comes to mind for an IDE targeted towards C#. It requires a license though

On windows I started to use RAD Debugger,
It’s not integrated with my editor, but works out of the box with zig and much better than windbg.

Still alpha, but better than everything else I tested. 64Bit only.

I don’t have a good debugging strategy for debugging Zig on Windows (particularly since I dislike VSCode very much) but on Linux I just use gdb. It’s able to work with it quite well from my experience. But dedicated support in debuggers would always be better.

1 Like

Wow, the RAD debugger works much better than what I expected, especially for an alpha project. Memory, registers, breakpoints – it’s definitely a good start.

1 Like

try rustrover with zigbrains plugin

1 Like

Thanks a lot. Now I can easily debug my UTs in VS Code.

1 Like

I’ve been trying to get it working with RAD but for some reason I can’t. I can run the program with rad but the debug info doesn’t show up. Literally just trying to debug hello world.

(edit - I’m new with both zig and rad )

I’ve no experience with the rad debugger but i wonder if you have a similar issue as here: No symbol in LLDB debugger

if you are using zig 0.15+ on x86_64 linux, then the custom backend is enabled by default in debug mode.

You can force the use of llvm with .use_llvm = true for your compile options, or -fllvm if you’re not using the build system.

1 Like

if you’re wondering why debug info with the custom backends doesn’t work; it’s 2 things, it uses DWARF 5 format which majority of debuggers have yet to update to.
It also has zig specific extensions to make debug info for incremental builds much easier to manage.

Even with dwarf 5, zig isn’t officially supported, though it is in the draft for dwarf 6. So debuggers won’t necessarily support zig.
Only the zig lldb fork supports zig afaik, there are some wip debuggers in zig that will likely support zig’s extensions but i dont think any of them currently do.

The reason debug info works with llvm is cause zig uses c++ debug info, which is less than accurate but works well enough for simple debugging.

8 Likes