Reputation: 13
I was debugging an application created in C ++ for Linux when I realized that the executables in release version were compiled with the -g flag.
My concern is whether it is possible to read the source code of the executable through gdb using list or backtrace (exploiting some know core dump or antoher method)
Upvotes: 0
Views: 1184
Reputation: 4771
No, the source code is not included in the executable, even when compiled with -g
. What is included are references to the source code, so there's a mapping between program addresses and file and line numbers.
There will also be information in the debug that describe the functions in your program, so there will be information describing each function, the types taken and returned, and what local variables it contains, there's also information about which addresses correspond to which functions. All your types and global variables will also be described in the debug information.
It is possible to split the debug information out of you program using objcopy, the following is taken from the gdb online manual (https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html)
objcopy --only-keep-debug foo foo.debug
strip -g foo
objcopy --add-gnu-debuglink=foo.debug foo
This takes the debug information out of foo
and places it in foo.debug
, the strips the debug information out of foo
and adds a link between foo.debug
back to foo
.
Now you, as the developer can debug release builds by loading the additional foo.debug
file containing the debug data, while the customer is only given foo
and so does not see the debug information.
A more detailed look at creating split debug information can be found here How to generate gcc debug symbol outside the build target?
Upvotes: 1
Reputation: 238401
No, source code is not included in a binary built with -g
and therefore it will not be possible to read it using only the binary.
Things that they may be able to read include:
Upvotes: 0