UH Navigation bar CS VNET NSM UH SEARCH

Computer Science Department Unix Primer

Debugging

The default GNU debugger is gdb. In order for gdb to be helpful, you need to use the -g option while compiling your programs. This includes symbol information such as your variable and function names in the executable. This information is usually not included because it is not required for your program to run.

The syntax of the gdb command is:

gdb executable [corefile]

The corefile option allows you to examine a run that has been core-dumped, meaning that you have already tried to run the program, but it crashed, leaving behind a dump of all its allocated memory pages and other vital info. If you have a corefile, you can see the program state from the instant that your program crashed, and look for anomalies. When dealing with segmentation faults, pay special attention to increment variables, pointers being accessed, and unterminated text strings. If you try to read or write a memory location outside your allocated memory pages, this will cause a segmentation fault.

University of Houston State of Texas Privacy and Policies Homeland Security Compact with Texans Reporting Copyright Infringement Contact U H Feedback Site Map Statewide Search U H System