| 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,stopandtracecommands each support a machine-instruction level variant:nexti,stepi,stopi, andtracei. Use theregscommand 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
examineorxcommand, 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
disandlisticommands. (See Using the dis Command and Using the listi Command.)Using the
examineorxCommandUse the
examinecommand, 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
examinecommand, orXif this is the first command given.The syntax for the
examinecommand is:
examine [address] [/ [count] [format]]To display the contents of memory from address1 through address2 inclusive, in format fmt, type:
examineaddress1,address2[/ [format]]Display the address, instead of the contents of the address in the given format by typing:
examineaddress= [format]To print the value stored at the next address after the one last displayed by
examine, type:
examine +/ iTo print the value of an expression, enter the expression as an address:
examineaddress=formatexamineaddress=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.:
0xff99An absolute address mainAddress of a function main+20Offset from a function address &errnoAddress of a variable strA 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;
&mainis equal tomain. Registers are denoted by preceding a name with a dollar sign ($).Formats
The format is the address display format in which
dbxdisplays 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
dbxsession 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
disCommandThe
discommand is equivalent to theexaminecommand withias the default display format.Here is the syntax for the
discommand.
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
listiCommandTo display source lines with their corresponding assembly instructions, use the
listicommand, which is equivalent to the commandlist-i. See the discussion oflist-iin 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
nexticommand or thestepicommandThe
nexticommand and thestepicommand behave the same as their source-code level counterparts: thenexticommand steps over functions, thestepicommand 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
nexticommand and thestepicommand 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)funchand::ungrasp(dbx)nextiungrasp +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
traceicommand For thetraceicommand,dbxexecutes a single instruction only after each check of the address being executed or the value of the variable being traced. Thetraceicommand produces automaticstepi-like behavior: the program advances one instruction at a time, stepping into function calls.When you use the
traceicommand, it causes the program to stop for a moment after each instruction whiledbxchecks for the address execution or the value of the variable or expression being traced. Using thetraceicommand 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:
traceievent-specification [modifier]Commonly used forms of
traceiare:
tracei stepTrace each instruction. tracei nextTrace each instruction, but skip over calls. tracei ataddressTrace 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
stopicommand. The command accepts any event specification, using the syntax:
stopievent-specification[modifier]Commonly used forms of the
stopicommand are:
stopi [ataddress] [-ifcond]stopi infunction[-ifcond]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 ataddressFor example:
(dbx)nextistopped in hand::ungrasp at 0x12638(dbx)stopi at &hand::ungrasp(3) stopi at &hand::ungrasp(dbx)Using the
adbCommandThe
adbcommand lets you enter commands in anadb(1) syntax. You can also enteradbmode which interprets every command asadbsyntax. Mostadbcommands are supported.For more information, see "adb Command" in the Using dbx Commands section of the Sun WorkShop online help.
Using the
regsCommandThe
regscommand lets you print the value of all the registers.Here is the syntax for the
regscommand:
regs [-f][-F]
-fincludes floating point registers (single precision).-Fincludes 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...$f30f31pairs of floating-point registers are treated as having C "double" type (normally$fNregisters 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.
$spStack pointer; equivalent of $uesp$pcProgram counter; equivalent of $eip$fpFrame 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 |