
Examining Data
Motorola
GNU Debugger (GDB)
For More Information On This Product,
Go to: www.freescale.com
D-35
As a special exception, you can refer to a variable or function whose scope is a single
source file even if the current execution point is not in this file. But it is possible to have
more than one such variable or function with the same name (if they are in different source
files). In such a case, it is not defined which one you will get. If you wish, you can specify
any one of them using the colon colon construct:
block::variable
Here block is the name of the source file whose variable you want.
D.9.3 Artificial Arrays
It is often useful to print out several successive objects of the same type in memory; a
section of an array, or an array of dynamically determined size for which only a pointer
exists in the program.
This can be done by constructing an artificial array with the binary operator ‘@’. The left
operand of ‘@’ should be the first element of the desired array, as an individual object.
The right operand should be the length of the array. The result is an array value whose
elements are all of the type of the left argument. The first element is actually the left
argument; the second element comes from bytes of memory immediately following those
that hold the first element, and so on. Here is an example. If a program says
int *array = (int *) malloc (len * sizeof (int));
you can print the contents of array with
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. (It would probably appear in an expression via the value history, after
you had printed it out.)
D.9.4 Format options
GDB provides a few ways to control how arrays and structures are printed.
info format
Display the current settings for the format options.
set array-max number-of-elements
If GDB is printing a large array, it will stop printing after it has printed the number of
elements set by the ‘set array-max’ command. This limit also applies to the display of
strings.
F
Freescale Semiconductor, Inc.
n
.