[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5.2 Continuing and Stepping
Continuing means resuming program execution until your program
completes normally. In contrast, stepping means executing just
one more “step” of your program, where “step” may mean either one
line of source code, or one machine instruction (depending on what
particular command you use). Either when continuing or when stepping,
your program may stop even sooner, due to a breakpoint or a signal. (If
it stops due to a signal, you may want to use handle
, or use
‘signal 0’ to resume execution. See section Signals.)
-
continue [ignore-count]
-
c [ignore-count]
-
fg [ignore-count]
Resume program execution, at the address where your program last stopped; any breakpoints set at that address are bypassed. The optional argument ignore-count allows you to specify a further number of times to ignore a breakpoint at this location; its effect is like that of
ignore
(see section Break Conditions).The argument ignore-count is meaningful only when your program stopped due to a breakpoint. At other times, the argument to
continue
is ignored.The synonyms
c
andfg
(for foreground, as the debugged program is deemed to be the foreground program) are provided purely for convenience, and have exactly the same behavior ascontinue
.
To resume execution at a different place, you can use return
(see section Returning from a Function) to go back to the
calling function; or jump
(see section Continuing at a Different Address) to go to an arbitrary location in your program.
A typical technique for using stepping is to set a breakpoint (see section Breakpoints; Watchpoints; and Catchpoints) at the beginning of the function or the section of your program where a problem is believed to lie, run your program until it stops at that breakpoint, and then step through the suspect area, examining the variables that are interesting, until you see the problem happen.
-
step
Continue running your program until control reaches a different source line, then stop it and return control to No value for GDBN. This command is abbreviated
s
.Warning: If you use the
step
command while control is within a function that was compiled without debugging information, execution proceeds until control reaches a function that does have debugging information. Likewise, it will not step into a function which is compiled without debugging information. To step through functions without debugging information, use thestepi
command, described below.The
step
command only stops at the first instruction of a source line. This prevents the multiple stops that could otherwise occur inswitch
statements,for
loops, etc.step
continues to stop if a function that has debugging information is called within the line. In other words,step
steps inside any functions called within the line.Also, the
step
command only enters a function if there is line number information for the function. Otherwise it acts like thenext
command. This avoids problems when usingcc -gl
on MIPS machines. Previously,step
entered subroutines if there was any debugging information about the routine.-
step count
Continue running as in
step
, but do so count times. If a breakpoint is reached, or a signal not related to stepping occurs before count steps, stepping stops right away.-
next [count]
Continue to the next source line in the current (innermost) stack frame. This is similar to
step
, but function calls that appear within the line of code are executed without stopping. Execution stops when control reaches a different line of code at the original stack level that was executing when you gave thenext
command. This command is abbreviatedn
.An argument count is a repeat count, as for
step
.The
next
command only stops at the first instruction of a source line. This prevents multiple stops that could otherwise occur inswitch
statements,for
loops, etc.-
set step-mode
-
set step-mode on
The
set step-mode on
command causes thestep
command to stop at the first instruction of a function which contains no debug line information rather than stepping over it.This is useful in cases where you may be interested in inspecting the machine instructions of a function which has no symbolic info and do not want No value for GDBN to automatically skip over this function.
-
set step-mode off
Causes the
step
command to step over any functions which contains no debug information. This is the default.-
show step-mode
Show whether No value for GDBN will stop in or step over functions without source line debug information.
-
finish
Continue running until just after function in the selected stack frame returns. Print the returned value (if any).
Contrast this with the
return
command (see section Returning from a Function).-
until
-
u
Continue running until a source line past the current line, in the current stack frame, is reached. This command is used to avoid single stepping through a loop more than once. It is like the
next
command, except that whenuntil
encounters a jump, it automatically continues execution until the program counter is greater than the address of the jump.This means that when you reach the end of a loop after single stepping though it,
until
makes your program continue execution until it exits the loop. In contrast, anext
command at the end of a loop simply steps back to the beginning of the loop, which forces you to step through the next iteration.until
always stops your program if it attempts to exit the current stack frame.until
may produce somewhat counterintuitive results if the order of machine code does not match the order of the source lines. For example, in the following excerpt from a debugging session, thef
(frame
) command shows that execution is stopped at line206
; yet when we useuntil
, we get to line195
:(No value for GDBP) f #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 206 expand_input(); (No value for GDBP) until 195 for ( ; argc > 0; NEXTARG) {
This happened because, for execution efficiency, the compiler had generated code for the loop closure test at the end, rather than the start, of the loop—even though the test in a C
for
-loop is written before the body of the loop. Theuntil
command appeared to step back to the beginning of the loop when it advanced to this expression; however, it has not really gone to an earlier statement—not in terms of the actual machine code.until
with no argument works by means of single instruction stepping, and hence is slower thanuntil
with an argument.-
until location
-
u location
Continue running your program until either the specified location is reached, or the current stack frame returns. location is any of the forms of argument acceptable to
break
(see section Setting Breakpoints). This form of the command uses breakpoints, and hence is quicker thanuntil
without an argument. The specified location is actually reached only if it is in the current frame. This implies thatuntil
can be used to skip over recursive function invocations. For instance in the code below, if the current location is line96
, issuinguntil 99
will execute the program up to line99
in the same invocation of factorial, i.e., after the inner invocations have returned.94 int factorial (int value) 95 { 96 if (value > 1) { 97 value *= factorial (value - 1); 98 } 99 return (value); 100 }
-
advance location
Continue running the program up to the given location. An argument is required, which should be of the same form as arguments for the
break
command. Execution will also stop upon exit from the current stack frame. This command is similar tountil
, butadvance
will not skip over recursive function calls, and the target location doesn't have to be in the same frame as the current one.-
stepi
-
stepi arg
-
si
Execute one machine instruction, then stop and return to the debugger.
It is often useful to do ‘display/i $pc’ when stepping by machine instructions. This makes No value for GDBN automatically display the next instruction to be executed, each time your program stops. See section Automatic Display.
An argument is a repeat count, as in
step
.-
nexti
-
nexti arg
-
ni
Execute one machine instruction, but if it is a function call, proceed until the function returns.
An argument is a repeat count, as in
next
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |