2

If you use gdb on an executable that was compiled without "-g" flag, can you still debug? If so, what difference will you see as compared to debugging an executable compiled with a "-g"?

Sara Takaya
  • 298
  • 2
  • 17

1 Answers1

6

Adding -g option in gcc enables adding debug symbols and information. Then, while debugging, the displayed information is more human readable.

From the online manual

-g

Produce debugging information in the operating system’s native format (stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging information.

On most systems that use stabs format, -g enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but probably makes other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use -gstabs+, -gstabs, -gxcoff+, -gxcoff, or -gvms

For example, for a binary, compiled using -g, running in gdb can show the function names while without the -g, you would have seen only the function pointers (address).

Community
  • 1
  • 1
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261