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).
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.
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?
.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
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, 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.)