Last updated:2026-10-12
Debugging Bazel Builds with LLDB¶
Today, while debugging, I found that files compiled by Bazel could no longer be debugged on my Mac — all I got was assembly.
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000fd0 hello_world`main
hello_world`main:
-> 0x100000fd0 <+0>: pushq %rbp
0x100000fd1 <+1>: movq %rsp, %rbp
0x100000fd4 <+4>: subq $0x60, %rsp
0x100000fd8 <+8>: movl $0x0, -0x4(%rbp)
(lldb) quit
How to solve it?
The default is standalone, and we need to disable it; here we use local, which means the output will be linked against its dependencies instead of using the default standalone strategy.
With this, the code becomes visible.
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000fdf hello_world`main at hello_world.cc:14:21
11
12 int main() {
13 // Create a thread pool
-> 14 auto threadPool = GetCpuThreadPool();
15 if (!threadPool) {
Why This Happens¶
Why is that? Bazel's default standalone spawn strategy runs compile actions inside a sandbox; on macOS the sandbox implementation (sandbox-exec) skews debug info paths and dSYM generation, and the binary ends up with a broken symbol table — so LLDB can only show you assembly.
Switch to:
This means compile actions run directly on the local machine without entering the sandbox; symbol information is fully preserved, and breakpoints land on the correct source lines. I recommend writing it straight into the project's .bazelrc, once and for all:
(1) when debugging, use bazel build -c dbg //... or bazel run -c dbg to make sure -O0 -g is on;
(2) on Linux the default sandbox generally does not affect debug symbols; this problem mainly shows up on macOS;
(3) if you still cannot see the source code, check the dSYM: dsymutil ./hello_world && lldb ./hello_world.
With that, Bazel + LLDB work happily together. If you have hit other pitfalls, feel free to add them in the comments~
Related Topics¶
- Building C++ Projects with Bazel | C++那些事
- CMake Essentials in Practice | C++那些事
- Getting Started with the Conan C++ Package Manager | C++那些事
- C++ Insights Compile-Time Observation | C++那些事
- Interactive C++ in Jupyter Notebook | C++那些事
- C++ string to int | C++那些事
- The C++ dbg-macro Debugging Macro | C++那些事
- GCC Compilation Flags Explained | C++那些事
- Debugging C++ Programs with GDB | C++那些事
- GDB Python Extension Debugging | C++那些事