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"?

- 298
- 2
- 17
-
2yes, you can. did you try? – Sourav Ghosh Apr 11 '17 at 10:32
1 Answers
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).

- 1
- 1

- 133,132
- 16
- 183
- 261