Search code examples
macosclangdwarf

No debug info / source code with LLDB on OSX


I'm not able to see source code in lldb, despite trying to the advice of LLDB not showing source code

I've boiled this down to a simple C++17 program that is compiled with the following command. I'm running on OSX with clang 7.0.1 that I've compiled myself from source, but my lldb is the XCode-installed one (this may be a problem?).

Here's my compile command:

clang++ -std=c++17 -march=native -Wall -g -O0  main.cpp -o main

Note that main/main.dSYM/Contents/Resources/DWARF is created when I compile and that seems fine.

One clear issue, though, is that debug info is not in the binary and the object file can't be found at all:

$ dsymutil main
warning: (x86_64) /var/folders/c1/vxvr6h9x10b8dbsxhh6nx05h0000gn/T/main-43ca25.o unable to open object file: No such file or directory
warning: no debug symbols in executable (-arch x86_64)

I was under the impression that I can just compile with debug info (via -g) and have everything "just work" but that's clearly not the case.

How can I get debug symbols to work so I can use lldb?


Solution

  • I was able to solve this problem by removing the -flto linker flag that I didn't realize I had on. Apparently, when LTO is enabled, debugging symbols do not work.