Expressions contain decimal, octal, and hexadecimal integers, symbols, adb variables, register names, and a variety of arithmetic and logical operators.
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_ofBy 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 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:
The following request prints these variables:
$vadb 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:
<bTo 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:
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>bTo 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.
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:
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:
Integers, symbols, variables, and register names can be combined with the following operators:
|*||Contents of location|
||||Bitwise inclusive Or|
|#||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+4whereas the following expression evaluates to 18:
4+2*3To change the precedence of the operations in an expression use parentheses. For example, the following expression evaluates to 10:
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'':
*0x1234Whereas the following is just equal to ``0x1234'':