diff options
author | sivachandra <sivachandra> | 2012-03-22 08:10:40 +0000 |
---|---|---|
committer | sivachandra <sivachandra> | 2012-03-22 08:10:40 +0000 |
commit | 6b02e7db494f5b445c71de1f59b034854008002b (patch) | |
tree | 11e618d75dc1f93ffd4cfebdf7cf8d30b4fe210e /gdb/python | |
parent | 5371d4e89fdf618acf847a6337a8c91b99c673fa (diff) | |
download | gdb-6b02e7db494f5b445c71de1f59b034854008002b.tar.gz |
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.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 44443e00662..58513d8b0f8 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\ |