aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2010-07-27 12:40:42 +0000
committerPhil Muldoon <pmuldoon@redhat.com>2010-07-27 12:40:42 +0000
commit5374244e7a2a4849211f94c40762cde79ba1e08e (patch)
tree1ee569b5fced183515e76d8fd490c830f824b14a /gdb/python
parent9691462bab74c130fe4fdfd5b755b1bd89e1444c (diff)
downloadgdb-5374244e7a2a4849211f94c40762cde79ba1e08e.zip
gdb-5374244e7a2a4849211f94c40762cde79ba1e08e.tar.gz
gdb-5374244e7a2a4849211f94c40762cde79ba1e08e.tar.bz2
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')
-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 2024021..d547ed1 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*/