Debugging at the Machine- Instruction Level |
14 |
![]() |
This chapter is organized into the following sections:
Examining the Contents of Memory
Using addresses and the examine or x command, you can examine the content of memory locations as well as print the assembly language instruction at each address. Using a command derived from adb(1), the assembly language debugger, you can query for:
Use the following syntax to display the contents of memory starting at addr 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, or X if this is the first command given.
The syntax for the examine command is:
examine [addr] [/ [count] [fmt]] |
To display the contents of memory from addr1 through addr2 inclusive, in format fmt:
examine addr1, addr2 [/ [fmt]] |
Display the address, instead of the contents of the address in the given format:
examine addr = [fmt] |
To print the value stored at the next address after the one last displayed by examine:
examine +/ i |
To print the value of an expression, enter the address as an expression:
examine addr=format examine addr= |
Addresses
The addr is any expression resulting in or usable as an address. The addr may be replaced with a + (plus sign) which displays the contents of the next address in the default format.
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 to main. Registers are denoted by preceding a name with a dollar sign($).
Formats
The fmt is the address display format in which dbx displays the results of a query. The output produced depends on the current display fmt. To change the display format, supply a different fmt code.
Count
The count is a repetition count in decimal. The increment size depends on the memory display format. Examples
The following examples show how to use an address with count and fmt options to display five successive disassembled instructions starting from the current stopping point.
Using the dis Command
The dis command is equivalent to the examine command with i as the default display format.
dis addr /[count] |
The dis command without arguments displays 10 instructions starting at the address +. With only a count, the dis command displays count instructions starting at the address +.
Using the listi Command
To display source lines along with their corresponding assembly instructions, use listi, which is equivalent to list -i
. See the discussion of list -i
in Chapter 3, "Viewing and Visiting Code".
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 the Machine-Instruction Level
To single-step from one machine-instruction to the next machine-instruction:
![]() | Use nexti or stepi |
The output from nexti and stepi differs from the corresponding source level commands in two ways. First, the output includes the address of the instruction at which the program is stopped (instead of the source code line number); secondly, the default output contains the disassembled instruction.
For example:
(dbx) func hand::ungrasp (dbx) nexti ungrasp +0x18: call support (dbx) |
Tracing at the Machine-Instruction Level
Tracing techniques at the machine instruction level work the same as at the source code level, except when you use tracei. For tracei, dbx executes a single instruction only after each check of the address being executed or the value of the variable being traced. tracei produces automatic stepi-like behavior: the program advances one instruction at a time, stepping into function calls.
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 address |
Trace the given code address |
Setting Breakpoints at Machine-Instruction Level
To set a breakpoint at machine-instruction level, use stopi. The command stopi 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] |
Setting a Breakpoint at an Address
To set a breakpoint at a specific address:
(dbx) stopi at address |
(dbx) nexti stopped in hand::ungrasp at 0x12638 (dbx) stopi at &hand::ungrasp (3) stopi at &hand::ungrasp (dbx) |
Using the adb Command
The adb command allows you to enter commands in an adb(1) syntax. You may also enter adb mode which interprets every command as adb syntax. Most adb commands are supported.
Using the regs Command
The regs command lets you print the value of all the registers.
regs [ |
-f
includes floating point registers (single precision). -F
includes floating point registers (double precision); this is a SPARC only option.
Platform-specific Registers
The following tables list platform-specific register names for SPARC, Intel and PowerPC that can be used in expressions. SPARC Register Information
The following register information is for SPARC systems.
$xg0 $xg1 through $xg7 $xo0 $xo1 through $xo7 $xfsr $tstate $gsr $f32f33 $f34f35 through $f62f63 |
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.
$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:
PowerPC Register Information
The following register information is for PowerPC systems.