Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig doesn't make PDB debug files correctly on Windows? #22039

Open
heavymetalmixer opened this issue Nov 20, 2024 · 1 comment
Open

Zig doesn't make PDB debug files correctly on Windows? #22039

heavymetalmixer opened this issue Nov 20, 2024 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@heavymetalmixer
Copy link

heavymetalmixer commented Nov 20, 2024

Zig Version

0.13.0

EDIT: Both LLDB and MSVC Debugger ignore imports. MSVC debugger jumps to the main function if there's a breakpoint on an import, LLDB looks for the next breakpoint and ends the debugging session if there's none.


The following are steps to reproduce the issue, which is not being able to debug Zig binaries on Windows with PDB files, and workarounds to make the debugging possible. I tested them on Windows 10 Pro x64 in VS Code, but the first link comes from someone who tried them on NeoVim.

Steps to Reproduce and Observed Behavior

Step 1: Install CodeLLDB extension in VS Code, it integrates the LLDB debugger in VS Code to debug C, C++ and Zig files (maybe more from LLVM).

Step 2: Create the .vscode folder inside the project's folder and create a "launch.json file" inside that folder.

Step 3: Paste the following inside the launch.json file and save it:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "CodeLLDB Debug",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/zig-out/bin/hello-world.exe",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopOnEntry": false,
            "terminal": "integrated",
        }
    ]
}

Step 4: Try to run the debugger and see that it ignores all breakpoints and only runs the binary.

If you set "stopOnEntry" to true, then VS Code will show you "Exception 0x80000003" between assembly code and the debugger will crash after a few debugging steps.

Note: The same issue happens on Zig 0.12.0 and 0.12.1. I didn't test it with older versions than those.

z1
z2


Workarounds

  1. Create the environment variable for your system LLDB_USE_NATIVE_PDB_READER and set it to 1. Restart VSCode, and CodeLLDB should be able to debug Zig binaries with DPB debug files as intented.

Given that this workaround isn't necessary for debugging C and C++ files it makes me think that Zig creates "broken" PDB files or in a non-standard way.

Both links have a lot of info on how LLDB works on VSCode, I recommend you read them.

Sources:
https://www.reddit.com/r/neovim/comments/1eeydfp/solving_codelldb_with_dap_not_picking_up_pdb/
https://werat.dev/blog/debugging-wine-with-lldb-and-vscode/


  1. The other workaround is to use the Microsoft debugger instead by using the following inside the launch.json file:
{
      "name": "MSVC Debug",
      "type": "cppvsdbg",
      "request": "launch",
      "program": "${workspaceFolder}/zig-out/bin/<executable name>.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "console": "internalConsole",
}

Expected Behavior

LLDB should be able to debug Zig binaries on Windows without issues nor having to use workarounds. On VS Code specifically, when using the CodeLLDB extension or when using LLDB manually from the console.

It would also be nice if Zig had an option to create DWARF files instead of PDB ones to be able to debug the binaries with GDB.

@heavymetalmixer heavymetalmixer added the bug Observed behavior contradicts documented or intended behavior label Nov 20, 2024
@heavymetalmixer
Copy link
Author

heavymetalmixer commented Nov 26, 2024

One more "bug" discovered (I don't if it's really a bug or intented behavior):

Both LLDB and MSVC Debugger ignore imports. MSVC debugger jumps to the nearest function if there's a breakpoint on an import, LLDB looks for the next breakpoint and ends the debugging session if there's none.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

1 participant