[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

General Programming Concepts: Writing and Debugging Programs


adb Debug Program Reference Information

The adb debug program uses addresses, expressions, operators, subcommands, and variables to organize and manipulate data.

adb Debug Program Addresses

The address in a file associated with a written address is determined by a mapping associated with that file. Each mapping is represented by two triples (B1, E1, F1) and (B2, E2, F2). The FileAddress parameter that corresponds to a written Address parameter is calculated as follows:

B1<=Address<E1=>FileAddress=Address+F1-B1

OR

B2<=Address<E2=>FileAddress=Address+F2-B2

If the requested Address parameter is neither between B1 and E1 nor between B2 and E2, the Address parameter is not valid. In some cases, such as programs with separated I and D space, the two segments for a file may overlap. If a ? (question mark) or / (slash) subcommand is followed by an * (asterisk), only the second triple is used.

The initial setting of both mappings is suitable for normal a.out and core files. If either file is not of the kind expected, the B1 parameter for that file is set to a value of 0, the E1 parameter is set to the maximum file size, and the F1 parameter is set to a value of 0. In this way, the whole file can be examined with no address translation.

adb Debug Program Expressions

The following expressions are supported by the adb debug program:

. (period) Specifies the last address used by a subcommand. The last address is also known as the current address.
+ (plus) Increases the value of . (period) by the current increment.
^ (caret) Decreases the value of . (period) by the current increment.
" (double quotes) Specifies the last address typed by a command.
Integer Specifies an octal number if this parameter begins with 0o, a hexadecimal number if preceded by 0x or #, or a decimal number if preceded by 0t. Otherwise, this expression specifies a number interpreted in the current radix. Initially, the radix is 16.
`Cccc' Specifies the ASCII value of up to 4 characters. A \ (backslash) can be used to escape an ' (apostrophe).
< Name Reads the current value of the Name parameter. The Name parameter is either a variable name or a register name. The adb command maintains a number of variables named by single letters or digits. If the Name parameter is a register name, the value of the register is obtained from the system header in the CoreFile parameter. Use the $r subcommand to see the valid register names.
Symbol Specifies a sequence of uppercase or lowercase letters, underscores, or digits, though the sequence cannot start with a digit. The value of the Symbol parameter is taken from the symbol table in the ObjectFile parameter. An initial _ (underscore) is prefixed to the Symbol parameter, if needed.
.Symbol Specifies the entry point of the function named by the Symbol parameter.
Routine.Name Specifies the address of the Name parameter in the specified C language routine. Both the Routine and Name parameters are Symbol parameters. If the Name parameter is omitted, the value is the address of the most recently activated C stack frame corresponding to the Routine parameter.
(Expression) Specifies the value of the expression.

adb Debug Program Operators

Integers, symbols, variables, and register names can be combined with the following operators:

Unary Operators
*Expression Returns contents of the location addressed by the Expression parameter in the CoreFile parameter.
@Expression Returns contents of the location addressed by the Expression parameter in the ObjectFile parameter.
-Expression Performs integer negation.
~Expression Performs bit-wise complement.
#Expression Performs logical negation.

Binary Operators
Expression1+Expression2 Performs integer addition.
Expression1-Expression2 Performs integer subtraction.
Expression1*Expression2 Performs integer multiplication.
Expression1%Expression2 Performs integer division.
Expression1&Expression2 Performs bit-wise conjunction.
Expression1|Expression2 Performs bit-wise disjunction.
Expression1#Expression2 Rounds up the Expression1 parameter to the next multiple of the Expression2 parameter.

Binary operators are left-associative and are less binding than unary operators.

adb Debug Program Subcommands

You can display the contents of a text or data segment with the ? (question mark) or the / (slash) subcommand. The = (equal sign) subcommand displays a given address in the specified format. The ? and / subcommands can be followed by an * (asterisk).

?Format Displays the contents of the ObjectFile parameter starting at the Address parameter. The value of . (period) increases by the sum of the increment for each format letter.
/Format Displays the contents of the CoreFile parameter starting at the Address parameter. The value of . (period) increases by the sum of the increment for each format letter.
=Format Displays the value of the Address parameter. The i and s format letters are not meaningful for this command.

The Format parameter consists of one or more characters that specify print style. Each format character may be preceded by a decimal integer that is a repeat count for the format character. While stepping through a format, the . (period) increments by the amount given for each format letter. If no format is given, the last format is used.

The available format letters are as follows:

a Prints the value of . (period) in symbolic form. Symbols are checked to ensure that they have an appropriate type.
b Prints the addressed byte in the current radix, unsigned.
c Prints the addressed character.
C Prints the addressed character using the following escape conventions:
  • Prints control characters as ~ (tilde) followed by the corresponding printing character.
  • Prints nonprintable characters as ~ (tilde) <Number>, where Number specifies the hexadecimal value of the character. The ~ character prints as ~ ~ (tilde tilde).
d Prints in decimal.
D Prints long decimal.
f Prints the 32-bit value as a floating-point number.
F Prints double floating point.
i Number Prints as instructions. Number is the number of bytes occupied by the instruction.
n Prints a new line.
o Prints 2 bytes in octal.
O Prints 4 bytes in octal.
p Prints the addressed value in symbolic form using the same rules for symbol lookup as the a format letter.
q Prints 2 bytes in the current radix, unsigned.
Q Prints 4 unsigned bytes in the current radix.
r Prints a space.
s Number Prints the addressed character until a zero character is reached.
S Number Prints a string using the ~ (tilde) escape convention. The Number variable specifies the length of the string including its zero terminator.
t Tabs to the next appropriate tab stop when preceded by an integer. For example, the 8t format command moves to the next 8-space tab stop.
u Prints as an unsigned decimal number.
U Prints a long unsigned decimal.
x Prints 2 bytes in hexadecimal.
X Prints 4 bytes in hexadecimal.
Y Prints 4 bytes in date format.
/ Local or global data symbol.
? Local or global text symbol.
= Local or global absolute symbol.
"..." Prints the enclosed string.
^ Decreases the . (period) by the current increment. Nothing prints.
+ Increases the . (period) by a value of 1. Nothing prints.
- Decreases the . (period) decrements by a value of 1. Nothing prints.
newline Repeats the previous command incremented with a Count of 1.
[?/]lValue Mask    Words starting at the . (period) are masked with the Mask value and compared with the Value parameter until a match is found. If L is used, the match is for 4 bytes at a time instead of 2 bytes. If no match is found, then . (period) is unchanged; otherwise, . (period) is set to the matched location. If the Mask parameter is omitted, a value of -1 is used.
[?/]wValue... Writes the 2-byte Value parameter into the addressed location. If the command is W, write 4 bytes. If the command is V, write 1 byte. Alignment restrictions may apply when using the w or W command.
[,Count][?/]m B1 E1 F1[?/] Records new values for the B1, E1, and F1 parameters. If less than three expressions are given, the remaining map parameters are left unchanged. If the ? (question mark) or / (slash) is followed by an * (asterisk), the second segment (B2, E2, F2) of the mapping is changed. If the list is terminated by ? or /, the file (ObjectFile or CoreFile, respectively) is used for subsequent requests. (For example, the /m? command causes / to refer to the ObjectFile) file. If the Count parameter is specified, the adb command changes the maps associated with that file or library only. The $m command shows the count that corresponds to a particular file. If the Count parameter is not specified, a default value of 0 is used.
>Name Assigns a . (period) to the variable or register specified by the Name parameter.
! Calls a shell to read the line following ! (exclamation mark).
$Modifier Miscellaneous commands. The available values for Modifier are:

<File
Reads commands from the specified file and returns to standard input. If a count is given as 0, the command will be ignored. The value of the count is placed in the adb 9 variable before the first command in the File parameter is executed.

<<File
Reads commands from the specified file and returns to standard input. The <<File command can be used in a file without causing the file to be closed. If a count is given as 0, the command is ignored. The value of the count is placed in the adb 9 variable before the first command in File is executed. The adb 9 variable is saved during the execution of the <<File command and restored when <<File completes. There is a limit to the number of <<File commands that can be open at once.

>File
Sends output to the specified file. If the File parameter is omitted, output returns to standard output. The File parameter is created if it does not exist.

b
Prints all breakpoints and their associated counts and commands.

c
Stacks back trace. If the Address parameter is given, it is taken as the address of the current frame (instead of using the frame pointer register). If the format letter C is used, the names and values of all automatic and static variables are printed for each active function. If the Count parameter is given, only the number of frames specified by the Count parameter are printed.

d
Sets the current radix to the Address value or a value of 16 if no address is specified.

e
Prints the names and values of external variables. If a count is specified, only the external variables associated with that file are printed.

f
Prints the floating-point registers in hexadecimal.

i instruction set
Selects the instruction set to be used for disassembly.

I
Changes the default directory as specified by the -I flag to the Name parameter value.

m
Prints the address map.

n mnem_set
Selects the mnemonics to be used for disassembly.

o
Sets the current radix to a value of 8.

q
Exits the adb command.

r
Prints the general registers and the instruction addressed by iar and sets the . (period) to iar. The Number$r parameter prints the register specified by the Number variable. The Number,Count$r parameter prints registers Number+Count-1,...,Number.

s
Sets the limit for symbol matches to the Address value. The default is a value of 255.

v
Prints all non-zero variables in octal.

w
Sets the output page width for the Address parameter. The default is 80.

P Name
Uses the Name value as a prompt string.

?
Prints the process ID, the signal that caused stoppage or termination, and the registers of $r.
:Modifier Manages a subprocess. Available modifiers are:

bCommand
Sets the breakpoint at the Address parameter. The breakpoint runs the Count parameter -1 times before causing a stop. Each time the breakpoint is encountered, the specified command runs. If this command sets . (period) to a value of 0, the breakpoint causes a stop.

cSignal
Continues the subprocess with the specified signal. If the Address parameter is given, the subprocess is continued at this address. If no signal is specified, the signal that caused the subprocess to stop is sent. Breakpoint skipping is the same as for the r modifier.

d
Deletes the breakpoint at the Address parameter.

k
Stops the current subprocess, if one is running.

r
Runs the ObjectFile parameter as a subprocess. If the Address parameter is given explicitly, the program is entered at this point. Otherwise, the program is entered at its standard entry point. The Count parameter specifies how many breakpoints are to be ignored before stopping. Arguments to the subprocess can be supplied on the same line as the command. An argument starting with < or > establishes standard input or output for the command. On entry to the subprocess, all signals are turned on.

sSignal
Continues the subprocess in single steps up to the number specified in the Count parameter. If there is no current subprocess, the ObjectFile parameter is run as a subprocess. In this case no signal can be sent. The remainder of the line is treated as arguments to the subprocess.

adb Debug Program Variables

The adb command provides a number of variables. When the adb program is started, the following variables are set from the system header in the specified core file. If the CoreFile parameter does not appear to be a core file, these values are set from the ObjectFile parameter:

0 Last value printed
1 Last displacement part of an instruction source
2 Previous value of the 1 variable
9 Count on the last $< or $<< subcommand
b Base address of the data segment
d Size of the data segment
e Entry address of the program
m "Magic" number
s Size of the stack segment
t Size of the text segment

Related Information

The adb command

adb Debug Program Overview

Using adb Expressions

Displaying and Manipulating the Source File with the adb Program

adb Debug Program Expressions

adb Debug Program Operators

adb Debug Program Subcommands

adb Debug Program Variables


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]