DBX Debugger
( Under IRIX 6.5, DBX is no longer a working debugger. It does not allow user to look into a class, e.g. one could not examine the value of a data member of a class. )
dbx is a utility for source-level debugging and execution of programs
written in C, C++, and FORTRAN. dbx allows you to trace the execution
of a specified object file. You can step through a program on a line-by-line
basis while you examine the state of the execution environment.
Programs compiled with the -g option of
cc
( and other compilers ) produce an object file. This object file contains
symbol table information, including the names of all source files that the
compiler translated to create the object file.
dbx also allows you to examine core files via its
where command. A core file contains the core image produced when
the object file was executed, providing information about the state of
the program and the system when the failure occurred. A core file
named core is produced by default.
dbx commands can be stored in a start up
.dbxinit file
that resides in the current directory or in your home directory.
dbx executes these commands just before reading the symbol table.
Running dbx
To invoke dbx, enter the following command:
% dbx [options] [object_file [corefile]]
where object_file is the name of the file you want to debug.
Once dbx is running, you should see the (dbx)
prompt.
At this point you can start issuing dbx commands.
Commands
There are many dbx commands, all described in the man pages.
Some of the basic commands are run,
where,
print,
stop,
list,
cont,
and quit:
- run [arguments]
- Begin executing the object
file, passing optional command-line arguments. The arguments
can include input or output redirection to a named file.
- where [n]
-
List all active functions on the stack, or only the top n.
- print [expressions]
- Print
the values of one or more comma-separated expressions.
To print values of two-dimensional FORTRAN array elements use the format:
print array_name[1,2]
- stop restriction [if cond]
-
Stop execution if specified restriction is true.
Restrictions include (this is a partial list):
-
- at (source line)
n
-
- if cond
-
- in (procedure or function)
func
-
- cond (condition) is a Boolean expression; if it
evaluates to true, then execution is stopped.
- list [n1 [,n2]] or
list func
-
- List the source text between lines n1 and
n2, or on lines surrounding the first statement of func.
With no arguments, list the next ten lines.
- cont [at n] [sig signal]
-
Continue execution
from the point at which it was stopped if no arguments. Resume from source
line n or, if a signal name or number is specified,
resume process as if it had received the signal.
- status [> file]
- Show active
trace, stop, and
when commands
- delete [n]
- Remove traces,
stops, and whens
corresponding to each command number n, given by
status
. If n is all remove all.
- quit
- Exit dbx.
Example
You may want to start by using dbx to set some break points within
your code. To step through your code at the very beginning, you need to
stop in the MAIN routine if you are debugging
an object file
created from FORTRAN source code (stop in
main if your source
is in C language). For example, you would type:
(dbx) stop in MAIN
Now you can issue the run command to
start execution of your
object file. You will get the process id and the name of the object file
being executed.
(dbx) run
At this point, you may use the list command
for the first 10-line listing of the source code:
(dbx) list
Use the stop command to set break-points at
various lines or procedures within the object-file:
(dbx) stop at 10
(dbx) stop in sub123
(dbx) stop in sub456 if i == 24
The execution will stop in the example above at line 10, or in subroutine
sub123, or in subroutine
sub456 when i
is equal to 24. To continue execution
at any point
in your debugging, issue the cont command:
(dbx) cont
To restart your debugging session, issue the rerun
command:
(dbx) rerun
To exit dbx, type quit:
(dbx) quit
The original page was created by Dong Zhao.
Now is maintained by Qizhong Li
Last modified: Thu May 6 15:21:29 CDT 1999