aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@sourceware.org>2012-03-22 08:10:44 +0000
committerSiva Chandra Reddy <sivachandra@sourceware.org>2012-03-22 08:10:44 +0000
commit7b282c5acc13f099b11a670de50fd52a0d81ea40 (patch)
treee5bac62553f4956c81aeeb122242d209be04e978 /gdb/python
parent0c83539f7ebce5901201956bebd1bef925e5c5f4 (diff)
downloadgdb-7b282c5acc13f099b11a670de50fd52a0d81ea40.zip
gdb-7b282c5acc13f099b11a670de50fd52a0d81ea40.tar.gz
gdb-7b282c5acc13f099b11a670de50fd52a0d81ea40.tar.bz2
2012-03-14 Siva Chandra <sivachandra@google.com>
Python scripting: Add new method Value.referenced_value to gdb.Value which can dereference pointer as well as reference values. * NEWS: Add entry under 'Python scripting' about the new method Value.referenced_value on gdb.Value objects. * python/py-value.c (valpy_referenced_value): New function defining a new method on gdb.Value objects which can dereference pointer and reference values. * testsuite/gdb.python/py-value.cc: Add test case for testing the methodology exposing C++ values to Python. * testsuite/gdb.python/py-value-cc.exp: Add tests testing the methodology exposing C++ values to Python. * testsuite/gdb.python/Makefile.in: Add py-value-cc to EXECUTABLES. * docs/gdb.texinfo (Python API/Values From Inferior): Add description about the new method Value.referenced_value. Add description on how Value.dereference is different (and similar) to Value.referenced_value.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-value.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 44443e0..58513d8 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -192,6 +192,47 @@ valpy_dereference (PyObject *self, PyObject *args)
return result;
}
+/* Given a value of a pointer type or a reference type, return the value
+ referenced. The difference between this function and valpy_dereference is
+ that the latter applies * unary operator to a value, which need not always
+ result in the value referenced. For example, for a value which is a reference
+ to an 'int' pointer ('int *'), valpy_dereference will result in a value of
+ type 'int' while valpy_referenced_value will result in a value of type
+ 'int *'. */
+
+static PyObject *
+valpy_referenced_value (PyObject *self, PyObject *args)
+{
+ volatile struct gdb_exception except;
+ PyObject *result = NULL;
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ struct value *self_val, *res_val;
+ struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+
+ self_val = ((value_object *) self)->value;
+ switch (TYPE_CODE (check_typedef (value_type (self_val))))
+ {
+ case TYPE_CODE_PTR:
+ res_val = value_ind (self_val);
+ break;
+ case TYPE_CODE_REF:
+ res_val = coerce_ref (self_val);
+ break;
+ default:
+ error(_("Trying to get the referenced value from a value which is "
+ "neither a pointer nor a reference."));
+ }
+
+ result = value_to_value_object (res_val);
+ do_cleanups (cleanup);
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
+
+ return result;
+}
+
/* Return "&value". */
static PyObject *
valpy_get_address (PyObject *self, void *closure)
@@ -1379,6 +1420,8 @@ Cast the value to the supplied type, as if by the C++\n\
reinterpret_cast operator."
},
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
+ { "referenced_value", valpy_referenced_value, METH_NOARGS,
+ "Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." },
{ "lazy_string", (PyCFunction) valpy_lazy_string,
METH_VARARGS | METH_KEYWORDS,
"lazy_string ([encoding] [, length]) -> lazy_string\n\