2010-07-27 Phil Muldoon <pmuldoon@redhat.com>
* python/py-value.c (valpy_call): New Function. 2010-07-27 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-value.exp (test_inferior_function_call): New function. * gdb.python/py-value.c (func1): New function. (func2): Likewise. 2010-07-27 Phil Muldoon <pmuldoon@redhat.com> * gdb.texinfo (Values From Inferior): Add value inferior function call description.
This commit is contained in:
parent
9691462bab
commit
5374244e7a
7 changed files with 126 additions and 1 deletions
|
@ -25,6 +25,7 @@
|
|||
#include "language.h"
|
||||
#include "dfp.h"
|
||||
#include "valprint.h"
|
||||
#include "infcall.h"
|
||||
|
||||
#ifdef HAVE_PYTHON
|
||||
|
||||
|
@ -393,6 +394,53 @@ valpy_setitem (PyObject *self, PyObject *key, PyObject *value)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* Called by the Python interpreter to perform an inferior function
|
||||
call on the value. */
|
||||
static PyObject *
|
||||
valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
|
||||
{
|
||||
struct value *return_value = NULL;
|
||||
Py_ssize_t args_count;
|
||||
volatile struct gdb_exception except;
|
||||
struct value *function = ((value_object *) self)->value;
|
||||
struct value **vargs = NULL;
|
||||
struct type *ftype = check_typedef (value_type (function));
|
||||
|
||||
if (TYPE_CODE (ftype) != TYPE_CODE_FUNC)
|
||||
{
|
||||
PyErr_SetString (PyExc_RuntimeError,
|
||||
_("Value is not callable (not TYPE_CODE_FUNC)."));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
args_count = PyTuple_Size (args);
|
||||
if (args_count > 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
vargs = alloca (sizeof (struct value *) * args_count);
|
||||
for (i = 0; i < args_count; i++)
|
||||
{
|
||||
PyObject *item = PyTuple_GetItem (args, i);
|
||||
|
||||
if (item == NULL)
|
||||
return NULL;
|
||||
|
||||
vargs[i] = convert_value_from_python (item);
|
||||
if (vargs[i] == NULL)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
TRY_CATCH (except, RETURN_MASK_ALL)
|
||||
{
|
||||
return_value = call_function_by_hand (function, args_count, vargs);
|
||||
}
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
|
||||
return value_to_value_object (return_value);
|
||||
}
|
||||
|
||||
/* Called by the Python interpreter to obtain string representation
|
||||
of the object. */
|
||||
static PyObject *
|
||||
|
@ -1151,7 +1199,7 @@ PyTypeObject value_object_type = {
|
|||
0, /*tp_as_sequence*/
|
||||
&value_object_as_mapping, /*tp_as_mapping*/
|
||||
valpy_hash, /*tp_hash*/
|
||||
0, /*tp_call*/
|
||||
valpy_call, /*tp_call*/
|
||||
valpy_str, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue