How to Use the dbx Debugger

First of all, you must be using cc on dunx or queen. Also, your program must compile (that is, when you give the command "cc my_program.c", the next thing you see should be a command prompt, with no warnings or errors.)

Now give the command:

cc -g my_program.c
This prepares your compiled program for the debugger.

Now give the command:

dbx a.out
You are now in the dbx debugger! You will probably see some info about the debugger, followed by lines like

"Reading symbolic information for (a.out, etc.)"
followed by the dbx prompt:
(dbx)
To set a breakpoint, for instance in a function that you're concerned about, type:
stop in my_function
If you know the line number (for instance, 37) of the code you need to look at, type:
stop at 37
To learn more about setting breakpoints, type:
help stop
You don't always need breakpoints: for instance, if your program was giving you a segmentation violation, you can run the program in the debugger, and it will tell you exactly what line of code caused the segmentation violation. Then you'll know what you need to work on.

Okay, now you can run your program. Type:

run
If you've set breakpoints, the program will stop at them. To move through your program line by line, type:
step
To see what is contained in a variable, type:
print variable_name
NOTE: the debugger needs to step one line past an assignment statement to reflect the new contents of the variable. If the contents of your variable don't make sense, try stepping over one more line of your code and printing the variable again.

If you're sick and tired of stepping through your code, type:

cont
and the program will continue running.

When you're done with the debugger, type:

quit
This should be enough to get you started. You can use the help command to learn more about various dbx features, or e-mail me with questions. A feature I've heard is useful is "display", although I haven't tried it myself.

Beth Randall's Tips for Students
Beth Randall's Home Page