Next: An example in
Up: Tracing code
Previous: Tracing code
When you want to know what exactly is happening in your program, you have to
trace it with the debugger. To do this, use the following commands in GDB
(the abbreviation of a command is given between parentheses):
- list (l): List a part of the program.
- step (s): Step the program until it reaches a different source line.
- next (n): Like the
step
command as long as function calls do not
happen; when they do, the call is treated as one instruction, ie. the
function is not entered but it is executed.
- break (b): Set a breakpoint at a specified line or function. A
breakpoint is a point at which execution will be stopped when the program is
running.
- print (p): Print the value of a variable.
With the program bug
, a debugging session could look like this:
SE Praktikum
Tue Aug 13 11:13:23 MET DST 1996