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]

[patch] Fix crash on lval_computed value_zero/value_one


Hi,

GDB can crash on computations with lval_computed values dereferencing NULL
struct lval_funcs vector.

Sure it could be abstracted more, currently it for example does:
(gdb) p a
$1 = (struct S *) <synthetic pointer>
(gdb) ptype &a[0]
Attempt to take address of value not located in memory.

Instead of reassembling new <synthetic pointer>.  But I believe it would
require struct lval_funcs extensions and this fix is good enough now.

No regressions on {x86_64,x86_64-m32,i686}-fedora16pre-linux-gnu.
I will check it in in some time.


Thanks,
Jan


gdb/
2011-07-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix crash on lval_computed values.
	* valops.c (value_zero, value_one): Use not_lval for lval_computed.

gdb/testsuite/
2011-07-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix crash on lval_computed values.
	* gdb.dwarf2/implptr.exp (print sizeof (j[0])): New test.

--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -860,7 +860,7 @@ value_zero (struct type *type, enum lval_type lv)
 {
   struct value *val = allocate_value (type);
 
-  VALUE_LVAL (val) = lv;
+  VALUE_LVAL (val) = (lv == lval_computed ? not_lval : lv);
   return val;
 }
 
@@ -911,7 +911,7 @@ value_one (struct type *type, enum lval_type lv)
       error (_("Not a numeric type."));
     }
 
-  VALUE_LVAL (val) = lv;
+  VALUE_LVAL (val) = (lv == lval_computed ? not_lval : lv);
   return val;
 }
 
--- a/gdb/testsuite/gdb.dwarf2/implptr.exp
+++ b/gdb/testsuite/gdb.dwarf2/implptr.exp
@@ -55,6 +55,7 @@ proc implptr_test_bar {} {
        "set bar breakpoint for implptr"
     gdb_continue_to_breakpoint "continue to bar breakpoint for implptr"
     gdb_test "print j" " = \\(intp\\) <synthetic pointer>" "print j in implptr:bar"
+    gdb_test {print sizeof (j[0])} " = 4" {print sizeof (j[0]) in implptr:bar}
     gdb_test "print *j" " = 5" "print *j in implptr:bar"
     gdb_test "print **k" " = 5" "print **k in implptr:bar"
     gdb_test "print ***l" " = 5" "print ***l in implptr:bar"


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