This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: fix PR c++/9197


This fixes PR c++/9197.

The PR doesn't really show any symptoms of the bug -- it is one of the
"cleanup" bugs that remain open in bugzilla -- but PR 11463 shows the
problem nicely: "print test1.gnu_obj_1" shows something, but "ptype" of
the same expression yields an error.

The current code uses lookup_struct_elt_type when
EVAL_AVOID_SIDE_EFFECTS is specified.  However, I don't see any reason
that this has to be done.  Other code paths read memory in this mode.
So, this patch removes these calls.

I took the liberty of updating opencl-lang.c as well.  I have no way to
test it but I believe it is obviously correct if the eval.c changes are.

Built and regtested on x86-64 Fedora 16.
New test case, from PR 11463, included.

Tom

2013-01-10  Tom Tromey  <tromey@redhat.com>

	PR c++/9197:
	* opencl-lang.c (evaluate_subexp_opencl) <STRUCTOP_STRUCT>: Use
	value_struct_elt, not lookup_struct_elt_type.
	* eval.c (evaluate_subexp_standard) <STRUCTOP_STRUCT,
	STRUCTOP_PTR>: Use value_struct_elt, not lookup_struct_elt_type.

2013-01-10  Tom Tromey  <tromey@redhat.com>

	* gdb.cp/m-static.exp: Add constructor ptype tests.

diff --git a/gdb/eval.c b/gdb/eval.c
index c9630df..4866f57 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1850,18 +1850,8 @@ evaluate_subexp_standard (struct type *expect_type,
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
       if (noside == EVAL_SKIP)
 	goto nosideret;
-      if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (lookup_struct_elt_type (value_type (arg1),
-						   &exp->elts[pc + 2].string,
-						   0),
-			   lval_memory);
-      else
-	{
-	  struct value *temp = arg1;
-
-	  return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
-				   NULL, "structure");
-	}
+      return value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
+			       NULL, "structure");
 
     case STRUCTOP_PTR:
       tem = longest_to_int (exp->elts[pc + 1].longconst);
@@ -1911,18 +1901,8 @@ evaluate_subexp_standard (struct type *expect_type,
           }
       }
 
-      if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (lookup_struct_elt_type (value_type (arg1),
-						   &exp->elts[pc + 2].string,
-						   0),
-			   lval_memory);
-      else
-	{
-	  struct value *temp = arg1;
-
-	  return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
-				   NULL, "structure pointer");
-	}
+      return value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
+			       NULL, "structure pointer");
 
     case STRUCTOP_MEMBER:
     case STRUCTOP_MPTR:
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 01e02c8..e405101 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -943,15 +943,9 @@ Cannot perform conditional operation on vectors with different sizes"));
 	  }
 	else
 	  {
-	    if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	      return
-		  value_zero (lookup_struct_elt_type
-			      (value_type (arg1),&exp->elts[pc + 2].string, 0),
-			      lval_memory);
-	    else
-	      return value_struct_elt (&arg1, NULL,
-				       &exp->elts[pc + 2].string, NULL,
-				       "structure");
+	    return value_struct_elt (&arg1, NULL,
+				     &exp->elts[pc + 2].string, NULL,
+				     "structure");
 	  }
       }
     default:
diff --git a/gdb/testsuite/gdb.cp/m-static.exp b/gdb/testsuite/gdb.cp/m-static.exp
index ae4b2ad..4dce778 100644
--- a/gdb/testsuite/gdb.cp/m-static.exp
+++ b/gdb/testsuite/gdb.cp/m-static.exp
@@ -64,6 +64,16 @@ gdb_test "print test1.key2" "\\$\[0-9\]* = 77" "simple object, static long"
 # simple object, static enum
 gdb_test "print test1.value" "\\$\[0-9\]* = oriental" "simple object, static enum"
 
+gdb_test "print test1.gnu_obj_1" \
+    { = {void \(gnu_obj_1 \* const, gnu_obj_1::antiquities, long\)} 0x[0-9a-f]+ <gnu_obj_1::gnu_obj_1\(gnu_obj_1::antiquities, long\)>} \
+    "simple object instance, print constructor"
+gdb_test "ptype test1.gnu_obj_1" \
+    {type = void \(gnu_obj_1 \* const, gnu_obj_1::antiquities, long\)} \
+    "simple object instance, ptype constructor"
+gdb_test "ptype gnu_obj_1::gnu_obj_1" \
+    {type = void \(gnu_obj_1 \* const, gnu_obj_1::antiquities, long\)} \
+    "simple object class, ptype constructor"
+
 gdb_test "print test1.'~gnu_obj_1'" \
     { = {void \(gnu_obj_1 \*( const)?, int\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \
     "simple object instance, print quoted destructor"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]