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: [PATCH 2/2] handle VLA in a struct or union


Hey Tom,

> > Joel> I think I need to review that code, as I do that a litte little
> > Joel> later in the function again. I'll send another update when I have
> > Joel> more info on this.
[...]
> So far, I've tried to build the dval using the original type,
> but that doesn't seem to be good enough. That's all I could do today,
> but I will have another look at it tomorrow.

This is really annoying :-(. We can't build the dval using
the original type because the length of that type is bogus
by construction. The errors I am seeing when I try that happen
when trying to print tagged objects containing dynamic structures
whose size depend on a discriminant. For instance:

 | type Variant_Root (R : Integer) is tagged record
 |    Initial : String (1 .. R) := (others => 'j');
 | end record;
 |
 | type Variant_Derived is new Variant_Root with record
 |    Attribute : Integer := 1;
 | end record;
 |
 | V : Variant_Derived (2);

This declares the Ada equivalent of a C++ class called Variant_Root
inside which we have an array "Initial" whose index range is 1 .. R,
and therefore dependent of the value of that field (a discriminant).
It then creates a new "class" Variant_Derived which is derived from
Variant_Root and adds an extra field Attribute. I don't think that
the extra derivation is really needed to reproduce the problem, but
that's what I investigated...

In any case, what happens is that we have an ___XVE type as per
the GNAT encoding (see exp_dbug.ads in gcc/ada), and the size of
that type cannot be used. It so happens to have a size of 8, but
it could as easily be 0, or -1. And unfortunately, the field we
are interested in ("R") is at offset 8. So when we create the dval
using the original type, and try to get the field at offset 8,
we start reading undefined memory...  (one of these days, we should
guard against this)

Perhaps we might think of having a new value_from_contents_and_address
that produces the value without resolving the type? If Ada is the only
user, as it would be, we could possibly put implement that in ada-lang,
I think. Kind of ugly, but this would be medium-term only, since we are
slowly trying to get rid of the GNAT encodings.

-- 
Joel


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