diff options
author | Tom Tromey <tromey@redhat.com> | 2010-08-23 20:29:19 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2010-08-23 20:29:19 +0000 |
commit | f9ffd4bb11c401df4c0c5733e946c48d6b295c5e (patch) | |
tree | e703cf5f4d37e888044a224d8b4a2ce06118e5da /gdb/python | |
parent | 9919d93bc70b0ed9bb5991bcf46e4c3ffaa0a3ce (diff) | |
download | fsf-binutils-gdb-f9ffd4bb11c401df4c0c5733e946c48d6b295c5e.zip fsf-binutils-gdb-f9ffd4bb11c401df4c0c5733e946c48d6b295c5e.tar.gz fsf-binutils-gdb-f9ffd4bb11c401df4c0c5733e946c48d6b295c5e.tar.bz2 |
gdb
PR python/11145:
* python/py-value.c: Include expression.h.
(valpy_do_cast): New function.
(valpy_cast): Use it.
(valpy_dynamic_cast): New function.
(valpy_reinterpret_cast): Likewise.
(value_object_methods): Add dynamic_cast, reinterpret_cast.
gdb/doc
PR python/11145:
* gdb.texinfo (Values From Inferior): Document dynamic_cast and
reinterpret_cast methods.
gdb/testsuite
PR python/11145:
* gdb.python/py-value.c (Base, Derived): New types.
(base): New global.
* gdb.python/py-value.exp (test_subscript_regression): Add
dynamic_cast test.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-value.c | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 75ee0de..aa18042 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -26,6 +26,7 @@ #include "dfp.h" #include "valprint.h" #include "infcall.h" +#include "expression.h" #ifdef HAVE_PYTHON @@ -295,9 +296,10 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw) return unicode; } -/* Cast a value to a given type. */ +/* A helper function that implements the various cast operators. */ + static PyObject * -valpy_cast (PyObject *self, PyObject *args) +valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op) { PyObject *type_obj; struct type *type; @@ -317,13 +319,47 @@ valpy_cast (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - res_val = value_cast (type, ((value_object *) self)->value); + struct value *val = ((value_object *) self)->value; + + if (op == UNOP_DYNAMIC_CAST) + res_val = value_dynamic_cast (type, val); + else if (op == UNOP_REINTERPRET_CAST) + res_val = value_reinterpret_cast (type, val); + else + { + gdb_assert (op == UNOP_CAST); + res_val = value_cast (type, val); + } } GDB_PY_HANDLE_EXCEPTION (except); return value_to_value_object (res_val); } +/* Implementation of the "cast" method. */ + +static PyObject * +valpy_cast (PyObject *self, PyObject *args) +{ + return valpy_do_cast (self, args, UNOP_CAST); +} + +/* Implementation of the "dynamic_cast" method. */ + +static PyObject * +valpy_dynamic_cast (PyObject *self, PyObject *args) +{ + return valpy_do_cast (self, args, UNOP_DYNAMIC_CAST); +} + +/* Implementation of the "reinterpret_cast" method. */ + +static PyObject * +valpy_reinterpret_cast (PyObject *self, PyObject *args) +{ + return valpy_do_cast (self, args, UNOP_REINTERPRET_CAST); +} + static Py_ssize_t valpy_length (PyObject *self) { @@ -1138,6 +1174,15 @@ static PyGetSetDef value_object_getset[] = { static PyMethodDef value_object_methods[] = { { "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." }, + { "dynamic_cast", valpy_dynamic_cast, METH_VARARGS, + "dynamic_cast (gdb.Type) -> gdb.Value\n\ +Cast the value to the supplied type, as if by the C++ dynamic_cast operator." + }, + { "reinterpret_cast", valpy_reinterpret_cast, METH_VARARGS, + "reinterpret_cast (gdb.Type) -> gdb.Value\n\ +Cast the value to the supplied type, as if by the C++\n\ +reinterpret_cast operator." + }, { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." }, { "lazy_string", (PyCFunction) valpy_lazy_string, METH_VARARGS | METH_KEYWORDS, "lazy_string ([encoding] [, length]) -> lazy_string\n\ |