HP (Hewlett-Packard) 5992-4701 Computer Hardware User Manual


 
p *array@len
The left operand of '@' must reside in memory. Array values made with '@' in this way
behave just like other arrays in terms of subscripting, and are coerced to pointers when
used in expressions. Artificial arrays most often appear in expressions via the value
history (see “Value history” (page 95)), after printing one out.
Another way to create an artificial array is to use a cast. This re-interprets a value as if
it were an array. The value need not be in memory:
((gdb)) p/x (short[2])0x12345678
$1 = {0x1234, 0x5678}
As a convenience, if you leave the array length out (as in '(type[])value'), GDB
calculates the size to fill the value (as 'sizeof(value)/sizeof(type)':
((gdb)) p/x (short[])0x12345678
$2 = {0x1234, 0x5678}
Sometimes the artificial array mechanism is not quite enough; in moderately complex
data structures, the elements of interest may not actually be adjacent―for example, if
you are interested in the values of pointers in an array. One useful work-around in this
situation is to use a convenience variable (See “Convenience variables” (page 96)) as
a counter in an expression that prints the first interesting value, and then repeat that
expression via RET. For instance, suppose you have an array dtab of pointers to
structures, and you are interested in the values of a field fv in each structure. Here is
an example of what you might type:
set $i = 0
p dtab[$i++]->fv
<RET>
<RET>
...
8.4 Output formats
By default, GDB prints a value according to its data type. Sometimes this is not what
you want. For example, you might want to print a number in hex, or a pointer in
decimal. Or you might want to view data in memory at a certain address as a character
string or as an instruction. To do these things, specify an output format when you print
a value.
The simplest use of output formats is to say how to print a value already computed.
This is done by starting the arguments of the print command with a slash and a format
letter. The format letters supported are:
x
Regard the bits of the value as an integer, and print the integer in hexadecimal.
d
Print as integer in signed decimal.
u
Print as integer in unsigned decimal.
o
Print as integer in octal.
86 Examining Data