How to get started using the DBX DEBUGGER
Dbx can be a very helpful debugger, and it works on C, Fortran, and Pascal
code. In order to use dbx, you must compile your code with the "-g" flag.
This flag causes the compiler to produce symbol table information that dbx
needs. (Type "man cc", "man f77", or "man pc" for details.)
If your program is exiting in the middle with an error such as a "segmentation
violation" or "floating exception", then you may want to enable a core dump.
Usually, those two messages above would also have "(core dumped)" by them,
indicating that the program wrote an image of its current memory into a file
called "core" in that directory. Athena turned this off by default, since for
most people "core" is just a waste of disk space.
To allow core dumps and still not have quota worries, you can make a symbolic
link from the name core into the /tmp directory. Core dumps created this way
will not take up quota, and they will automatically vanish when you log out.
The dump will also occur more quickly since it doesn't have to go over the
network to your directory. To set up a core link in a directory:
athena% ln -s /tmp/core.project ./core
athena% unlimit coredumpsize
/tmp/core.project in the first line is the name that the file is really
called. You can change the name to something else if you want to work with
more than one directory at a time.
Here are some useful commands to get you started with dbx. Full details are
available by typing
athena% man dbx
To start it up, you'd type a form of the dbx command (on the Sun Sparc
workstations, you should type "add sunsoft" prior to using "dbx"!)
- To run dbx on the core file that is in your directory:
athena% dbx
- To run dbx on a program that does not have a core file:
athena% dbx programname
Once you are in dbx, there are various options.
- To get a stack trace of the functions that are open at this point:
(dbx) where
For example:
(dbx) where
read.read(0x0, 0x4000, 0x2000) at 0x3a8
_filbuf(0x1958) at 0x353
fgets.fgets(0x7fffe1e4, 0x4f, 0x1958) at 0x209
readResponse(), line 53 in "housing.c"
chooseSide(), line 66 in "housing.c"
main(0x1, 0x7fffe294, 0x7fffe29c), line 11 in "housing.c"
In this example, my function main() called chooseSide(), which called
readResponse(), and my program stopped in readResponse line 53.
Usually you'll see other functions called after yours, functions that you
didn't write yourself. These are normally system or library function calls,
and you shouldn't worry about them. Understanding them can be useful, since
they help to verify where the crash actually occured, and the arguments to
these functions are usually related to the cause of the crash. (In the
above example, these functions are fgets.fgets() _filbuf(), and read.read().)
- To print out the value of the variable you specify:
(dbx) print variablename
If you have variables in two different functions with the same name, you can
specify the one in the function you want with the syntax:
(dbx) print functionname.variablename
- One useful thing you can do is change the value of a variable in the middle
of your program's execution. You can, for example, stop at a particular
function, and then set the value of one of its arguments. For example:
(dbx) stop at BigFunction
[2] stop in BigFunction
(dbx) print k
7
(dbx) assign j=k+3
The above sequence of commands will stop your program at the entry to the
function Big Function(), show you the value of the variable k, and then
assign the value 10 (7+3) to the variable j. After having done this, you
might choose the (dbx) continue command to continue running your program
(with the value of whatever variables you have assigned set as you wish) or
the (dbx) next command, which will just execute the next line of your source
code, and then stop the program again, so that you can inspect more values.
There are a number of other useful commands in dbx. You'll see them in the
manual page. Also, note that some of the major problems with dbx are listed
at the very end of the manual page.
last updated: 10/13/95
|