This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 1/3] Initial support for variant parts


>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

>> +  /* * The index of the discriminant field.  If -1, then this union
>> +     must have just a single field.  */
>> +
>> +  int discriminant_index;
>> +
>> +  /* * The index of the default branch of the union.  If -1, then
>> +     there is no default branch.  */
>> +
>> +  int default_index;
>> +
>> +  /* * The discriminant values corresponding to each branch.  This has
>> +     a number of entries equal to the number of fields in this union.
>> +     If discriminant_index is not -1, then that entry in this array is
>> +     not used.  If default_index is not -1, then that entry in this
>> +     array is not used.  */
>> +
>> +  ULONGEST discriminants[1];

Joel> It took me a while to answer to myself why "discriminants[default_index]"
Joel> is unused if default_index != 1. IIUC, that's because the default branch
Joel> can apply to multiple indices, right?

Yes (assuming you meant to write "-1" there).  Here's an example showing
what a default case looks like in DWARF:

 <4><24e>: Abbrev Number: 12 (DW_TAG_variant)
 <5><24f>: Abbrev Number: 13 (DW_TAG_member)
    <250>   DW_AT_type        : <0x262>
    <254>   DW_AT_alignment   : 8
    <255>   DW_AT_data_member_location: 0

Here, the DW_TAG_variant does not have a DW_AT_discr_value or
DW_AT_discr_list.  This means it is the default -- if the discriminator
value does not match one of the other discriminants, then this variant
is assumed.

Joel> A small note: We (probably the Ada maintainers) will have to extend
Joel> your current approach to discriminant handling because a given branch
Joel> may be apply to multiple values of a given discriminant.

Yeah, that's the DW_AT_discr_list case that I mentioned in one of the
messages.  I think this should be reasonably easy to add.

Joel> Another note for the future: Discriminants in Ada can be any discrete
Joel> type (integers, signed or unsigned, enum, etc) or even an access type
Joel> (the equivalent of a pointer in C). Thinking of the future, I think we
Joel> would change the ULONGEST here into an array of char * containing the
Joel> target-side representation of the dicriminant. Or would you suggest
Joel> something different?

My first thought is that using the target representation is inconvenient
in the DWARF reader, because with DW_AT_discr_* we just get scalar
values.

It seems to me that using a wide-enough scalar here would be enough for
all the cases you list, provided that sign extension was handled
properly.  I'm not 100% sure this does handle sign extension though -- I
can update the test for that.

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]