This is the mail archive of the 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]

Re: Python: fetch value when building gdb.Value object

On Wed, 28 Sep 2011 21:24:45 +0200, Phil Muldoon wrote:
> What scenario will this test catch that the previous test won't?  I'm
> not saying you are incorrect, I just don't understand. What
> error-trigger does the assignment to "inval" trigger?

I would prefer here a testcase more clearly showing the bug, attached below.

I believe the patch is right, as Phil hasn't yet agreed posting it only.


2011-09-21  Paul Koning  <>

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

2011-09-21  Paul Koning  <>
	    Jan Kratochvil  <>

	* gdb.python/py-value.exp
	(python inval = gdb.parse_and_eval('*(int*)0'))
	(python argc_lazy = gdb.parse_and_eval('argc'), sanity check argc)
	(set argc=2, python print argc_lazy): New tests.

--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -209,7 +209,7 @@ valpy_get_address (PyObject *self, void *closure)
 	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 @@ PyObject *
 value_to_value_object (struct value *val)
   value_object *val_obj;
+  volatile struct gdb_exception except;
+    {
+      if (value_lazy (val))
+	value_fetch_lazy (val);
+    }
   val_obj = PyObject_New (value_object, &value_object_type);
   if (val_obj != NULL)
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -218,6 +218,11 @@ proc test_value_in_inferior {} {
   # 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.*"
+  gdb_test "python argc_lazy = gdb.parse_and_eval('argc')"
+  gdb_test "print argc" " = 1" "sanity check argc"
+  gdb_test_no_output "set argc=2"
+  gdb_test "python print argc_lazy" "\r\n1"
   # Test string fetches,  both partial and whole.
   gdb_test "print st" "\"divide et impera\""

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