Debugging a Program With dbx |
Debugging at the
Machine-Instruction LevelThis chapter describes how to use event management and process control commands at the machine-instruction level, how to display the contents of memory at specified addresses, and how to display source lines along with their corresponding machine instructions. The
next
,step
,stop
andtrace
commands each support a machine-instruction level variant:nexti
,stepi
,stopi
, andtracei
. Use theregs
command to print out the contents of machine registers or theThis chapter is organized into the following sections:
- Examining the Contents of Memory
- Stepping and Tracing at Machine-Instruction Level
- Setting Breakpoints at the Machine-Instruction Level
- Using the adb Command
- Using the regs Command
Examining the Contents of Memory
Using addresses and the
examine
orx
command, you can examine the content of memory locations as well as print the assembly language instruction at each address. Using a command derived fromadb
(1), the assembly language debugger, you can query for:
- The address, using the
=
(equal sign) character, or,- The contents stored at an address, using the
/
(slash) character.You can print the assembly commands using the
dis
andlisti
commands. (See Using the dis Command and Using the listi Command.)Using the
examine
orx
CommandUse the
examine
command, or its aliasx
, to display memory contents or addresses.Use the following syntax to display the contents of memory starting at address for count items in format fmt. The default addr is the next one after the last address previously displayed. The default count is 1. The default fmt is the same as was used in the previous
examine
command, orX
if this is the first command given.The syntax for the
examine
command is:
examine [address] [/ [count] [format]]To display the contents of memory from address1 through address2 inclusive, in format fmt, type:
examine
address1,
address2[/ [
format]]
Display the address, instead of the contents of the address in the given format by typing:
examine
address= [
format]
To print the value stored at the next address after the one last displayed by
examine
, type:
examine +/ i
To print the value of an expression, enter the expression as an address:
examine
address=
formatexamine
address=
Addresses
The address is any expression resulting in or usable as an address. The address may be replaced with a + (plus sign), which displays the contents of the next address in the default format.
For example, the following are valid addresses.:
0xff99
An absolute address main
Address of a function main+20
Offset from a function address &errno
Address of a variable str
A pointer-value variable pointing to a string
Symbolic addresses used to display memory are specified by preceding a name with an ampersand (&). Function names can be used without the ampersand;
&main
is equal tomain
. Registers are denoted by preceding a name with a dollar sign ($).Formats
The format is the address display format in which
dbx
displays the results of a query. The output produced depends on the current display format. To change the display format, supply a different format code.The default format set at the start of each
dbx
session isX
, which displays an address or value as a 32-bit word in hexadecimal. The following memory display formats are legal.
Count
The count is a repetition count in decimal. The increment size depends on the memory display format.
Examples of Using an Address
The following examples show how to use an address with count and format options to display five successive disassembled instructions starting from the current stopping point.
For SPARC:
For Intel:
Using the
dis
CommandThe
dis
command is equivalent to theexamine
command withi
as the default display format.Here is the syntax for the
dis
command.
dis [
address] [
address1,
address2] [/
count]
- Without arguments displays 10 instructions starting at +.
- With the address argument only, disassembles 10 instructions starting at address.
- With the address1 and address2 arguments, disassembles instructions from address1 through address2.
- With only a count, displays count instructions starting at +.
Using the
listi
CommandTo display source lines with their corresponding assembly instructions, use the
listi
command, which is equivalent to the commandlist
-i
. See the discussion oflist
-i
in Printing a Source Listing.For SPARC:
For Intel:
Stepping and Tracing at Machine-Instruction Level
Machine-instruction level commands behave the same as their source level counterparts except that they operate at the level of single instructions instead of source lines.
Single Stepping at the Machine-Instruction Level
To single step from one machine instruction to the next machine instruction, use the
nexti
command or thestepi
commandThe
nexti
command and thestepi
command behave the same as their source-code level counterparts: thenexti
command steps over functions, thestepi
command steps into a function called by the next instruction (stopping at the first instruction in the called function). The command forms are also the same. See "next Command"
and "step Command" in the Using dbx Commands section of the Sun WorkShop online help for a description.The output from the
nexti
command and thestepi
command differs from the corresponding source level commands in two ways:
- The output includes the address of the instruction at which the program is stopped (instead of the source code line number).
- The default output contains the disassembled instruction instead of the source code line.
For example:
(dbx)
func
hand::ungrasp
(dbx)
nexti
ungrasp +0x18: call support
(dbx)
For more information, see "nexti Command" and "stepi Command" in the Using dbx Commands section of the Sun WorkShop online help.
Tracing at the Machine-Instruction Level
Tracing techniques at the machine-instruction level work the same as at the source code level, except you use the
tracei
command For thetracei
command,dbx
executes a single instruction only after each check of the address being executed or the value of the variable being traced. Thetracei
command produces automaticstepi
-like behavior: the program advances one instruction at a time, stepping into function calls.When you use the
tracei
command, it causes the program to stop for a moment after each instruction whiledbx
checks for the address execution or the value of the variable or expression being traced. Using thetracei
command can slow execution considerably.For more information on trace and its event specifications and modifiers, see Tracing Code and "trace Command" in the Using dbx Commands section of the Sun WorkShop online help.
Here is the general syntax for
tracei
:
tracei
event-specification [modifier]Commonly used forms of
tracei
are:
tracei step
Trace each instruction. tracei next
Trace each instruction, but skip over calls. tracei at
addressTrace the given code address.
For more information, see "tracei Command" in the Using dbx Commands section of the Sun WorkShop online help.
For SPARC:
Setting Breakpoints at the Machine-Instruction Level
To set a breakpoint at the machine-instruction level, use the
stopi
command. The command accepts any event specification, using the syntax:
stopi
event-specification[
modifier]
Commonly used forms of the
stopi
command are:
stopi [at
address] [-if
cond]
stopi in
function[-if
cond]
For more infomation, see "stopi Command" in the Using dbx Commands section of the Sun WorkShop online help.
Setting a Breakpoint at an Address
To set a breakpoint at a specific address, type:
(dbx)
stopi at
addressFor example:
(dbx)
nexti
stopped in hand::ungrasp at 0x12638
(dbx)
stopi at &hand::ungrasp
(3) stopi at &hand::ungrasp
(dbx)
Using the
adb
CommandThe
adb
command lets you enter commands in anadb
(1) syntax. You can also enteradb
mode which interprets every command asadb
syntax. Mostadb
commands are supported.For more information, see "adb Command" in the Using dbx Commands section of the Sun WorkShop online help.
Using the
regs
CommandThe
regs
command lets you print the value of all the registers.Here is the syntax for the
regs
command:
regs [-f][-F]
-f
includes floating point registers (single precision).-F
includes floating point registers (double precision). These are SPARC-only options.For more information, see "regs Command" in the Using dbx Commands section of the Sun WorkShop online help.
For SPARC:
Platform-Specific Registers
The following tables list platform-specific register names for SPARC and Intel that can be used in expressions.
SPARC Register Information
The following register information is for SPARC systems.
The
$f0f1
$f2f3
...$f30f31
pairs of floating-point registers are treated as having C "double" type (normally$fN
registers are treated as C "float" type). These pairs can also be referred to as$d0
...$d30
.The following additional registers are available on SPARC V9 and V8+ hardware:
$g0g1 through $g6g7$o0o1 through $o6o7$xfsr $tstate $gsr$f32f33 $f34f35 through $f62f63 ($d32 ... $$d62)See the SPARC Architecture Reference Manual and the Sun-4 Assembly Language Reference Manual for more information on SPARC registers and addressing.
Intel Register Information
The following register information is for Intel systems.
Commonly used registers are also aliased to their machine independent names.
$sp
Stack pointer; equivalent of $uesp
$pc
Program counter; equivalent of $eip
$fp
Frame pointer; equivalent of $ebp
Registers for the 80386 lower halves (16 bits) are:
The first four 80386 16-bit registers can be split into 8-bit parts:
Registers for the 80387 are:
Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback |
Library | Contents | Previous | Next | Index |