0

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)

Holister
  • 13
  • 5

2 Answers2

1

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?

Community
  • 1
  • 1
Andrew
  • 3,770
  • 15
  • 22
0

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:

  • Names of variables and functions
  • For each intruction: full path of source file, line in the file and name of the function it is in
eerorika
  • 232,697
  • 12
  • 197
  • 326
  • How about Beej's Guide ? [link(]http://beej.us/guide/bggdb/) I mean, he can see source code, maybe the example is simple but ... how its posible? – Holister Nov 18 '15 at 19:34
  • 2
    @Holister it's possible because he has the source code on the system where he's debugging. – eerorika Nov 18 '15 at 22:37