This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFC: fix PR c++/15401
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 08 May 2013 12:58:22 -0600
- Subject: RFC: fix PR c++/15401
This fixes PR c++/15401.
The bug is that with 'set print object on', printing a value which is
a reference to a pointer loses the reference type.
Built and regtested on x86-64 Fedora 18.
New regression test included.
Tom
PR c++/15401:
* c-valprint.c (c_value_print): Use value_addr for
references. Convert back to reference type with value_ref.
* gdb.cp/class2.cc (main): New local 'aref'.
* gdb.cp/class2.exp: Check printing of 'aref'.
---
gdb/c-valprint.c | 24 ++++++++++++------------
gdb/testsuite/gdb.cp/class2.cc | 1 +
gdb/testsuite/gdb.cp/class2.exp | 4 ++++
3 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 646aed7..ce2c29d 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -497,18 +497,11 @@ c_value_print (struct value *val, struct ui_file *stream,
else if (options->objectprint
&& (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
{
+ int is_ref = TYPE_CODE (type) == TYPE_CODE_REF;
+
+ if (is_ref)
+ val = value_addr (val);
- if (TYPE_CODE(type) == TYPE_CODE_REF)
- {
- /* Copy value, change to pointer, so we don't get an
- error about a non-pointer type in
- value_rtti_target_type. */
- struct value *temparg;
- temparg=value_copy(val);
- deprecated_set_value_type
- (temparg, lookup_pointer_type (TYPE_TARGET_TYPE (type)));
- val = temparg;
- }
/* Pointer to class, check real type of object. */
fprintf_filtered (stream, "(");
@@ -522,7 +515,14 @@ c_value_print (struct value *val, struct ui_file *stream,
type = real_type;
/* Need to adjust pointer value. */
- val = value_from_pointer (type, value_as_address (val) - top);
+ val = value_from_pointer (real_type,
+ value_as_address (val) - top);
+
+ if (is_ref)
+ {
+ val = value_ref (value_ind (val));
+ type = value_type (val);
+ }
/* Note: When we look up RTTI entries, we don't get
any information on const or volatile
diff --git a/gdb/testsuite/gdb.cp/class2.cc b/gdb/testsuite/gdb.cp/class2.cc
index 0c9d9df..97c44de 100644
--- a/gdb/testsuite/gdb.cp/class2.cc
+++ b/gdb/testsuite/gdb.cp/class2.cc
@@ -67,6 +67,7 @@ int main (void)
B beta, *bbp;
C gamma;
empty e;
+ A &aref (alpha);
alpha.a1 = 100;
beta.a1 = 200; beta.b1 = 201; beta.b2 = 202;
diff --git a/gdb/testsuite/gdb.cp/class2.exp b/gdb/testsuite/gdb.cp/class2.exp
index 824f56e..00b6322 100644
--- a/gdb/testsuite/gdb.cp/class2.exp
+++ b/gdb/testsuite/gdb.cp/class2.exp
@@ -110,3 +110,7 @@ gdb_test_no_output "set print object on"
gdb_test "p acp" "= \\(C \\*\\) ${hex}"
gdb_test "p acp->c1" "\\(A \\*\\) 0x0"
gdb_test "p acp->c2" "\\(A \\*\\) ${hex}f"
+
+# Regression test for PR c++/15401.
+# Check that the type printed is a reference.
+gdb_test "p aref" " = \\(A \\&\\) .*"
--
1.8.1.4