[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
General Programming Concepts: Writing and Debugging Programs

Debugging at the Machine Level with dbx

You can use the dbx debug program to examine programs at the assembly language level. You can display and modify memory addresses, display assembler instructions, single-step instructions, set breakpoints and trace events at memory addresses, and display the registers.

In the commands and examples that follow, an address is an expression that evaluates to a memory address. The most common forms of addresses are integers and expressions that take the address of an identifier with the & (ampersand) operator. You can also specify an address as an expression enclosed in parentheses in machine-level commands. Addresses can be composed of other addresses and the operators + (plus), - (minus), and indirection (unary *).

The following sections contain more information on debugging at the machine level with the dbx program.

Using Machine Registers

Use the registers subcommand to see the values of the machine registers. Registers are divided into three groups: general-purpose, floating-point, and system-control.

General-purpose registers:

General-purpose registers are denoted by $rNumber, where Number represents the number of the register.

Note: The register value may be set to a hexadecimal value of 0xdeadbeef. This is an initialization value assigned to all general-purpose registers at process initialization.

Floating-point registers:

Floating-point registers are denoted by $frNumber, where Number represents the number of the register. Floating-point registers are not displayed by default. Unset the $noflregs debug program variable to enable the floating-point register display (unset $noflregs).

System-control registers:

Supported system-control registers are denoted by:

Examining Memory Addresses

Use the following command format to print the contents of memory starting at the first address and continuing up to the second address, or until the number of items specified by the Count variable are displayed. The Mode specifies how memory is to print.

Address, Address / [Mode][> File]
Address / [Count][Mode] [> File]

If the Mode variable is omitted, the previous mode specified is reused. The initial mode is X. The following modes are supported:

b Prints a byte in octal.
c Prints a byte as a character.
D Prints a long word in decimal.
d Prints a short word in decimal.
f Prints a single-precision floating-point number.
g Prints a double-precision floating-point number.
h Prints a byte in hexadecimal.
i Prints the machine instruction.
lld Prints an 8-byte signed decimal number.
llo Prints an 8-byte unsigned octal number.
llu Prints an 8-byte unsigned decimal number.
llx Prints an 8-byte unsigned hexadecimal number.
O Prints a long word in octal.
o Prints a short word in octal.
q Prints an extended-precision floating-point number.
s Prints a string of characters terminated by a null byte.
X Prints a long word in hexadecimal.
x Prints a short word in hexadecimal.

In the following example, expressions in parentheses can be used as an address:

(dbx) print &x
0x3fffe460
(dbx) &x/X
3fffe460: 31323300
(dbx) &x,&x+12/x
3fffe460: 3132 3300 7879 7a5a 5958 5756 003d 0032
(dbx) ($pc)/2i
100002cc (sub)  7c0802a6        mflr     r0
100002d0 (sub + 0x4)    bfc1fff8         stm       r30,-8(r1)

Running a Program at the Machine Level

The commands for debugging your program at the machine-level are similar to those at the symbolic level. The stopi subcommand stops the machine when the address is reached, the condition is true, or the variable is changed. The tracei subcommands are similar to the symbolic trace commands. The stepi subcommand executes either one or the specified Number of machine instructions.

If you performed another stepi subcommand at this point, you would stop at address 0x10000618, identified as the entry point of procedure printf. If you do not intend to stop at this address, you could use the return subcommand to continue execution at the next instruction in sub at address 0x100002e0. At this point, the nexti subcommand will automatically continue execution to 0x10000428.

If your program has multiple threads, the symbolic thread name of the running thread is displayed when the program stops. For example:

stopped in sub at 0x100002d4 ($t4)
10000424 (sub+0x4) 480001f5 bl 0x10000618 (printf)

Debugging fdpr Reordered Executables

You can debug programs that have been reordered with fdpr (feedback directed program restructuring, part of Performance Toolbox for AIX) at the instruction level. If optimization options -R0 or -R2 are used, additional information is provided enabling dbx to map most reordered instruction addresses to the corresponding addresses in the original executable as follows:

0xRRRRRRRR = fdpr[0xYYYYYYYY]

In this example, 0xRRRRRRRR is the reordered address and 0xYYYYYYYY is the original address. In addition, dbx uses the traceback entries in the original instruction area to find associated procedure names for the stopped in message, the func subcommand, and the traceback.

(dbx) stepi
stopped in proc_d at 0x1000061c = fdpr[0x10000278]
0x1000061c (???) 9421ffc0       stwu   r1,-64(r1)
(dbx)

In the preceding example, dbx indicates the program is stopped in the proc_d subroutine at address 0x1000061c in the reordered text section originally located at address 0x10000278. For more information about fdpr, see the fdpr command.

Displaying Assembly Instructions

The listi subcommand for the dbx command displays a specified set of instructions from the source file. In the default mode, the dbx program lists the instructions for the architecture on which it is running. You can override the default mode with the $instructionset and $mnemonics variables of the set subcommand for the dbx command.

For more information on displaying instructions or disassembling instructions, see the listi subcommand for the dbx command. For more information on overriding the default mode, see the $instructionset and $mnemonics variables of the set subcommand for the dbx command.

Related Information

dbx Symbolic Debug Program Overview

Using the dbx Debug Program

Displaying and Manipulating the Source File with the dbx debug Program

Examining Program Data

Customizing the dbx Debugging Environment


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]