188.8.131.52 Array Slices
It is often useful to print out several successive objects of the same
type in memory; a "slice" (section) of an array, or an array of
dynamically determined size for which only a pointer exists in the
Using DDD, you can display slices using the `FROM..TO' notation
(Note: Creating Multiple Displays). But this requires that you
already know FROM and TO; it is also inefficient to create several
single displays. If you use GDB, you have yet another alternative.
Using GDB, you can display successive objects by referring to a
contiguous span of memory as an "artificial array", using the binary
operator `@'. The left operand of `@' should be the first element of
the desired array and be an individual object. The right operand
should be the desired 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
and display the contents with
graph display array@len
The general form of displaying an array slice is thus
graph display ARRAY[FIRST]@NELEMS
where ARRAY is the name of the array to display, FIRST is the index of
the first element, and NELEMS is the number of elements to display.
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.
automatically generated by info2www version 184.108.40.206