I'm getting tired of having to keep my source code untouched until I'm through with its debugging. Any time I change my code, GDB starts complaining about it:
warning: Source file is more recent than executable.
until I recompile it, which can not always be done quickly. I think it would be great if it was possible to include a program's source code into its binary and to make GDB use it instead of its up-to-date version.
Could anyone suggest a way how to do it? Has this been implemented at all?
After you compile your code, you can copy of the source code to a different location.
Then, in gdb you can set the directory where gdb is looking for the source code:
set directories /your/new/directory
.
Now, gdb will work with the source code found in that directory and you can change the original source code without gdb noticing.
Source code embedding is a feature in DWARF v5. Oddly gcc 11.1 and gdb seem to be completely missing support. Clang supports it though.
clang-13 -gdwarf-5 -gembed-source hello.c -o hello
Unfortunately, lldb does not appear to be able to use the embedded source yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With