ADB(1) — USER COMMANDS
NAME
adb − debugger
SYNOPSIS
adb [ −w ] [ −k ] [ −Idir ] [ objfil [ corfil ] ]
DESCRIPTION
Adb is an interactive, general purpose debugger. It examines files and provides a controlled environment for the execution of UNIX programs.
Objfil is normally an executable program file, preferably containing a symbol table. If the file does not contain a symbol table, it can still be examined, but the symbolic features of adb cannot be used. The default for objfil is a.out. Corfil is assumed to be a core image file produced after executing objfil. The default for corfil is core.
OPTIONS
−w Create both objfil and corfil if necessary and open them for reading and writing so that files can be modified using adb.
−k Do UNIX kernel memory mapping; should be used when core is a UNIX crash dump or /dev/mem.
−I specifies a directory where files to be read with $< or $<< (see below) will be sought; the default is /usr/lib/adb.
USING ADB
Adb reads commands from the standard input and displays responses on the standard output. Adb ignores QUIT; INTERRUPT causes return to the next adb command.
Adb saves and restores terminal characteristics when running a sub−process. This makes it possible to debug programs that manipulate the screen. See tty(4).
In general, requests to adb are of the form
[address] [, count] [command] [;]
The symbol dot (.) represents the current location. It is initially zero. If address is present then dot is set to address. For most commands count specifies how many times the command will be executed. The default count is 1. Address and count are expressions.
EXPRESSIONS
. The value of dot.
+ The value of dot incremented by the current increment.
^ The value of dot decremented by the current increment.
& The last address typed. (Used to be “"”.)
integer A number. The prefixes 0o and 0O (“zero oh”) force interpretation in octal radix; the prefixes 0t and 0T force interpretation in decimal radix; the prefixes 0x and 0X force interpretation in hexadecimal radix. Thus 0o20 = 0t16 = 0x10 = sixteen. If no prefix appears, then the default radix is used; see the $d command. The default radix is initially hexadecimal. The hexadecimal digits are 0123456789abcdefABCDEF with the obvious values. Note that if a hexadecimal number starts with a letter, but does not duplicate a defined symbol, it is accepted as a hexadecimal value. To enter a hexadecimal number that is the same as a defined symbol, preceed it by 0, 0x, or 0X.
integer.fraction
A 32 bit floating point number.
´cccc´ The ASCII value of up to 4 characters. A backslash (‘\’) may be used to escape a ´.
< name The value of name, which is either a variable name or a register name. Adb maintains a number of variables (see VARIABLES) named by single letters or digits. If name is a register name then the value of the register is obtained from the system header in corfil. The register names are those printed by the $r command.
symbol A symbol is a sequence of upper or lower case letters, underscores or digits, not starting with a digit. The backslash character \ may be used to escape other characters. The value of the symbol is taken from the symbol table in objfil. An initial _ will be prepended to symbol if needed.
_ symbol
In C, the ‘true name’ of an external symbol begins with ‘_’. It may be necessary to use this name to distinguish it from internal or hidden variables of a program.
routine.name
The address of the variable name in the specified C routine. Both routine and name are symbols. If name is omitted the value is the address of the most recently activated C stack frame corresponding to routine.
(exp) The value of the expression exp.
Unary operators
∗exp The contents of the location addressed by exp in corfil.
%exp The contents of the location addressed by exp in objfil. (Used to be @.)
−exp Integer negation.
~exp Bitwise complement.
#exp Logical negation.
^Fexp (Control−f) Translates program addresses into sourcefile addresses. (Works only if the program has been compiled using the −go flag. See cc(1).)
^Aexp (Control−a) Translates sourcefile addresses into program addresses. (Works only if the program has been compiled using the −go flag. See cc(1).)
`name (Back−quote) Translates a procedure name into a sourcefile address. (Works only if the program has been compiled using the −go flag. See cc(1).)
"filename"
A filename enclosed in quotation marks (for instance, "main.c") produces the sourcefile address for the zero-th line of that file. Thus to reference the third line of the file main.c, we say: "main.c"+3. (Works only if the program has been compiled using the −go flag. See cc(1).)
Binary operators are left associative and are less binding than unary operators.
e1+e2 Integer addition.
e1−e2 Integer subtraction.
e1∗e2 Integer multiplication.
e1%e2 Integer division.
e1&e2 Bitwise conjunction.
e1│e2 Bitwise disjunction.
e1#e2 E1 rounded up to the next multiple of e2.
VARIABLES
Adb provides a number of variables. Named variables are set initially by adb but are not used subsequently. Numbered variables are reserved for communication as follows.
0 The last value printed.
1 The last offset part of an instruction source.
2 The previous value of variable 1.
9 The count on the last $< or $<< command.
On entry the following are set from the system header in the corfil. If corfil does not appear to be a core file then these values are set from objfil.
b The base address of the data segment.
d The data segment size.
e The entry point.
m The ‘magic’ number (0407, 0410 or 0413).
s The stack segment size.
t The text segment size.
COMMANDS
Adb commands consist of a verb followed by a modifier or list of modifiers.
The verbs are:
? Print locations starting at address in objfil.
/ Print locations starting at address in corfil.
= Print the value of address itself.
@ Interpret address as a sourcefile address, and print locations in objfile or lines of the source text. (Works only if the program has been compiled using the −go flag. See cc(1).)
: Manage a subprocess.
$ Execute miscellaneous commands.
> Assign a value to a variable or register.
RETURN Repeat the previous command with a count of 1. Dot is incremented by its current increment.
! Call the shell to execute the following command.
Each verb has a specific set of modifiers, these are described below.
[ ?, /, @, = ] Modifiers
The first four verbs described above take the same set of modifiers. These modifiers specify the format of command output. Each modifier consists of a letter preceded by an optional repeat count; each verb may take one or more modifiers:
[ ?, /, @, = ] [ [ rcount ] fletter ... ]
Each time one of these commands is given, dot is incremented by a certain amount (sum of the increments specific to each format letter, see below). If a command is given without a modifier, the last specified format is used to display output. The following lists the format letter, the amount dot increments each time the letter is used, and a description of what each letter does.
o2 Print 2 bytes in octal. All octal numbers output by adb are preceded by 0.
O4 Print 4 bytes in octal.
q2 Print in signed octal.
Q4 Print long signed octal.
d2 Print in decimal.
D4 Print long decimal.
x2 Print 2 bytes in hexadecimal.
X4 Print 4 bytes in hexadecimal.
u2 Print as an unsigned decimal number.
U4 Print long unsigned decimal.
f4 Print the 32 bit value as a floating point number.
F8 Print double floating point.
b1 Print the addressed byte in octal.
c1 Print the addressed character.
C1 Print the addressed character using the standard escape convention: print control characters as ^X and the delete character as ^?.
sn Print the addressed characters until a zero character is reached.
Sn Print a string using the ^X escape convention (see C above). n is the length of the string including its zero terminator.
Y4 Print 4 bytes in date format (see ctime(3)).
in Print as machine instructions. n is the number of bytes occupied by the instruction. In this format, variables 1 and 2 are set to the offset parts of the source and destination respectively.
zn Print as machine instructions with 68010 instruction timings. n is the number of bytes occupied by the instruction. In this format, variables 1 and 2 are set to the offset parts of the source and destination respectively.
I0 Print the source text line specified by dot (@ command) or most closely corresponding to dot (? command).
a0 Print the value of dot in symbolic form. Symbols are checked to ensure that they have an appropriate type as indicated below.
/ local or global data symbol
? local or global text symbol
= local or global absolute symbol
p4 Print the addressed value in symbolic form using the same rules for symbol lookup as a.
A0 Print the value of dot in sourcefile symbolic form, that is: "filename"+nnn. (Works only if the program has been compiled using the −go flag. See cc(1).)
P4 Print the addressed value in sourcefile symbolic form, that is: "filename"+nnn. (Works only if the program has been compiled using the −go flag. See cc(1).)
t0 When preceded by an integer, tabs to the next appropriate tab stop. For example, 8t moves to the next 8-space tab stop.
r0 Print a space.
n0 Print a newline.
"..."0 Print the enclosed string.
^ Dot is decremented by the current increment. Nothing is printed.
+ Dot is incremented by 1. Nothing is printed.
− Dot is decremented by 1. Nothing is printed.
[ ?, /] Modifiers
[?/]l value mask
Words starting at dot are masked with mask and compared with value until a match is found. If L is used then the match is for 4 bytes at a time instead of 2. If no match is found then dot is unchanged; otherwise dot is set to the matched location. If mask is omitted then −1 is used.
[?/]w value ...
Write the 2-byte value into the addressed location. If the command is W, write 4 bytes. Odd addresses are not allowed when writing to the subprocess address space.
[?/]m b1 e1 f1[?/]
New values for (b1, e1, f1) are recorded. If less than three expressions are given then the remaining map parameters are left unchanged. If the ‘?’ or ‘/’ is followed by ‘∗’ then the second segment (b2,e2,f2) of the address mapping is changed (see ADDRESS MAPPING, below). If the list is terminated by ‘?’ or ‘/’ then the file (objfil or corfil respectively) is used for subsequent requests. (So that, for example, ‘/m?’ will cause ‘/’ to refer to objfil.)
: Modifiers
bc Set breakpoint at address. The breakpoint is executed count−1 times before causing a stop. Each time the breakpoint is encountered the command c is executed. If this command is omitted or sets dot to zero then the breakpoint causes a stop.
Bc Like b but takes a sourcefile address. (Works only if the program has been compiled using the −go flag. See cc(1).)
d Delete breakpoint at address.
D Like d but takes a sourcefile address. (Works only if the program has been compiled using the −go flag. See cc(1).)
r Run objfil as a subprocess. If address is given explicitly then the program is entered at this point; otherwise the program is entered at its standard entry point. count specifies how many breakpoints are to be ignored before stopping. Arguments to the subprocess may be supplied on the same line as the command. An argument starting with < or > causes the standard input or output to be established for the command. All signals are enabled on entry to the subprocess.
cs The subprocess is continued with signal s, see sigvec(2). If address is given then the subprocess is continued at this address. If no signal is specified then the signal that caused the subprocess to stop is sent. Breakpoint skipping is the same as for r.
ss As for c except that the subprocess is single stepped count times. If there is no current subprocess then objfil is run as a subprocess as for r. In this case no signal can be sent; the remainder of the line is treated as arguments to the subprocess.
S Like s but single steps source lines, rather than machine instructions. This is acheived by repeatedly single−stepping machine instructions until the corresponding sourcefile address changes. (Thus procedure calls cause stepping to stop.) (Works only if the program has been compiled using the −go flag. See cc(1).)
i Add the signal specified by address to the list of signals which are passed directly to the subprocess with the minimum of interference. Normally, adb intercepts all signals destined for the subprocess, and the user must use the :c command to continue the process with the signal. Signals on this list are handed to the process with an implicit :cs as soon as they are seen.
t Remove the signal specified by address from the list of signals that are implicitly passed to the subprocess.
k Terminate the current subprocess, if any.
$ Modifiers
<file Read commands from the file file. If this command is executed in a file, further commands in the file are not seen. If file is omitted, the current input stream is terminated. If a count is given, and is zero, the command will be ignored. The value of the count will be placed in variable 9 before the first command in file is executed.
<<file Similar to <, but can be used in a file of commands without closing the file. Variable 9 is saved during the execution of this command, and restored when it completes. There is a (small) finite limit to the number of << files that can be open at once.
>file Append output to file, which is created if it does not exist. If file is omitted, output is returned to the terminal.
? Print process id, the signal which stopped the subprocess, and the registers. Produces the same response as $ used without any modifier.
r Print the general registers and the instruction addressed by pc. Dot is set to pc.
b Print all breakpoints and their associated counts and commands.
c C stack backtrace. If address is given then it is taken as the address of the current frame instead of the contents of the frame−pointer register. If count is given then only the first count frames are printed.
C Similar to c, but in addition prints the names and (32 bit) values of all automatic and static variables for each active function. (Works only if the program has been compiled using the −go flag. See cc(1).)
d Set the default radix to address and report the new value. Note that address is interpreted in the (old) current radix. Thus “10$d” never changes the default radix. To make decimal the default radix, use “0t10$d”.
e Print the names and values of external variables.
w Set the page width for output to address (default 80).
s Set the limit for symbol matches to address (default 255).
o All integers input are regarded as octal.
q Exit from adb.
v Print all non zero variables in octal.
m Print the address map.
f Print a list of known source file names.
p Print a list of known procedure names.
p (Kernel debugging) Change the current kernel memory mapping to map the designated user structure to the address given by the symbol _u. The address argument is the address of the user’s proc structure.
i Show which signals are passed to the subprocess with the minimum of adb interference. Signals may be added to or deleted from this list using the :i and :t commands.
W Re-open objfile and corfile for writing, as though the −w command−line argument had been given.
ADDRESS MAPPING
The interpretation of an address depends on the context it is used in. If a subprocess is being debugged, addresses are interpreted in the usual way (as described below) in the address space of the subprocess. If the operating system is being debugged, either post-mortem or by using the special file /dev/mem to interactively examine and/or modify memory, the maps are set to map the kernel virtual addresses which start at zero. For some commands, the address is not interpreted as a memory address at all, but as an ordered pair representing a file number and a line number within that file. The @ command always takes such a sourcefile address, and several operators are available to convert to and from the more customary core locations.
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) and the file address corresponding to a written address is calculated as follows.
b1≤address<e1 => file address=address+f1−b1, otherwise,
b2≤address<e2 => file address=address+f2−b2,
otherwise, the requested address is not legal. If a ? or / is followed by an ∗ then 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 then, for that file, b1 is set to 0, e1 is set to the maximum file size and f1 is set to 0; in this way the whole file can be examined with no address translation.
FILES
a.out
core
SEE ALSO
cc(1), dbx(1), ptrace(2), a.out(5), core(5)
Using adb to debug the UNIX kernel in the Sun System Internals Guide.
DIAGNOSTICS
‘Adb’ when there is no current command or format. Comments about inaccessible files, syntax errors, abnormal termination of commands, etc. Exit status is 0, unless last command failed or returned nonzero status.
BUGS
There doesn’t seem to be any way to clear all breakpoints.
Adb uses the symbolic information in an old and now obsolete format generated by the −go flag of cc(1); it should be changed to use the new format used by the dbx debugger and generated by −g.
Since no shell is invoked to interpret the arguments of the :r command, the customary wild−card and variable expansions cannot occur.
Since there is little type−checking on addresses, using a sourcefile address in an inappropriate context may lead to unexpected results: ‘main?i will almost certainly not do anything useful.
Sun Release 2.0 — Last change: 1 February 1985