Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: <tromey@redhat.com>
Cc: <gdb-patches@sourceware.org>
Subject: [RFA] examine for TYPE_CODE_REF  (PR 11349)
Date: Sun, 02 May 2010 23:01:00 -0000	[thread overview]
Message-ID: <000c01caea4b$4ef18ba0$ecd4a2e0$@muller@ics-cnrs.unistra.fr> (raw)
In-Reply-To: <m3y6g4zxkr.fsf@fleche.redhat.com>

> 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  <muller@ics.u-strasbg.fr>

	* printcmd.c (x_command): Only dereference once implicitly for
	TYPE_CODE_REF.

2010-05-03  Pierre Muller  <muller@ics.u-strasbg.fr>

	* 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 {


  reply	other threads:[~2010-05-02 23:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <17731.9300863475$1272644394@news.gmane.org>
2010-04-30 16:59 ` [RFC] examine for TYPE_CODE_REF in pascal language PR 11349 Tom Tromey
2010-05-02 23:01   ` Pierre Muller [this message]
2010-05-03 17:40     ` [RFA] examine for TYPE_CODE_REF (PR 11349) Tom Tromey
2010-05-04  6:52       ` Pierre Muller
2010-05-04 14:22         ` Joel Brobecker

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='000c01caea4b$4ef18ba0$ecd4a2e0$@muller@ics-cnrs.unistra.fr' \
    --to=pierre.muller@ics-cnrs.unistra.fr \
    --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