The GDB Debugger
--By Traci C. Wu, cs60 handout, Fall 98

Introduction:

The Debugger GDB is a technique for finding anomalies--program bugs, it allows you to see what is going on inside another program while it executes, or what another program was doing at the moment it crashed. The way the debugger allows you to find bugs is by allowing you to run your program on a line-by-line basis, pausing the program at times or conditions that you specify and allowing you to examine variables, registers, the run time stack and other facets of program state while paused.
Function Summary:
GDB can do four main kinds of things to help you catch bugs in the act:
1. Start your program, specifying anything that might affect its behavior.
2. Make your program stop on specified conditions.
3. Examine what has happened when your program has stopped.
4. Change things in your program to allows you experiment with correcting the effects of one bug   and go on to learn about another.
Starting GDB:
In order to use the GDB, your program must have been compiled with the -g option and the executable must be in current directory.
Basic GDB commands:
help                      --ask for help (see below)
where                     --display program stack
up/down                   --navigate through the different program stack frames
list                      --see the contents of the corresponding source file
run < arglist >           --start your program with arglist as its command line
print < expr >            --display the value of an expression
break < function >        --set breakpoint at function
cont                      --continue running your program
next                      --execute next line, including function calls
step                      --execute until another line is reached
finish                    --execute until the end of the current function
quit                      --exit from GDB
Getting help:
(gdb) help
List of classes of commands:
 
aliases     -- Aliases of other commands
breakpoints -- Making program stop at certain points
data        -- Examining data
files       -- Specifying and examining files
internals   -- Maintenance commands
obscure     -- Obscure features
running     -- Running the program
stack       -- Examining the stack
status      -- Status inquiries
support     -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined-- User-defined commands
 
Type "help" followed by a class name for a list of commands in that class.
Type "help" followed by command name for full documentation.
Command name abbreviations are allowed if unambiguous.