From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17314 invoked by alias); 9 May 2014 15:57:34 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 17158 invoked by uid 89); 9 May 2014 15:57:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 09 May 2014 15:57:30 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D738B1161A6; Fri, 9 May 2014 11:57:26 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id eHORy1GYi716; Fri, 9 May 2014 11:57:26 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id A902F1161A4; Fri, 9 May 2014 11:57:26 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 68714E0A88; Fri, 9 May 2014 08:57:26 -0700 (PDT) Date: Fri, 09 May 2014 15:57:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] handle VLA in a struct or union Message-ID: <20140509155726.GG4063@adacore.com> References: <1399574816-12845-1-git-send-email-tromey@redhat.com> <1399574816-12845-3-git-send-email-tromey@redhat.com> <20140508210914.GE4063@adacore.com> <87lhucuf98.fsf@fleche.redhat.com> <20140508223853.GF4063@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140508223853.GF4063@adacore.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2014-05/txt/msg00116.txt.bz2 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