Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] handle VLA in a struct or union
Date: Fri, 09 May 2014 15:57:00 -0000	[thread overview]
Message-ID: <20140509155726.GG4063@adacore.com> (raw)
In-Reply-To: <20140508223853.GF4063@adacore.com>

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


  reply	other threads:[~2014-05-09 15:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-08 18:47 [PATCH 0/2] " Tom Tromey
2014-05-08 18:47 ` [PATCH 1/2] minor cleanups in is_dynamic_type Tom Tromey
2014-05-08 18:47 ` [PATCH 2/2] handle VLA in a struct or union Tom Tromey
2014-05-08 19:01   ` pinskia
2014-05-08 19:07     ` Tom Tromey
2014-05-08 20:30     ` Philippe Waroquiers
2014-05-08 21:32       ` Tom Tromey
2014-05-08 21:09   ` Joel Brobecker
2014-05-08 21:33     ` Tom Tromey
2014-05-08 22:38       ` Joel Brobecker
2014-05-09 15:57         ` Joel Brobecker [this message]
2014-05-21 17:28           ` Tom Tromey
2014-05-21 18:24             ` Joel Brobecker
2014-05-21 22:02             ` Joel Brobecker
2014-05-21 22:28               ` Tom Tromey
2014-06-04 20:27               ` Tom Tromey
2014-05-09  8:05   ` Agovic, Sanimir
2014-05-09 21:08     ` Tom Tromey
2014-05-12 15:37       ` Agovic, Sanimir
2014-05-12 17:00         ` Tom Tromey
2014-05-13  7:53           ` Agovic, Sanimir

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140509155726.GG4063@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox