- Normally, when we write a program, we want to be able to debug it
- that is, test it using a debugger that allows running it step by step,
- setting a break point before a given command is executed,
- looking at contents of variables during program execution, and so on.
- In order for the debugger to be able to relate between the executable program and the original source code, we need to tell the compiler to insert information to the resulting executable program that'll help the debugger. This information is called "debug information". In order to add that to our program, lets compile it differently:
$gcc -g code1.c -o code1
The "-g" flag tells the compiler to use debug info, and is recognized by mostly any compiler out there.
- You will note that the resulting file is much larger than that created without usage of the "-g" flag.
- The difference in size is due to the debug information. We may still remove this debug information using the strip command, like this:
$strip code1
You'll note that the size of the file now is even smaller than if we didn't use the "-g" flag in the first place. This is because even a program compiled without the "-g" flag contains some symbol information (function names, for instance), that the strip command removes. You may want to read strip's manual page (man strip) to understand more about what this command does.
Cem Ozdogan
2011-02-14