Array formatting

Xcdb displays arrays similar to structures, except that the elements are identified by indexes rather than member names. At the minimum level of detail, only the word array displays. At the maximum level, the indexes and values of all the array elements display.

Statically allocated arrays

Consider the following declaration.

      struct point
          {
          char *name;
          int   coord[3];
          } Set[] = {
                  {"one",   {1,1,1}},
                  {"two",   {2,2,2}},
                  {"three", {3,3,3}},
                  {"four",  {4,4,4}},
                  {"five",  {5,5,5}},
                  {"six",   {6,6,6}},
                  };
This sequence shows how you might inspect the object:

      
    Set: array
      
      
    Set: { point point point point ... }
      
      
    Set: 0: point
           1: point
           2: point
           3: point
           ...
      
      Set: 0: { ptr array }
      
         1: { ptr array }
           2: { ptr array }
           3: { ptr array }
           ...
      
      Set: 0: { ptr array }
           1: name: ptr
      
            coord: array
           2: { ptr array }
           3: { ptr array }
           ...
      
      Set: 0: { ptr array }
           1: name: ptr
              coord: { 2 2 2 }
           2: { ptr array }
           3: { ptr array }
           ...

Dynamically allocated arrays

In the previous section, the array dimensions were defined at compile time and known to the debugger. But for arrays with runtime defined dimensions, the outer array dimension is unknown to Xcdb, so it assumes a value of 1 until you tell it otherwise. Consider the following declaration:

      main()
          {
          char **stuff = malloc(3 * sizeof(char *));
          stuff[0] = "abc";
          stuff[1] = "def";
          stuff[2] = "ghi";
          return 0;
          }
To format stuff as an array of character pointers, step the program until the array has been completely initialized, and then:

      
    stuff: ->->0x61
      
      
    stuff: ->"abc"
      
      
      
    stuff: { "abc" "def" NULL }
      
      stuff: 0: "abc"
          1: "def"
          2: "ghi"

Subrange selection

Select specific subranges of array elements by clicking on the array and choosing Select subrange from the menu. Then, type the subscript or range of subscripts of the element(s) you wish to see. Use an expression of the form:

      subrangeSpecifier     ::= sectionSpecifier { ',' sectionSpecifier }...
      
      sectionSpecifier      ::= '[' subdimensionSpecifier { ',' subdimensionSpecifier }... ']'
      
      subdimensionSpecifier ::= lo '..' hi// subdim elements between lo and hi, inclusive
                          |   lo  '..' '*'// all elements of subdimension, starting at 'lo'
                          |   '*' '..' hi// all elements of subdimension, ending at 'hi'
                          |   '*' '..' '*'// all elements of subdimension
                          |   '*'       // all elements of subdimension
                          |   n           // nth element of subdimension
The count of subdimensionSpecifier items must match the count of array dimensions. Here are some examples:

      char array[4][2];           // a 4 by 2 array
      
      [0, *]                      // matches elements:    [0,0]
                                                          [0,1]
      
      [1..2, 1], [ 3, 0..1]       // matches elements:    [1,1]
                                                          [2,1]
                                                          [3,0]
                                                          [3,1]
If a subrange specifier would display more than 1,000 elements, then the remainder would display as "...". Change this limit by specifying a different value using -e or the xcdb.ArrayLimits item in .Xdefaults.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker