Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Python: fetch value when building gdb.Value object
@ 2011-09-21 16:17 Paul Koning
  2011-09-28 19:29 ` Phil Muldoon
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Paul Koning @ 2011-09-21 16:17 UTC (permalink / raw)
  To: gdb-patches

GDB sometimes lazily evaluates operations on values, and py-value.c wasn't taking that into account.  The result was that assigning a Value object to a Python variable could assign a lazy value, so that any errors in accessing the data would occur at a later time, and sometimes would not be handled right.  (For example, the "nonzero" operation would fail without a Python traceback.)

The attached patch cures this by fetching any lazy values when the gdb.Value object is built, and adds a test in the testcases to verify this.

Ok to submit?

	paul

ChangeLog:
	
2011-09-21  Paul Koning  <paul_koning@dell.com>

	* python/py-value.c (valpy_get_address): Use Py_XINCREF.
	(value_to_value_object): Fetch value if it was lazy.

testsuite/ChangeLog:
	
2011-09-21  Paul Koning  <paul_koning@dell.com>

	* gdb.python/py-value.exp: Add test for null pointer reference
	assigned to a variable.

Index: python/py-value.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-value.c,v
retrieving revision 1.25
diff -u -r1.25 py-value.c
--- python/py-value.c	27 Jun 2011 19:21:51 -0000	1.25
+++ python/py-value.c	21 Sep 2011 15:45:12 -0000
@@ -209,7 +209,7 @@
 	val_obj->address = value_to_value_object (res_val);
     }
 
-  Py_INCREF (val_obj->address);
+  Py_XINCREF (val_obj->address);
 
   return val_obj->address;
 }
@@ -1045,7 +1045,15 @@
 value_to_value_object (struct value *val)
 {
   value_object *val_obj;
+  volatile struct gdb_exception except;
 
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      if (value_lazy (val))
+	value_fetch_lazy (val);
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+  
   val_obj = PyObject_New (value_object, &value_object_type);
   if (val_obj != NULL)
     {
Index: testsuite/gdb.python/py-value.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-value.exp,v
retrieving revision 1.22
diff -u -r1.22 py-value.exp
--- testsuite/gdb.python/py-value.exp	26 Jul 2011 18:38:55 -0000	1.22
+++ testsuite/gdb.python/py-value.exp	21 Sep 2011 15:45:13 -0000
@@ -218,6 +218,7 @@
 
   # Test memory error.
   gdb_test "python print gdb.parse_and_eval('*(int*)0')" "gdb.MemoryError: Cannot access memory at address 0x0.*"
+  gdb_test "python inval = gdb.parse_and_eval('*(int*)0')" "gdb.MemoryError: Cannot access memory at address 0x0.*"
 
   # Test string fetches,  both partial and whole.
   gdb_test "print st" "\"divide et impera\""


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2011-10-21 15:51 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-21 16:17 Python: fetch value when building gdb.Value object Paul Koning
2011-09-28 19:29 ` Phil Muldoon
2011-09-28 20:06   ` Paul Koning
2011-10-04 15:43     ` Tom Tromey
2011-09-28 20:42   ` Paul Koning
2011-10-01  9:05     ` Jan Kratochvil
2011-10-03 10:22       ` Phil Muldoon
2011-10-04 15:40       ` Tom Tromey
2011-10-01  9:29   ` Jan Kratochvil
2011-10-01 10:23     ` Pedro Alves
2011-10-01 11:03       ` Jan Kratochvil
2011-10-01 12:17     ` Python: fetch value when building gdb.Value object [rediff] Jan Kratochvil
2011-10-01 18:58       ` Paul Koning
2011-10-03 10:19       ` Phil Muldoon
2011-10-03 16:16         ` Paul Koning
2011-10-01  1:00 ` [PING] [RFA] Re: Python: fetch value when building gdb.Value object Paul Koning
2011-10-04 15:45 ` Tom Tromey
2011-10-04 15:51   ` Paul Koning
2011-10-14 20:03     ` Tom Tromey
2011-10-14 20:30       ` Paul Koning
2011-10-19 20:56         ` Tom Tromey
2011-10-19 20:58           ` Paul Koning
2011-10-20 15:09             ` Tom Tromey
2011-10-21  7:46               ` Paul Koning
2011-10-21 17:13                 ` Tom Tromey
2011-10-14 23:36   ` Jim Blandy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox