Debug sessions with gdb and ddd
A graphical frontend for gdb is for example DDD. Type in a empty line for repeating the last command.
To debug program with a bigger symbol table which can be used by gdb use gcc option -g
gcc -g ...
further information for gdb3
Start debug session:
gdb program [corefile]
The corefile is a file from a ealier run and maybe a core dump file. To end gdb use "quit" or "q".
commands inside gdb
lists the commands around the point where the program stops at this time. If you repeat the command "list" you get the lines after these which you have already seen. You can repeat that until you reach the end of the program.
lists lines 1 until 5.
runs the program.
run arg1 arg2
runs the program with parameters
set args arg1 arg2
gives arguments after run.
break linenumber if expression
break function if expression
continues execution of the program.
overview of the breakpoints you have defined.
deletes breakpoint number 2.
removes all breakpoints.
disables breakpoint 1
enables it again
executes the next assignment or steps into a function dependent where the program is currently.
executes next assignment or steps over a function if current position is a function call.
shows values of variables.
print myfunction(2, 4711)
calls function with these parameters.
You get an output with $1, $2, ... . These variables can be used:
print $1 + $2
$3 = 4711
prints first ten addresses of the array.
gives 10 values beginning with the first position.
gives 10 values beginning with the twentieth position.
returns type of i e.g. "type = int"
gives more information what is helpful with structures. "whatis" gives only "type = structure" but "ptype" gives the whole definition of that structure.
find position where the program breaks its execution due to SIGSEGV.