[Dwarf-discuss] Recovering type definitions

Paul Hilfinger hilfingr
Wed May 25 22:58:58 PDT 2005


I was looking at the Ada example in D.2.2, which contains

    subtype TEENY is INTEGER range 1..100; 
    type ARR is array (INTEGER range <>) of INTEGER; 
    type REC2(N : TEENY := 100) is record 
       VEC2 : ARR(1..N);  -- < 
    end record; 

The suggested encoding for the type REC2 gives the location of
VEC2's upper bound as a DWARF expression:

    DW_OP_push_object_address, 
    DW_OP_lit<n> ! where n == offset(REC2, VEC2) - offset(REC2, N) 
    DW_OP_neg 
    DW_OP_plus

It occurs to me that one has to work a bit to recover from this the
information that, e.g., GDB would print in response to 

    ptype REC2

which would be expected to resemble the original type declaration to
some extent, e.g.,

     type rec2 is record
        n : teeny;
	vec2: arr ( 1 .. n );
     end record;

Indeed, while it is possible to recover that the upper bound is N (by 
symbolically analyzing the expression and discovering that the
indicated location happens to coincide with that of N), it is
impossible from the suggested encoding to reproduce the type names Teeny for
N and Arr for Vec2 (as the text says, there is no notion of subtype in
Dwarf).

It might seem that the problem of type names could be solved by giving
names to the types of n and vec2, but would the resulting name
duplication cause confusion?  

Also, recovering that the upper bound is N in this case looks easy
enough, but things look to become harder with more complex types in
which several fields are dynamic, as for VEC3 in 

    type REC3(M, N : TEENY) is record 
       VEC2 : ARR(M..N);
       VEC3 : ARR(1..M);
    end record; 

(in the particular Ada implementations of interest, VEC2 and VEC3 are
unboxed).  I am not sanguine about extracting a general algorithm for
'ptype'-like operations given examples like this.

Is there a better way of encoding these examples in DWARF?  

Paul Hilfinger
AdaCore, Inc.







More information about the Dwarf-Discuss mailing list