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

Using adb Expressions

The following sections describe the use of adb expressions.

Using Integers in Expressions

When creating an expression, you can use integers in three forms: decimal, octal, and hexadecimal. Decimal integers must begin with a non-zero decimal digit. Octal numbers must begin with a 0 (zero) and have octal digits only (0-7). Hexadecimal numbers must begin with the prefix 0x and can contain decimal digits and the letters a through f (in both uppercase and lowercase). The following are examples of valid numbers:

Decimal         Octal            Hexadecimal
34              042              0x22
4090            07772            0xffa

Using Symbols in Expressions

Symbols are the names of global variables and functions defined within the program being debugged. Symbols are equal to the address of the given variable or function. They are stored in the program symbol table and are available if the symbol table has not been stripped from the program file.

In expressions, you can spell the symbol exactly as it is in the source program or as it has been stored in the symbol table. Symbols in the symbol table are no more than 8 characters long.

When you use the ? subcommand, the adb program uses the symbols found in the symbol table of the program file to create symbolic addresses. Thus, the ? subcommand sometimes gives a function name when displaying data. This does not happen if the ? subcommand is used for text (instructions) and the / command is used for data.

Local variables can only be addressed if the C language source program is compiled with the -g flag.

If the C language source program is not compiled using the -g flag the local variable cannot be addressed. The following command displays the value of the local variable b in a function sample:

.sample.b / x - value of local variable.
.sample.b = x - Address of local variable.

Using Operators in Expressions

You can combine integers, symbols, variables, and register names with the following operators:

Unary Operators: 
~ (tilde) Bitwise complementation
- (dash) Integer negation
* (asterisk) Returns contents of location
Binary Operators: 
+ (plus) Addition
- (minus) Subtraction
* (asterisk) Multiplication
% (percent) Integer division
& (ampersand) Bitwise conjunction
] (right bracket) Bitwise disjunction
^ (caret) Modulo
# (number sign) Round up to the next multiple

The adb debug program uses 32-bit arithmetic. Values that exceed 2,147,483,647 (decimal) are displayed as negative values. The following example shows the results of assigning two different values to the variable n, and then displaying the value in both decimal and hexadecimal:

2147483647>n<
n=D
    2147483647<
n=X
    7fffffff
2147483648>n<
n=D
    -2147483648<
n=X
    80000000

Unary operators have higher precedence than binary operators. All binary operators have the same precedence and are evaluated in order from left to right. Thus, the adb program evaluates the following binary expressions as shown:

2*3+4=d
    10
4+2*3=d
    18

You can change the precedence of the operations in an expression by using parentheses. The following example shows how the previous expression is changed by using parentheses:

4+(2*3)=d
    10

The unary operator, * (asterisk), treats the given address as a pointer into the data segment. An expression using this operator is equal to the value pointed to by that pointer. For example, the expression:

*0x1234

is equal to the value at the data address 0x1234, whereas the example:

0x1234

is equal to 0x1234.

Related Information

adb Debug Program Overview.

Customizing the adb Debug Program.

Computing Numbers and Displaying Text.

Displaying and Manipulating the Source File with the adb Program.

adb Debug Program Expressions

adb command.


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