This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: Python: fetch value when building gdb.Value object [rediff]
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Phil Muldoon <pmuldoon at redhat dot com>
- Cc: Paul Koning <paulkoning at comcast dot net>, gdb-patches at sourceware dot org
- Date: Sat, 1 Oct 2011 14:16:42 +0200
- Subject: Re: Python: fetch value when building gdb.Value object [rediff]
- References: <36B29E9D-F2B3-446F-AF8A-97254A3AAEE2@comcast.net> <m3ipocii6a.fsf@redhat.com> <20111001092852.GB11227@host1.jankratochvil.net>
Updated for current HEAD:
On Sat, 01 Oct 2011 11:28:52 +0200, Jan Kratochvil wrote:
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.
Thanks,
Jan
gdb/
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/
2011-09-21 Paul Koning <paul_koning@dell.com>
Jan Kratochvil <jan.kratochvil@redhat.com>
* 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;
+ 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)
{
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -236,6 +236,18 @@ proc test_value_in_inferior {} {
gdb_test "python print gdb.parse_and_eval('*(int*)0')" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test
}
+ # Test Python values are not lazy.
+ set test "memory error occurs even for possibly lazy values"
+ if {$can_read_0} {
+ untested $test
+ } else {
+ gdb_test "python inval = gdb.parse_and_eval('*(int*)0')" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test
+ }
+ 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\""
gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1