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]

FYI: fix BINOP_SUBSCRIPT with pieced arrays


I'm checking this in after my previous patch goes in.

This fixes the second case in

    https://bugzilla.redhat.com/show_bug.cgi?id=589467

The bug here is that we can create a pieced array and print the entire
array, but printing an element of the array causes an error:

    (gdb) p a
    $4 = {4, 14}
    (gdb) p a[0]
    Can't take address of "a" which isn't an lvalue.
    (gdb) p a[1]
    Can't take address of "a" which isn't an lvalue.

The fix is to change BINOP_SUBSCRIPT handling in eval.c to use
evaluate_subexp rather than evaluate_subexp_with_coercion.
This lets us properly handle a pieced array.

I verified by hand that this does not cause over-eager array reading,
which is the concern expressed in evaluate_subexp_with_coercion.

Built and regtested on x86-64 (compile farm).
I updated pieces.exp to add a new test.

Tom

2010-05-13  Tom Tromey  <tromey@redhat.com>

	* eval.c (evaluate_subexp_standard) <BINOP_SUBSCRIPT>: Call
	evaluate_subexp, not evaluate_subexp_with_coercion.

2010-05-13  Tom Tromey  <tromey@redhat.com>

	* gdb.dwarf2/pieces.exp (pieces_test_f2): New proc.
	Call it.

diff --git a/gdb/eval.c b/gdb/eval.c
index 985e653..c416cbf 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2031,8 +2031,8 @@ evaluate_subexp_standard (struct type *expect_type,
       error (_("':' operator used in invalid context"));
 
     case BINOP_SUBSCRIPT:
-      arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
-      arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
+      arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
+      arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
       if (noside == EVAL_SKIP)
 	goto nosideret;
       if (binop_user_defined_p (op, arg1, arg2))
diff --git a/gdb/testsuite/gdb.dwarf2/pieces.exp b/gdb/testsuite/gdb.dwarf2/pieces.exp
index 85ca23e..e6c1431 100644
--- a/gdb/testsuite/gdb.dwarf2/pieces.exp
+++ b/gdb/testsuite/gdb.dwarf2/pieces.exp
@@ -57,4 +57,16 @@ proc pieces_test_f1 {} {
     gdb_test "print a.j" " = 14" "print a.j in pieces:f1"
 }
 
+# Function f2 tests for a bug when indexing into an array created
+# using DW_OP_piece.
+proc pieces_test_f2 {} {
+    gdb_test "break pieces.c:33" "Breakpoint 3.*" \
+       "set second breakpoint for pieces"
+    gdb_continue_to_breakpoint "second continue to breakpoint for pieces"
+    gdb_test "print a" " = .4, 14." "print a in pieces:f2"
+    gdb_test "print a\[0\]" " = 4" "print a\[0\] in pieces:f2"
+    gdb_test "print a\[1\]" " = 14" "print a\[1\] in pieces:f2"
+}
+
 pieces_test_f1
+pieces_test_f2


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