aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Jung Bauermann <bauerman@br.ibm.com>2009-03-29 21:11:11 +0000
committerThiago Jung Bauermann <bauerman@br.ibm.com>2009-03-29 21:11:11 +0000
commitc0c6f77785d5f523f929919b66cf90bcd273a9fe (patch)
treeedc6c9f326c1edbb4823fff90eadeac7bceb9469
parent3cb51905575ddbdc88eee13144b537d222e61cb4 (diff)
downloadgdb-c0c6f77785d5f523f929919b66cf90bcd273a9fe.zip
gdb-c0c6f77785d5f523f929919b66cf90bcd273a9fe.tar.gz
gdb-c0c6f77785d5f523f929919b66cf90bcd273a9fe.tar.bz2
gdb/
Change gdb.Value.address from a method to an attribute. * python/python-value.c (value_object): Add `address' element. (valpy_dealloc): Decrement reference to self->address if set. (valpy_new): Initialize val_obj->address. (valpy_address): Rename to ... (valpy_get_address): ... this. Change signature from method to attribute. Update self->address if not set. (value_to_value_object): Initialize val_obj->address. (value_object_getset): Add `address' element. (value_object_methods): Remove `address' element. gdb/testsuite/ * gdb.python/python-value.exp: Add tests for the address attribute. gdb/doc/ * gdb.texinfo (Values From Inferior): Change gdb.Value.address from a method to an attribute.
-rw-r--r--gdb/ChangeLog13
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo8
-rw-r--r--gdb/python/python-value.c35
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.python/python-value.exp6
6 files changed, 65 insertions, 7 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 226faa0..78db079 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,16 @@
+2009-03-29 Thiago Jung Bauermann <bauerman@br.ibm.com>
+
+ Change gdb.Value.address from a method to an attribute.
+ * python/python-value.c (value_object): Add `address' element.
+ (valpy_dealloc): Decrement reference to self->address if set.
+ (valpy_new): Initialize val_obj->address.
+ (valpy_address): Rename to ...
+ (valpy_get_address): ... this. Change signature from method to
+ attribute. Update self->address if not set.
+ (value_to_value_object): Initialize val_obj->address.
+ (value_object_getset): Add `address' element.
+ (value_object_methods): Remove `address' element.
+
2009-03-29 Andreas Schwab <schwab@linux-m68k.org>
* observer.sh: Set LANG/LC_ALL to C, not c.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index beca846..aa1d564 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2009-03-29 Thiago Jung Bauermann <bauerman@br.ibm.com>
+
+ * gdb.texinfo (Values From Inferior): Change gdb.Value.address
+ from a method to an attribute.
+
2009-03-26 Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.texinfo (Values From Inferior): Document is_optimized_out
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 8db5679..0dff6e0 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18325,9 +18325,15 @@ bar = some_val['foo']
Again, @code{bar} will also be a @code{gdb.Value} object.
-The following attribute is provided:
+The following attributes are provided:
@table @code
+@defmethod Value address
+If this object is addressable, this read-only attribute holds a
+@code{gdb.Value} object representing the address. Otherwise,
+this attribute holds @code{None}.
+@end defmethod
+
@cindex optimized out value in Python
@defmethod Value is_optimized_out
This read-only boolean attribute is true if the compiler optimized out
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index bf07dc4..49b884f 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -59,6 +59,7 @@ typedef struct {
PyObject_HEAD
struct value *value;
int owned_by_gdb;
+ PyObject *address;
} value_object;
/* Called by the Python interpreter when deallocating a value object. */
@@ -71,6 +72,13 @@ valpy_dealloc (PyObject *obj)
if (!self->owned_by_gdb)
value_free (self->value);
+
+ if (self->address)
+ /* Use braces to appease gcc warning. *sigh* */
+ {
+ Py_DECREF (self->address);
+ }
+
self->ob_type->tp_free (self);
}
@@ -105,6 +113,7 @@ valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
value_obj->value = value;
value_obj->owned_by_gdb = 0;
+ value_obj->address = NULL;
release_value (value);
value_prepend_to_list (&values_in_python, value);
@@ -129,18 +138,30 @@ valpy_dereference (PyObject *self, PyObject *args)
/* Return "&value". */
static PyObject *
-valpy_address (PyObject *self, PyObject *args)
+valpy_get_address (PyObject *self, void *closure)
{
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
+ value_object *val_obj = (value_object *) self;
volatile struct gdb_exception except;
- TRY_CATCH (except, RETURN_MASK_ALL)
+ if (!val_obj->address)
{
- res_val = value_addr (((value_object *) self)->value);
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ res_val = value_addr (val_obj->value);
+ }
+ if (except.reason < 0)
+ {
+ val_obj->address = Py_None;
+ Py_INCREF (Py_None);
+ }
+ else
+ val_obj->address = value_to_value_object (res_val);
}
- GDB_PY_HANDLE_EXCEPTION (except);
- return value_to_value_object (res_val);
+ Py_INCREF (val_obj->address);
+
+ return val_obj->address;
}
/* Implementation of gdb.Value.string ([encoding] [, errors]) -> string
@@ -726,6 +747,7 @@ value_to_value_object (struct value *val)
{
val_obj->value = val;
val_obj->owned_by_gdb = 0;
+ val_obj->address = NULL;
release_value (val);
value_prepend_to_list (&values_in_python, val);
}
@@ -838,6 +860,8 @@ gdbpy_initialize_values (void)
}
static PyGetSetDef value_object_getset[] = {
+ { "address", valpy_get_address, NULL, "The address of the value.",
+ NULL },
{ "is_optimized_out", valpy_get_is_optimized_out, NULL,
"Boolean telling whether the value is optimized out (i.e., not available).",
NULL },
@@ -845,7 +869,6 @@ static PyGetSetDef value_object_getset[] = {
};
static PyMethodDef value_object_methods[] = {
- { "address", valpy_address, METH_NOARGS, "Return the address of the value." },
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
{ "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
"string ([encoding] [, errors]) -> string\n\
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index e30eeab..c9eca11 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2009-03-29 Thiago Jung Bauermann <bauerman@br.ibm.com>
+
+ * gdb.python/python-value.exp: Add tests for the address
+ attribute.
+
2009-03-29 Andreas Schwab <schwab@linux-m68k.org>
* gdb.arch/powerpc-prologue.exp: Update for disassemble-next-line.
diff --git a/gdb/testsuite/gdb.python/python-value.exp b/gdb/testsuite/gdb.python/python-value.exp
index 2d1ece6..b3b5746 100644
--- a/gdb/testsuite/gdb.python/python-value.exp
+++ b/gdb/testsuite/gdb.python/python-value.exp
@@ -70,6 +70,9 @@ proc test_value_creation {} {
gdb_py_test_silent_cmd "python a = gdb.Value (u'unicode test')" "create unicode value" 1
gdb_test "python print a" "\"unicode test\"" "print Unicode string"
gdb_test "python print a.__class__" "<type 'gdb.Value'>" "verify type of unicode string"
+
+ # Test address attribute is None in a non-addressable value
+ gdb_test "python print 'result =', i.address" "= None" "Test address attribute in non-addressable value"
}
proc test_value_numeric_ops {} {
@@ -228,6 +231,9 @@ proc test_value_in_inferior {} {
# Smoke-test is_optimized_out attribute
gdb_test "python print 'result =', arg0.is_optimized_out" "= False" "Test is_optimized_out attribute"
+
+ # Test address attribute
+ gdb_test "python print 'result =', arg0.address" "= 0x\[\[:xdigit:\]\]+" "Test address attribute"
}