LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   -g and -o in gdb (https://www.linuxquestions.org/questions/linux-newbie-8/g-and-o-in-gdb-4175432131/)

randiijo 10-14-2012 07:25 AM

-g and -o in gdb
 
i'm newbie in linux gcc,gdb

when i make a debug.c data, and go to gcc
and put this
$gcc -g -o debugfile debug.c
$gdb debugfile
and then sentence showed up "Reading symbols from........./debugfile...done

if i use
$gcc -o debugfile debug.c
$gdb debugfile

this sentence sentence showed up
"Reading symbols from.........../debugfile...(no debugging symbols found)"

what is the causes of these different output

thank you.. sorry for bad english use

Whyte 10-14-2012 09:29 AM

That's quite simple... even if you decide to name the output file "debugfile", it doesn't actually make it be a debug file... it's just the compilation output (a binary executable).

What actually makes it "debuggable" is in fact the '-g' option:

Code:

-g
Produce debugging information in the operating system's native format. GDB can work with this debugging information.

(taken from the kilometric gcc manual, 'man gcc')

If you add the '-g' option, debugging symbols will be added to the output file. If you don't, debugging symbols will be omitted, making your program much smaller in size, but harder to debug and reverse engineer.


Edit: Oh, and as for what debugging symbols actually are... they're little bits of extra information scattered all over the program, that help gdb figure out what assembler instruction corresponds to what line of code, what memory address corresponds to what variable name, and so on. These aren't actually needed in a program to run, but they're needed to debug it.


All times are GMT -5. The time now is 09:08 PM.