Using LLDB to debug Rust/c++ on Windows

Fist of all, I have been looking around and it doesn’t seem like there are a lot of Windows using LLDB. I can’t find any official info about whether or not it is supported and I haven’t been able to get it to work myself. Is there anyone here that can share there experience?

Here is what I have done so far:

Create a Rust project, load that executable in lldb and try to break in a breakpoint:

cargo new lldb-test
cd lldb-test
cargo build
lldb .\target\debug\lldb-test.exe

in the lldb REPL:

(lldb) image list
[  0] B0075AFD-6D58-4D2C-9A92-229CECAB68C7-00000001 0x0000000140000000 <my_path>\lldb-test\ta
rget\debug\lldb-test.exe
(lldb) b main.rs:2
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.

and if I run it never breaks in the bp.

I tried this on WSL and it worked just fine (stopped in the bp).

I also tested with C++:

main.cpp:

#include <iostream>

int main()
{
    std::cout << "Hello World" << std::endl;
}

Test:

cl .\main.cpp /Za /Zi /EHsc

output:

Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30133 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

main.cpp
Microsoft (R) Incremental Linker Version 14.29.30133.0    
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe 
/debug
main.obj
lldb .\main.exe
(lldb) target create ".\\main.exe"
(lldb) Current executable set to '<my_path>\lldb-test\main.exe' (i386).
(lldb) image list
[  0] 080F38EB-06B9-4DD5-8F38-1E1E0175CAD1-00000001 0x00400000 <my_path>\lldb-test\main.exe 
(lldb) b main.cpp:5
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) run
(lldb) Process 14660 launched: '<my_path>\lldb-test\main.exe' (i386)
Process 14660 exited with status = 0 (0x00000000)
(lldb) 

In short, the same happens, the run finished without hitting the bg.

PS:
I’m using:
lldb version 16.0.1, installed with chocolatey.
Windows 10.

Did you build your targets with debug turned on? For the Windows c++ compiler, I believe that’s /Zi /Od . Without debug info you can’t set source breakpoints.

Rust ships rust-lldb and rust-gdb.

I believe cargo build used builds debug mode by default. As you can see the target is in a debug subfolder and there is a .pdb file created.

For the c++ example, as you can see I’m using the /Zi flag. I didn’t use /Od (no optimation) but I will try it. But there is a .pdb file created so there should be debug info available.

Now, I don’t know if lldb did load the .pdb file. Is there a way to confirm that?

Interesting, I wasn’t aware of this. Should it be installed automatically with cargo/rust-analyzer?

Any more info/links you can provide?

.cargo/bin/rust-lldb, it is in the same directory as rustc on my machine. Probably rustup has installed it. rust-lldb is a lldb with some support for Rust.

cargo build is the debug build and cargo build --release is with less debug info.

You can check that lldb can resolve sources. Load the program into lldb, but don’t run it. Type “list main”. If it prints out the source for main, then debug info is loaded.

Ok, so it looks like it’s not able to load the debug symbols:

lldb .\main.exe
(lldb) target create ".\\main.exe"
(lldb) Current executable set to ´<my_path>\lldb-test\cpp\main.exe' (i386).
(lldb) list main
error: Could not find function named: "main".
(lldb)

Is there a way to explicitly load the .pdb file? Or should it find it automatically?

I didn’t actually have rustup installed. I just installed the a packet from chocolatey called rust-ms.

But anyway, I installed rustup and indeed it has a rust-lldb, but now I get this:

rust-lldb.exe .\target\debug\lldb-rust-test.exe
error: the 'rust-lldb.exe' binary, normally provided by the 'rustc' component, is not applicable to the 'stable-x86_64-pc-w
indows-msvc' toolchain

Assuming your pdb is next to your exe, it should find it automatically.

Not being able to find function “main” means symbols aren’t loaded, which probably also means debug info isn’t loaded.

lab.llvm.org has an AArch64 Windows LLDB bot at Buildbot . I don’t know if it’s using pdb or dwarf.

@omjavaid can you confirm whether our (Linaro’s) bot uses PDB or DWARF?

I don’t see any flags in the CMake for it, but not sure what the default is.

This looks like a missing DIA SDK or missing msdia*.dll in environment. LLDB requires it for debugging using PDBs and that is the default format on windows. In case you dont have it installed you can generate dwarf symbols with the specific flag to your compiler.

LLDB’s shell testsuite uses clang-cl on windows and it defaults to PDB.

However in API tests we specify dwarf explicitly. API tests do not support testing with PDB at the moment.

FWIW, LLDB does have some support for parsing PDBs internally too - but it’s less complete than the codepath that uses the DIA SDK.

If it doesn’t even find the main function, it sounds more like it hasn’t found the PDB file at all.

This is how you set DIA SDK dlls to the path for arm64. In case you are running on x86 or amd64 set the architecture appropriately.

set MSVC_INSTALL_DIR=c:\Program Files\Microsoft Visual Studio\2022\Community

set “PATH=%MSVC_INSTALL_DIR%\DIA SDK\bin\arm64;%PATH%”

FWIW, I tested the example commands, cl .\main.cpp /Za /Zi /EHsc, and my LLDBs do manage to run list main just fine on it. I tested both with a version built without DIA SDK, a toolchain from Release llvm-mingw 20230320 with LLVM 16.0.0 · mstorsjo/llvm-mingw · GitHub, and a copy of LLDB built locally with MSVC with the DIA SDK enabled.

(The LLDB from the official LLVM release that I have installed doesn’t start, since it requires a different version of Python than what I happen to have installed.)

In order to use LLDB’s native PDB reading support please set LLDB_USE_NATIVE_PDB_READER=1

1 Like

This did the trick, thank you so much