gdb, lldb not showing line numbers for binaries compiled from stdin

Alec Jacobson

June 17, 2014

weblog/

I recently figured out why my self-compiling C++ files didn't play nicely with debuggers. It seems that when compiling with gcc (from Macports) and reading in the C++ code from standard input (using the -x c++ - arguments), the debuggers gdb and lldb won't show high level information like code snippets or line numbers even if the -g option is present. Seems that gcc isn't really including that information in the binary, rather it's looking it up at run-time. You can verify this by changing the source file after compiling and then running the debugger. clang++ on the otherhand seems to embedd information from stdin into the executable so that it can be properly debugged.

In the meantime, I'll keep using gcc but for self-compiling routines I need to use auxiliary files.