[Python] Add methods reference_value and const_value to gdb.Value.
gdb/ChangeLog: * NEWS (Python Scripting): Mention the new gdb.Value methods. * python/py-value.c (valpy_reference_value): New function. (valpy_const_value): Likewise. (value_object_methods): Add new methods. * value.c (make_cv_value): New function. * value.h (make_cv_value): Declare. gdb/doc/ChangeLog: * python.texi (Values From Inferior): Add descriptions of new methods gdb.Value.reference_value and gdb.Value.const_value. gdb/testsuite/ChangeLog: * gdb.python/py-xmethods.cc: Enhance test case. * gdb.python/py-xmethods.exp: New tests. * gdb.python/py-xmethods.py (A_indexoper): New xmethod worker function. (B_indexoper): Likewise. (global_dm_list) : Add new xmethod worker functions.
This commit is contained in:
parent
10a52f094e
commit
4c082a81df
11 changed files with 135 additions and 1 deletions
|
@ -236,6 +236,59 @@ valpy_referenced_value (PyObject *self, PyObject *args)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* Return a value which is a reference to the value. */
|
||||
|
||||
static PyObject *
|
||||
valpy_reference_value (PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *result = NULL;
|
||||
|
||||
TRY
|
||||
{
|
||||
struct value *self_val;
|
||||
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
||||
|
||||
self_val = ((value_object *) self)->value;
|
||||
result = value_to_value_object (value_ref (self_val));
|
||||
|
||||
do_cleanups (cleanup);
|
||||
}
|
||||
CATCH (except, RETURN_MASK_ALL)
|
||||
{
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
}
|
||||
END_CATCH
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Return a "const" qualified version of the value. */
|
||||
|
||||
static PyObject *
|
||||
valpy_const_value (PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *result = NULL;
|
||||
|
||||
TRY
|
||||
{
|
||||
struct value *self_val, *res_val;
|
||||
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
||||
|
||||
self_val = ((value_object *) self)->value;
|
||||
res_val = make_cv_value (1, 0, self_val);
|
||||
result = value_to_value_object (res_val);
|
||||
|
||||
do_cleanups (cleanup);
|
||||
}
|
||||
CATCH (except, RETURN_MASK_ALL)
|
||||
{
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
}
|
||||
END_CATCH
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Return "&value". */
|
||||
static PyObject *
|
||||
valpy_get_address (PyObject *self, void *closure)
|
||||
|
@ -1692,6 +1745,10 @@ 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." },
|
||||
{ "reference_value", valpy_reference_value, METH_NOARGS,
|
||||
"Return a value of type TYPE_CODE_REF referencing this value." },
|
||||
{ "const_value", valpy_const_value, METH_NOARGS,
|
||||
"Return a 'const' qualied version of the same value." },
|
||||
{ "lazy_string", (PyCFunction) valpy_lazy_string,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
"lazy_string ([encoding] [, length]) -> lazy_string\n\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue