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

Can't debug with LLDB on Windows #13095

Open
jarek-przygodzki opened this issue Oct 7, 2022 · 3 comments
Open

Can't debug with LLDB on Windows #13095

jarek-przygodzki opened this issue Oct 7, 2022 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior downstream An issue with a third party project that uses Zig. os-windows
Milestone

Comments

@jarek-przygodzki
Copy link

Zig Version

0.10.0-dev.4213+91b05ad47

Steps to Reproduce

  • ceate a hello-world Zig application (zig init-exe)
  • load application in lldb debugger (version 15.0.1)
PS C:\projects\Zig\hello-world> &"$env:LLVM_HOME\bin\lldb.exe" zig-out\bin\hello-world.exe
(lldb) target create "zig-out\\bin\\hello-world.exe"
(lldb) Current executable set to 'C:\projects\Zig\hello-world\zig-out\bin\hello-world.exe' (x86_64).
  • try finding symbols/setting breakpoint

Expected Behavior

Symbols are picked up automatically, debugging works.

Actual Behavior

Symbols are not picked up automatically, and attempt to add them manually fails with Assertion failed: (obj_load_address && obj_load_address != LLDB_INVALID_ADDRESS)

(lldb) add-dsym zig-out\bin\hello-world.pdb
Assertion failed: (obj_load_address && obj_load_address != LLDB_INVALID_ADDRESS), function InitializeObject, file C:\src\llvm_package_15.0.1\llvm-project\lldb\source\Plugins\SymbolFile\PDB\SymbolFilePDB.cpp, line 199
backtrace leading to the failure:
please file a bug report against lldb reporting this failure log, and as many details as possible
symbol file 'C:\projects\Zig\hello-world\zig-out\bin\hello-world.pdb' has been added to 'C:\projects\Zig\hello-world\zig-out\bin\hello-world.exe'

With LLDB_USE_NATIVE_PDB_READER="yes" symbols can be loaded

PS C:\projects\Zig\hello-world> $env:LLDB_USE_NATIVE_PDB_READER="yes"
PS C:\projects\Zig\hello-world> &"$env:LLVM_HOME\bin\lldb.exe" zig-out\bin\hello-world.exe
(lldb) target create "zig-out\\bin\\hello-world.exe"
(lldb) Current executable set to 'C:\projects\Zig\hello-world\zig-out\bin\hello-world.exe' (x86_64).
(lldb) add-dsym zig-out\bin\hello-world.pdb
symbol file 'C:\projects\Zig\hello-world\zig-out\bin\hello-world.pdb' has been added to 'C:\projects\Zig\hello-world\zig-out\bin\hello-world.exe'
(lldb) image lookup -n main
1 match found in C:\projects\Zig\hello-world\zig-out\bin\hello-world.exe:
        Address: hello-world.exe[0x00000001400015c0] (hello-world.exe..text + 1472)
        Summary: hello-world.exe`main at main.zig:3
(lldb) l main
File: C:\projects\Zig\hello-world\src\main.zig
   1    const std = @import("std");
   2
   3    pub fn main() !void {
   4        // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
   5        std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
   6
   7        // stdout is for the actual output of your application, for example if you
   8        // are implementing gzip, then only the compressed bytes should be sent to
   9        // stdout, not any debugging messages.
   10       const stdout_file = std.io.getStdOut().writer();
   11       var bw = std.io.bufferedWriter(stdout_file);

But lldb crashes when reaching an breakpoint

(lldb) b main
Breakpoint 1: where = hello-world.exe`main + 26 at main.zig:5, address = 0x00000001400015da
(lldb) run
(lldb) Process 40128 launched: 'C:\projects\Zig\hello-world\zig-out\bin\hello-world.exe' (x86_64)PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.

Exception Code: 0xC0000005
(lldb)  #0 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x296898 C:\Program Files\LLVM\bin\liblldb.dll 0xc30ae7
 #1 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x22b2cc C:\Program Files\LLVM\bin\liblldb.dll 0x1fcbe5
 #2 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x1fcaa7 C:\Program Files\LLVM\bin\liblldb.dll 0x1b9e7d1
 #3 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x1b9d5ed C:\Program Files\LLVM\bin\liblldb.dll 0x987c32
 #4 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x9876e3 C:\Program Files\LLVM\bin\liblldb.dll 0x9879ae
 #5 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x987609 C:\Program Files\LLVM\bin\liblldb.dll 0x98814d
 #6 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x96b990 C:\Program Files\LLVM\bin\liblldb.dll 0x96d8d5
 #7 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x96e34e C:\Program Files\LLVM\bin\liblldb.dll 0x328bc1
 #8 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x462209 C:\Program Files\LLVM\bin\liblldb.dll 0x2dc3cc
 #9 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x2d74ce C:\Program Files\LLVM\bin\liblldb.dll 0x2dd375
#10 0x00007ffb16cf6898 C:\Program Files\LLVM\bin\liblldb.dll 0x2e6004 C:\Program Files\LLVM\bin\liblldb.dll 0x8ab274
#11 0x00007ffb16cf6898 (C:\Program Files\LLVM\bin\liblldb.dll+0x296898)
#12 0x00007ffb17690ae7 (C:\Program Files\LLVM\bin\liblldb.dll+0xc30ae7)
#13 0x00007ffb16c8b2cc (C:\Program Files\LLVM\bin\liblldb.dll+0x22b2cc)
0x00007FFB16CF6898, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x296898 byte(s), PyInit__lldb() + 0x1ADA98 byte(s)
0x00007FFB17690AE7, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0xC30AE7 byte(s), PyInit__lldb() + 0xB47CE7 byte(s)
0x00007FFB16C8B2CC, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x22B2CC byte(s), PyInit__lldb() + 0x1424CC byte(s)
0x00007FFB16C5CBE5, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x1FCBE5 byte(s), PyInit__lldb() + 0x113DE5 byte(s)
0x00007FFB16C5CAA7, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x1FCAA7 byte(s), PyInit__lldb() + 0x113CA7 byte(s)
0x00007FFB185FE7D1, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x1B9E7D1 byte(s), PyInit__lldb() + 0x1AB59D1 byte(s)
0x00007FFB185FD5ED, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x1B9D5ED byte(s), PyInit__lldb() + 0x1AB47ED byte(s)
0x00007FFB173E7C32, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x987C32 byte(s), PyInit__lldb() + 0x89EE32 byte(s)
0x00007FFB173E76E3, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x9876E3 byte(s), PyInit__lldb() + 0x89E8E3 byte(s)
0x00007FFB173E79AE, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x9879AE byte(s), PyInit__lldb() + 0x89EBAE byte(s)
0x00007FFB173E7609, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x987609 byte(s), PyInit__lldb() + 0x89E809 byte(s)
0x00007FFB173E814D, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x98814D byte(s), PyInit__lldb() + 0x89F34D byte(s)
0x00007FFB173CB990, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x96B990 byte(s), PyInit__lldb() + 0x882B90 byte(s)
0x00007FFB173CD8D5, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x96D8D5 byte(s), PyInit__lldb() + 0x884AD5 byte(s)
0x00007FFB173CE34E, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x96E34E byte(s), PyInit__lldb() + 0x88554E byte(s)
0x00007FFB16D88BC1, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x328BC1 byte(s), PyInit__lldb() + 0x23FDC1 byte(s)
0x00007FFB16EC2209, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x462209 byte(s), PyInit__lldb() + 0x379409 byte(s)
0x00007FFB16D3C3CC, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x2DC3CC byte(s), PyInit__lldb() + 0x1F35CC byte(s)
0x00007FFB16D374CE, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x2D74CE byte(s), PyInit__lldb() + 0x1EE6CE byte(s)
0x00007FFB16D3D375, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x2DD375 byte(s), PyInit__lldb() + 0x1F4575 byte(s)
0x00007FFB16D46004, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x2E6004 byte(s), PyInit__lldb() + 0x1FD204 byte(s)
0x00007FFB1730B274, C:\Program Files\LLVM\bin\liblldb.dll(0x00007FFB16A60000) + 0x8AB274 byte(s), PyInit__lldb() + 0x7C2474 byte(s)
0x00007FFBF1341BB2, C:\WINDOWS\System32\ucrtbase.dll(0x00007FFBF1320000) + 0x21BB2 byte(s), _configthreadlocale() + 0x92 byte(s)
0x00007FFBF39C7034, C:\WINDOWS\System32\KERNEL32.DLL(0x00007FFBF39B0000) + 0x17034 byte(s), BaseThreadInitThunk() + 0x14 byte(s)
0x00007FFBF3C826A1, C:\WINDOWS\SYSTEM32\ntdll.dll(0x00007FFBF3C30000) + 0x526A1 byte(s), RtlUserThreadStart() + 0x21 byte(s)
@jarek-przygodzki jarek-przygodzki added the bug Observed behavior contradicts documented or intended behavior label Oct 7, 2022
@andrewrk andrewrk added this to the 0.12.0 milestone Oct 14, 2022
@andrewrk andrewrk added the downstream An issue with a third party project that uses Zig. label Oct 14, 2022
@Bambofy
Copy link

Bambofy commented Apr 15, 2023

Adding LLDB_USE_NATIVE_PDB_READER="yes" to the environment variables on windows fixed this error for me too.

@sgwong
Copy link

sgwong commented May 16, 2023

Setting LLDB_USE_NATIVE_PDB_READER="yes" does make the LLDB able to debug the main function. But once you try to break point in a function other than the main, LLDB will crash. windows visual studio able to debug it and the VSCode 'cppvsdbg' also works without issues.

@heavymetalmixer
Copy link

I know this is years later, but if you still have yet to find a way to debug Zig binaries, here I have 2 workarounds (the second one only works for VS Code): #22039

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 downstream An issue with a third party project that uses Zig. os-windows
Projects
None yet
Development

No branches or pull requests

5 participants