sdb: symbolic debugger

Examining variables

The sdb program can be used to display variables in the stopped program. A variable is displayed by typing its name followed by a slash.

This causes sdb to display the value of variable errflag. Unless otherwise specified, variables are assumed to be either local to or accessible from the current function. To specify a different function, use the following to display variable i in function sub:

The sdb program supports a limited form of pattern matching for variable and function names. The symbol * is used to match any sequence of characters of a variable name and ?, to match any single character. Consider the following commands:

The first prints the values of all variables beginning with x, the second prints the values of all two-letter variables in function sub beginning with y, and the last prints all variables. In the first example, only variables accessible from the current function are printed. The last example, prints global program and libc variables. The following command displays the variables for each function on the call stack and libc variables.
The sdb program normally displays the variable in a format determined by its type as declared in the source program. To request a different format, place a specifier after the slash. The specifier consists of an optional length specification followed by the format. The length specifiers are:

one byte

two bytes (half word)

four bytes (long word)
The length specifiers are effective only with the formats d, o, x, and u. If no length is specified, the word length of the host machine is used. A number can be used with the s or a format to control the number of characters printed. The s and a formats normally print characters until either a null is reached or 128 characters have been printed. The number specifies exactly how many characters should be printed. There are a number of format specifiers available:



decimal unsigned



32-bit single-precision floating point

64-bit double-precision floating point

assume variable is a string pointer and print characters starting at the address pointed to by the variable, until a null is reached

print characters starting at the variable's address until a null is reached

pointer to function

interpret as a machine-language instruction
For example, the variable i can be displayed with the following to print out the value of i in hexadecimal:
The sdb program also knows about structures, arrays, and pointers, so that all of the following commands work.
The only restriction is that array subscripts must be numbers.

NOTE: As a special case, the following displays the structure pointed to by psym in decimal.

Core locations can also be displayed by specifying their absolute addresses.

The above command displays location 1024 in decimal. As in C language, numbers may also be specified in octal or hexadecimal, so the above command is equivalent to both:
To print out the contents of argv in the stack trace example above:
It is possible to mix numbers and variables so that the following refers to an element of a structure starting at address 1000:
Where as the following refers to an element of a structure whose address is at 1000. For commands of the types *1000.x/ and *1000->x/, the sdb program uses the structure template of the last structure referenced.
The address of a variable is printed with =. The following displays the address of i.
Another feature whose usefulness will become apparent later is the following command which redisplays the last variable typed:

Next topic: Source file display and manipulation
Previous topic: Printing a stack trace

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