Table of Contents Previous Slide Next Slide

Software Development in the UNIX Environment
Debugging Your Code

Two commonly used debuggers:

Other platforms-specfic debuggers

List of Commonly Used GDB Commands:

run - run the program under gdb
run args - run the program with argument 'args'
backtrace - print a trace of all stack frames
help - get help on various gdb commands
quit - quit gdb

list - list the 10 lines surrounding the code jsut executed
list line1,line2 - list from line1 to line2 in the file currently being debugged
list function - list the first 10 lines from this function

print p - print the value of variable p
print *p - print the value that is pointed to by p
whatis p - print data type of expression p
ptype p - print defintion of p (typedef, struct, class, union)
print function::variable - print the value of a variable in the given function
print *base@length - to print array (or memory location) starting at base and going for 'length' value (ex *b@10)
print array[element] - print array elements
set variable - assign a value to a variable ( x[2] =5)

break line number - set a breakpoint at the specified line-number
break function - set a breakpoint at the start of this function
break line-number if condition -set a breakpoint at this line number if condition is true
break function if condition -set a breakpoint at this function if condition is true
break filename:line number - set a breakpoint at this line number in this source file
break filename:function - set a breakpoint at this function in this source file
info breakpoints - print out information about all breakpoints
delete # - delete breakpoint id#
clear line# - clear breakpoint at this line #
clear function - clear breakpoint at beginning of this function
disable # -disable breakpoint #
enable # - enable breakpoint #

watchpoint expression -stops execution whenever the value of expression changes

step - executes the next program line
next - executes the next program line but executes an entire function if the next line is a function
down - move down the stack frame
up - move up the stack frame

info signals - show how gdb handles various signals
signal # - send a signal to a program
handle SIGNAL_NAME action - tell gdb how to handle a signal