summaryrefslogtreecommitdiff
path: root/gdb/python/py-value.c
diff options
context:
space:
mode:
authorpmuldoon <pmuldoon>2010-07-27 12:40:40 +0000
committerpmuldoon <pmuldoon>2010-07-27 12:40:40 +0000
commit457b1d1e76ca6ed6b78183c1401de7043dd239cd (patch)
treedd40f1fb33f76047710bdc5d09df93af6073a85a /gdb/python/py-value.c
parent326905fb03804adfdece491aeaa1de2fc8eedbc6 (diff)
downloadgdb-457b1d1e76ca6ed6b78183c1401de7043dd239cd.tar.gz
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.
Diffstat (limited to 'gdb/python/py-value.c')
-rw-r--r--gdb/python/py-value.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 2024021ac11..d547ed1b172 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -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*/