From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19764 invoked by alias); 13 Feb 2013 20:31:47 -0000 Received: (qmail 19742 invoked by uid 22791); 13 Feb 2013 20:31:42 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Feb 2013 20:31:33 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1DKVXfM016411 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Feb 2013 15:31:33 -0500 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1DKVVLV015486 for ; Wed, 13 Feb 2013 15:31:32 -0500 Subject: [PATCH] [RFC] Fix ptype bug actually exercised in userdef.exp To: gdb-patches@sourceware.org From: Pedro Alves Date: Wed, 13 Feb 2013 20:31:00 -0000 Message-ID: <20130213203131.30816.4686.stgit@brno.lan> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 X-SW-Source: 2013-02/txt/msg00327.txt.bz2 I happened to notice a bug with ptype &Ref, and found out userdef.exp actually exercises the bug. With: class Container { public: Member m; Member& operator* (); }; Member& Container::operator* () { return this->m; } And 'c' is of type Container: (gdb) p c $1 = {m = {z = -9192}} (gdb) p *c $2 = (Member &) @0x7fffffffda20: {z = -9192} (gdb) ptype *c type = class Member { public: int z; } & (gdb) p &*c $3 = (Member *) 0x7fffffffda20 (gdb) ptype &*c type = class Member { public: int z; } &* (gdb) Notice that last print (&*c) on says the type is a pointer - that's how you get the address behind a reference. But notice the last ptype instead says the type of the same expression is a pointer _reference_. This looks like a bug to me. This patch fixes it. The issue is that we're entering the VALUE_LVAL (x) == lval_memory branch by mistake for references. The fix is just to swap the tests so references are checked first, like value_addr also handles references first. Comments? Tested on x86_64 Fedora 17. 2013-02-13 Pedro Alves * eval.c (evaluate_subexp_for_address) : Swap and handle TYPE_CODE_REF before lval_memory. 2013-02-13 Pedro Alves * gdb.cp/userdef.exp (ptype &*c): Don't expect an &. --- gdb/eval.c | 10 ++++------ gdb/testsuite/gdb.cp/userdef.exp | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/gdb/eval.c b/gdb/eval.c index f4b39cb..96efa21 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -2929,12 +2929,10 @@ evaluate_subexp_for_address (struct expression *exp, int *pos, { struct type *type = check_typedef (value_type (x)); - if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x)) - return value_zero (lookup_pointer_type (value_type (x)), - not_lval); - else if (TYPE_CODE (type) == TYPE_CODE_REF) - return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)), - not_lval); + if (TYPE_CODE (type) == TYPE_CODE_REF) + return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)), not_lval); + else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x)) + return value_zero (lookup_pointer_type (value_type (x)), not_lval); else error (_("Attempt to take address of " "value not located in memory.")); diff --git a/gdb/testsuite/gdb.cp/userdef.exp b/gdb/testsuite/gdb.cp/userdef.exp index 7c20b33..51a1bb5 100644 --- a/gdb/testsuite/gdb.cp/userdef.exp +++ b/gdb/testsuite/gdb.cp/userdef.exp @@ -133,7 +133,7 @@ gdb_test "break A2::operator +" ".*Breakpoint $decimal at.*" gdb_test "print c" "\\\$\[0-9\]* = {m = {z = .*}}" gdb_test "print *c" "\\\$\[0-9\]* = \\(Member &\\) @$hex: {z = .*}" gdb_test "print &*c" "\\\$\[0-9\]* = \\(Member \\*\\) $hex" -gdb_test "ptype &*c" "type = (struct|class) Member {(\[\r\n \]+public:)?\[\r\n \]+int z;\[\r\n\].*} &\\*" +gdb_test "ptype &*c" "type = (struct|class) Member {(\[\r\n \]+public:)?\[\r\n \]+int z;\[\r\n\].*} \\*" gdb_test "print operator== (mem1, mem2)" " = false" gdb_test "print operator== (mem1, mem1)" " = true"