Debugging Zig code is a bit of a dark art at present:. There’s no official documentation on the subject, and the lore involved is scattered among blog posts, video, Ziggit questions, the Discord, and so on.
So I thought I’d start a topic as a place to share knowledge of the dark art. I also want to improve my own workflow here, so I’ll start with what I have working.
VSCode and CodeLLDB
I do most of my development in Neovim now (I use Neovim btw), but not debugging… yet.
For that I’m using VSCode with a great plugin, Zig language extras, which adds some code actions, specifically to tests: it has run test
and debug test
. That second one is what I want to reproduce: writing a test which produces the defect I need to address, and running it straight from the file, is basically ideal: you get a little custom program focused on the problem, and when it’s fixed, you have a regression test.
Once I managed to get the LLDB pretty printers from the Zig repo wired up to CodeLLDB, this is a generally pleasant workflow. I don’t remember how I did that well enough to specify it in detail, but fortunately I don’t have to because I started a thread asking for help at the time.
I’d probably just stick with what works, but there’s a significant limitation in the plugin: it uses the older zig test
system, which doesn’t integrate with the build system. So it can’t launch debugging sessions for any code which relies on an import. As time goes by that describes less and less of my projects.
I haven’t been able to figure out how to debug straight from a test built with zig build test
, in VSCode or elsewhere. I’d rather be using DAP anyhow, but even setting that up to work with Zig is not something I’ve found docs about (they all cover Go for some reason).
So I’m putting it out there to the crowd: how do you debug Zig code? What’s your setup like, how did you get it running? What are the critical yet esoteric details someone setting this up would stumble on?
I put this in Explain rather than Help, because there are a bunch of operating systems and tools to do this, and I want to hear about all of them!