Debugging with GDB Manual HP WDB v6.3 (5900-2180, August 2012)
in the following excerpt from a debugging session, the f (frame) command
shows that execution is stopped at line 206; yet when we use until, we
get to line 195:
((gdb)) f
#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
206 expand_input();
((gdb)) 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. The until 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 than until 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 “Setting breakpoints” (page 39)). This form of
the command uses breakpoints, and hence is quicker than until without
an argument.
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 GDB automatically display the next instruction to
be executed, each time your program stops. See “Automatic display”
(page 67).
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.
5.3 Signals
A signal is an asynchronous event that can happen in a program. The operating system defines
the possible kinds of signals, and gives each kind a name and a number. For example, in Unix
SIGINT is the signal a program gets when you type an interrupt character (often C- c); SIGSEGV
is the signal a program gets from referencing a place in memory far away from all the areas in
use; SIGALRM occurs when the alarm clock timer goes off (which happens only if your program
has requested an alarm).
Some signals, including SIGALRM, are a normal part of the functioning of your program. Others,
such as SIGSEGV, indicate errors; these signals are fatal (they kill your program immediately) if
the program has not specified in advance some other way to handle the signal. SIGINT does not
indicate an error in your program, but it is normally fatal so it can carry out the purpose of the
interrupt: to kill the program.
GDB has the ability to detect any occurrence of a signal in your program. You can tell GDB in
advance what to do for each kind of signal.
Normally, GDB is set up to ignore non-erroneous signals like SIGALRM (so as not to interfere with
their role in the functioning of your program) but to stop your program immediately whenever an
error signal happens. You can change these settings with the handle command.
50 Stopping and Continuing