Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




5 Compiling for debugging

Normally, an executable file does not contain any references to the original program source code, such as variable names or line-numbers--the executable file is simply the sequence of machine code instructions produced by the compiler. This is insufficient for debugging, since there is no easy way to find the cause of an error if the program crashes.

GCC provides the -g debug option to store additional debugging information in object files and executables. This debugging information allows errors to be traced back from a specific machine instruction to the corresponding line in the original source file. The execution of a program compiled with -g can also be followed in a debugger, such as the GNU Debugger gdb (for more information, see "Debugging with GDB: The GNU Source-Level Debugger", section Further reading). Using a debugger allows the values of variables to be examined while the program is running.

The debug compilation option works by storing the names and source code line-numbers of functions and variables in a symbol table in the object file or executable.

  Published under the terms of the GNU General Public License Design by Interspire