DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
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.

   *errflag/
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:
   *sub:i/

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:

   *x*/
   *sub:y?/
   **/
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:

b
one byte

h
two bytes (half word)

l
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:

c
character

d
decimal

u
decimal unsigned

o
octal

x
hexadecimal

f
32-bit single-precision floating point

g
64-bit double-precision floating point

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

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

p
pointer to function

i
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:
   *i/x
The sdb program also knows about structures, arrays, and pointers, so that all of the following commands work.
   *array[2][3]/
   *sym.id/
   *psym->usage/
   *xsym[20].p->usage/
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.
   *psym[0]

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

   *1024/
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:
   *02000/
   *0x400/
To print out the contents of argv in the stack trace example above:
   *0x7fffff54/s
It is possible to mix numbers and variables so that the following refers to an element of a structure starting at address 1000:
   *1000.x/
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.
   *1000->x/
The address of a variable is printed with =. The following displays the address of i.
   *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