|
|
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:
*i/xThe 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.
*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/sIt 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:
*./