Debugging a Program With dbx |
Working With Signals
This chapter describes how to use
dbx
to work with signals.dbx
supports thecatch
command, which instructsdbx
to stop a program whendbx
detects any of the signals appearing on the catch list.The
dbx
commandscont
,step
, andnext
support the-sig
signal_name option, which lets you resume execution of a program with the program behaving as if it had received the signal specified in thecont
-sig
command.This chapter is organized into the following sections.
- Understanding Signal Events
- Catching Signals
- Sending a Signal in a Program
- Automatically Handling Signals
Understanding Signal Events
When a signal is to be delivered to a process that is being debugged, the signal is redirected to
dbx
by the kernel. When this happens, you usually receive a prompt. You then have two choices:
- "Cancel" the signal when the program is resumed--the default behavior of the
FIGURE 14-1 Intercepting and Cancelling the SIGINT Signalcont
command--facilitating easy interruption and resumption withSIGINT
(Control-C) as shown in FIGURE 14-1.- "Forward" the signal to the process using:
cont -sig
signalIn addition, if a certain signal is received frequently, you can arrange for
dbx
to forward automatically the signal because you do not want it displayed:
ignore
signal# "ignore"
However, the signal is still forwarded to the process. A default set of signals is automatically forwarded in this manner (see "ignore Command" in the Using dbx Commands section of the Sun WorkShop online help).
Catching Signals
By default, the catch list contains many of the more than 33 detectable signals. (The numbers depend upon the operating system and version.) You can change the default catch list by adding signals to or removing them from the default catch list.
To see the list of signals currently being trapped, type
catch
with no signal argument.
(dbx)
catch
To see a list of the signals currently being ignored by
dbx
when the program detects them, typeignore
with no signal argument.
(dbx)
ignore
Changing the Default Signal Lists
You control which signals cause the program to stop by moving the signal names from one list to the other. To move signal names, supply a signal name that currently appears on one list as an argument to the other list.
For example, to move the
QUIT
andABRT
signals from the catch list to the ignore list:
(dbx)
ignore QUIT ABRT
Trapping the FPE Signal
Often programmers working with code that requires floating point calculations want to debug exceptions generated in a program. When a floating point exception like overflow or divide by zero occurs, the system returns a reasonable answer as the result for the operation that caused the exception. Returning a reasonable answer lets the program continue executing quietly. Solaris implements the IEEE Standard for Binary Floating Point Arithmetic definitions of reasonable answers for exceptions.
Because a reasonable answer for floating point exceptions is returned, exceptions do not automatically trigger the signal
SIGFPE
.To find the cause of an exception, you need to set up a trap handler in the program so that the exception triggers the signal
SIGFPE
. (Seeieee_handler
(3m) man page for an example of a trap handler.)
ieee_handler
fpsetmask
(see thefpsetmask
(3c) man page)-ftrap
compiler flag (for FORTRAN 77 and Fortran 95, see thef77
(1) andf95
(1) man pages)When you set up a trap handler using the
ieee_handler
command, the trap enable mask in the hardware floating point status register is set. This trap enable mask causes the exception to raise theSIGFPE
signal at run time.Once you have compiled the program with the trap handler, load the program into
dbx
. Before you can catch theSIGFPE
signal, you must addFPE
to thedbx
signal catch list.
(dbx)
catch FPE
By default,
FPE
is on the ignore list.Determining Where the Exception Occurred
After adding
FPE
to the catch list, run the program indbx
. When the exception you are trapping occurs, theSIGFPE
signal is raised anddbx
stops the program. Then you can trace the call stack using thedbx
where
command to help find the specific line number of the program where the exception occurs (see "where Command" in the Using dbx Commands section of the Sun WorkShop online help).Determining the Cause of the Exception
To determine the cause of the exception, use the
regs -f
command to display the floating point state register (FSR). Look at the accrued exception (aexc
) and current exception (cexc
) fields of the register, which contain bits for the following floating-point exception conditions:
- Invalid operand
- Overflow
- Underflow
- Division by zero
- Inexact result
For more information on the floating-point state register, see Version 8 (for V8) or Version 9 (for V9) of The SPARC Architecture Manual.For more discussion and examples, see the Numerical Computation Guide.
Sending a Signal in a Program
The
dbx
cont
command supports the-sig
signal option, which lets you resume execution of a program with the program behaving as if it had received the system signal signal.For example, if a program has an interrupt handler for
SIGINT
(^C
), you can type^C
to stop the application and return control todbx
. If you issue acont
command by itself to continue program execution, the interrupt handler never executes. To execute the interrupt handler, send the signal,sigint
, to the program:
(dbx)
cont -sig int
The
step
,next
, anddetach
commands accept-sig
as well.Automatically Handling Signals
The event management commands can also deal with signals as events. These two commands have the same effect.
(dbx)
stop sig signal
(dbx)
catch
signalHaving the signal event is more useful if you need to associate some pre-programmed action.
(dbx)
when sig SIGCLD {echo Got $sig $signame;}
In this case, make sure to first move
SIGCLD
to the ignore list.
(dbx)
ignore SIGCLD
Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback |
Library | Contents | Previous | Next | Index |