Debug Zig on Windows

Hello, I’ve searched online and found a few posts about setting zig up for debugging on windows with vs code but I cannot get it to work. I’ve been trying on and off for the past 2 months but for some reason I just cannot get it to actually debug any thing.

I’m using windows 11 and visual studio code. I have the c++ modules installed from visual studio. Does anyone have any ideas or suggestions on how to get it to work?

This is my launch.json
This is my tasks.json
My build.zig

Same here.
But if debugging inside vsc is not set in stone for you, you should take a look at the RAD debugger.

I saw this mentioned on a reddit thread. Is it easy to set up?

You download the binary, and it just works. Couldn’t be easier!

Thank you I will check it out.

This is the debugger right? GitHub - EpicGamesExt/raddebugger: A native, user-mode, multi-process, graphical debugger.

Yes, it is.

Try the CodeLLDB extension, this should work out of the box:

…but also see the Windows specific notes: Windows · vadimcn/codelldb Wiki · GitHub

(PS: after trying out the most recent version maybe I promised to much… I can’t get CodeLLDB to create a template launch.json file on Windows)

I would first try a minimal launch.json without any build task magic or non-required options, e.g.:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "debug",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/zig-out/bin/zigboy.exe",
            "cwd": "${workspaceFolder}",
        }
    ]
}

This launch.json works here (sokol-zig examples) with the MS C/C++ Extension and the Zig extension installed (without the Zig extension to identify Zig files as source code VSCode wouldn’t let me set breakpoints).

You just need to build the debuggee manually via zig build so that the executable is placed into zig-out/bin (you should check that it’s there, because just a zig run won’t place an executable into zig-out), and then press F5 to start a debug session.

1 Like

Note that CodeLLDB type is "lldb".
i.e.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch zigboy Exe",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/zig-out/bin/zigboy.exe",
            "cwd": "${workspaceFolder}"
        }
    ]
}

CodeLLDB installs it’s own copy of lldb.

If you have lldb allready installed and usable in your PATH you can also use the LLDB DAP vscode extension provided by llvm. Their launch.json type is "lldb-dap".


Another option for windows debugging is WinDbg, that support time travel debugging.
Install by running winget install Microsoft.WinDbg

Yeah, but I didn’t even get that far when I just tried the current CodeLLDB version - so I tried the MSVC debugger integration from the MS C/C++ Extension and that also worked :slight_smile: Normally VSCode offers to create a launch.json template for all debug extensions (e.g. you get a dropdown with ‘CodeLLDB’ in it), but that just did nothing. It looks like there’s some regression in CodeLLDB or VSCode on Windows.