From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58060 invoked by alias); 23 Mar 2015 13:36:36 -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 58045 invoked by uid 89); 23 Mar 2015 13:36:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 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; Mon, 23 Mar 2015 13:36:33 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9B2501162E4; Mon, 23 Mar 2015 09:36:29 -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 qm6j844DMlZl; Mon, 23 Mar 2015 09:36:29 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 672E71162DF; Mon, 23 Mar 2015 09:36:29 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id CD95540EAD; Mon, 23 Mar 2015 06:36:27 -0700 (PDT) Date: Mon, 23 Mar 2015 13:36:00 -0000 From: Joel Brobecker To: Pierre-Marie de Rodat Cc: GDB Patches Subject: Re: [PATCH] Do not consider reference types as dynamic Message-ID: <20150323133627.GG5438@adacore.com> References: <54FEDC09.3050106@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54FEDC09.3050106@adacore.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2015-03/txt/msg00720.txt.bz2 Hello Pierre-Marie, > I'm working on a GCC patch that fixes the type of Ada functions that > return their result by reference: the debugging information > currently says they return a pointer to the result and my patch > turns these into references. The intent is that when evaluating a > call to such functions from debuggers, the returned value is > automatically dereferenced: > > # Currently we have: > (gdb) print my_function("foo") > $1 = (access ...) 0x... > > # We would like to have instead: > (gdb) print my_function("foo") > $1 = > > Doing so in GDB is currently not possible when the referenced object > type is dynamic. Indeed, the return value for such calls is not in > memory and GDB considers reference types as dynamic iff the > referenced type is dynamic. As a consequence, the type resolving > process ends up trying to read memory at address 0x0, fails to do so > and aborts printing the final value: > > # With my locally patched GCC, I have: > (gdb) print my_function("foo") > $1 = Cannot access memory at address 0x0 > > The attached patch fixes GDB so that the above works. It just makes > GDB never consider reference types as dynamic (which makes sense per > se IMHO) so this memory problem does not occurs. > > I tested this patch on x86_64-linux with C, C++, Ada, Fortran and > Java compilers: it triggers no regression. Note that the testcase it > adds (gdb.ada/funcall_ref.exp) cannot pass without my local GCC > patch and relies on my previous submitted patch > (https://www.sourceware.org/ml/gdb-patches/2015-03/msg00241.html). If it cannot pass without your GCC patch, let's add a setup_xfail. > Ok to push? > Thank you in advance! > > gdb/ChangeLog: > 2015-03-10 Pierre-Marie de Rodat > > * gdbtypes.c (is_dynamic_type_internal): Remove special handling > of TYPE_CODE_REF types so that they are not considered as > dynamic depending on the referenced type. > > gdb/testsuite/ChangeLog: > 2015-03-10 Pierre-Marie de Rodat > > * gdb.ada/funcall_ref.exp: New file. > * gdb.ada/funcall_ref/foo.adb: New file. Mostly OK - a couple of minor comments below. > +# Test printing and type-printing of a discriminated record that a function > +# returns by reference. > + > +gdb_test "p get (\"Hello world!\")" \ > + "= \\(n => 12, s => \"Hello world!\"\\)" \ > + "p get (\"Hello world!\")" If the test "label" (3rd argument) is the same as the command being sent, you do not need to explicitly specify it. So, the following is equivalent to your version: gdb_test "p get (\"Hello world!\")" \ "= \\(n => 12, s => \"Hello world!\"\\)" > +gdb_test "ptype get (\"Hello world!\")" \ > + [multi_line "type = record" \ > + " n: natural;" \ > + " s: access array \\(1 \\.\\. n\\) of character;" \ > + "end record"] \ > + "ptype get (\"Hello world!\")" Same here. > +++ b/gdb/testsuite/gdb.ada/funcall_ref/foo.adb > @@ -0,0 +1,19 @@ > +procedure Foo is Missing copyright header. Thank you, -- Joel