DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
adb: absolute debugger

Forming expressions

Expressions contain decimal, octal, and hexadecimal integers, symbols, adb variables, register names, and a variety of arithmetic and logical operators.

Symbol names

A symbol is the name of a global variable or function defined within the program being debugged, and is equal to the address of the given variable or function. Symbols are stored in the program's symbol table, and are available if the symbol table has not been stripped from the program file.

Expressions that include references to a function can be evaluated by specifying the function's name or its symbol table name. Symbols in the symbol table are no more than 31 characters long. The following are examples of symbols:

   main	_start	hex2bin	__out_of
By using the question mark (?) command, adb uses the symbols found in the symbol table of the program file to create symbolic addresses. Sometimes the command gives a function name when it displays data. This does not happen if the ? command for text (instructions) and the slash (/) command is used for data. Local variables cannot be addressed.

adb variables

adb automatically creates a set of its own variables whenever the debugger is initiated. These variables are set to the addresses and sizes of various parts of the program file as defined below:


Variable
Definition

b
base address of data segment

d
size of data

e
entry address of the program

m
execution type

n
number of segments

s
size of stack

t
size of text
A user can access storage locations using the adb defined variables.

The following request prints these variables:

   $v
adb reads the program file to find the values for these variables. If the file does not seem to be a program file, then adb leaves the values undefined.

To use the current value of an adb variable in an expression, precede the variable name with a less than (<) sign. For example, the current value of the base variable b is:

   <b
To create or change the value of an existing variable by assigning a value to a variable name, use the greater than (>) sign. The assignment has the following form:

expression > variable-name

In the above command line expression is the value to be assigned to the variable, and variable-name must be a single letter.

For example, the following assignment gives the hexadecimal value ``0x2000'' to the variable b:

   0x2000>b
To display the values of all currently defined adb variables, followed by their values in the current format, use the $v command. The command displays any variable whose value is not zero. If a variable also has a nonzero segment value, the variable's value is displayed as an address; otherwise it is displayed as a number.

Current address

The adb program has two special variables that keep track of the last address to be used in a command and the last address to be typed with a command. The dot (.) variable, also called the current address, contains the last address to be used in a command. The double quotation mark (") variable contains the last address to be typed with a command. The dot and double quote variables are usually the same except when you use implied commands, such as the Newline and caret (^) characters. (These automatically increment and decrement dot, but leave " unchanged.)

Both the dot and the double quote can be used in any expression. The less than (<) sign is not required. For example, the following command displays the value of the current address:

   .=
The following command displays the last address to be typed:
   "=

Register names

adb allows the use of the current value of the CPU registers when evaluating expressions. To specify the value of a register, precede its name with the less than (<) sign.

For example, the value of the eax register can be evaluated in an expression by specifying the register as follows:

   <eax


NOTE: Register names cannot be used unless adb has been started with either a core file, or the program is currently being run under adb control.

Operators

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

Unary Meaning
~ Not
- Negative
* Contents of location
Binary Meaning
+ Addition
- Subtraction
* Multiplication
% Integer division
& Bitwise And
| Bitwise inclusive Or
^ Modulo
# Round up to the next multiple

Unary operators have higher precedence than binary operators. Expressions are evaluated from left to right. All binary operators have the same precedence. Therefore, the following expression evaluates to 10:

   2*3+4
whereas the following expression evaluates to 18:
   4+2*3
To change the precedence of the operations in an expression use parentheses. For example, the following expression evaluates to 10:
   4+(2*3)


NOTE: The adb program uses 32-bit arithmetic. Values that exceed 2,147,483,647 (decimal) are displayed as negative values.

The unary * operator treats an expression as a pointer to an address. An expression using this operator evaluates to the value stored at the given address. For example, the following expression evaluates to the value stored at the address ``0x1234'':

   *0x1234
Whereas the following is just equal to ``0x1234'':
   0x1234


Next topic: Choosing data formats
Previous topic: Forming addresses

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003