From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22595 invoked by alias); 2 May 2010 23:01:08 -0000 Received: (qmail 22428 invoked by uid 22791); 2 May 2010 23:01:07 -0000 X-SWARE-Spam-Status: No, hits=0.0 required=5.0 tests=BAYES_40,MSGID_MULTIPLE_AT X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.156) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 02 May 2010 23:01:01 +0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o42N0k9P052814 ; Mon, 3 May 2010 01:00:47 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms1.u-strasbg.fr [IPv6:2001:660:2402:d::10]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id o42N0kIZ060812 ; Mon, 3 May 2010 01:00:46 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from d620muller (lec67-4-82-230-53-140.fbx.proxad.net [82.230.53.140]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o42N0iDD094628 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) ; Mon, 3 May 2010 01:00:45 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: Cc: References: <17731.9300863475$1272644394@news.gmane.org> In-Reply-To: Subject: [RFA] examine for TYPE_CODE_REF (PR 11349) Date: Sun, 02 May 2010 23:01:00 -0000 Message-ID: <000c01caea4b$4ef18ba0$ecd4a2e0$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" 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: 2010-05/txt/msg00021.txt.bz2 > Pierre> -inside x_command, a TYPE_CODE_REF generates a call > Pierre> to value_ind, but this generates possibly several dereferencing > Pierre> if the target type is also a pointer. > > Pierre> I do not know what is the expectation for C language > Pierre> here, and I don't even know how to generate code that > Pierre> has variables of type TYPE_CODE_REF from C source. > > You need C++ to make a TYPE_CODE_REF. It corresponds to a C++ > reference. OK, I looked into gdb.cp and found uses in ref-types.exp > Pierre> Should this change be extended to other languages > Pierre> or to all languages? > > I think coerce_ref is the right thing to do here for C++. If an > expression evaluates to a reference to a pointer, I would expect the > reference to be ignored and the referred-to pointer to be used instead. Ok, so let's try to use coerce_ref for all languages! > However, the fact that the code is explicitly written to check > TYPE_CODE_REF and use value_ind gives me pause. If you change it to > unconditionally use coerce_ref, do any tests fail? I first did a simple test without the condition, nothing special came out. After this, I tried to modify the gdb.cp/ref-types.exp to add a test for this modification. Here is a new patch: the new test fails on current CVS GDB but passes with the change in printcmd.c below. Is this patch OK? Pierre 2010-05-03 Pierre Muller * printcmd.c (x_command): Only dereference once implicitly for TYPE_CODE_REF. 2010-05-03 Pierre Muller * testsuite/gdb.cp/ref-types.exp: Add test to examine use a reference local variable. Index: src/gdb/printcmd.c =================================================================== RCS file: /cvs/src/src/gdb/printcmd.c,v retrieving revision 1.176 diff -u -p -r1.176 printcmd.c --- src/gdb/printcmd.c 22 Apr 2010 23:15:41 -0000 1.176 +++ src/gdb/printcmd.c 2 May 2010 22:21:02 -0000 @@ -1420,7 +1420,7 @@ x_command (char *exp, int from_tty) old_chain = make_cleanup (free_current_contents, &expr); val = evaluate_expression (expr); if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF) - val = value_ind (val); + val = coerce_ref (val); /* In rvalue contexts, such as this, functions are coerced into pointers to functions. This makes "x/i main" work. */ if (/* last_format == 'i' && */ Index: src/gdb/testsuite/gdb.cp/ref-types.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/ref-types.exp,v retrieving revision 1.12 diff -u -p -r1.12 ref-types.exp --- src/gdb/testsuite/gdb.cp/ref-types.exp 1 Jan 2010 07:32:01 -0000 1.12 +++ src/gdb/testsuite/gdb.cp/ref-types.exp 2 May 2010 22:21:03 -0000 @@ -200,6 +200,19 @@ gdb_expect { timeout { fail "(timeout) print value of *rps" } } +# GDB had a bug about dereferencing a pointer type +# that would lead to wrong results +# if we try to examine memory at pointer value. + +send_gdb "x /hd rps\n" +gdb_expect { + -re ".* -1.*$gdb_prompt $" { + pass "examine value at rps" + } + -re ".*$gdb_prompt $" { fail "examine value at rps" } + timeout { fail "(timeout) examine value at rps" } + } + send_gdb "ptype rps\n" gdb_expect {