aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/python.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2009-12-03 18:30:02 +0000
committerTom Tromey <tromey@redhat.com>2009-12-03 18:30:02 +0000
commit57a1d736959fb92e39abab59511a903b7ec59547 (patch)
tree5ec223f0d33bfe64a7583c5993325705b1fad1cc /gdb/python/python.c
parentfb169834478e0db3ffe865300c0cf4556160c7bd (diff)
downloadgdb-57a1d736959fb92e39abab59511a903b7ec59547.zip
gdb-57a1d736959fb92e39abab59511a903b7ec59547.tar.gz
gdb-57a1d736959fb92e39abab59511a903b7ec59547.tar.bz2
gdb
* python/python.c (gdbpy_parse_and_eval): New function. (GdbMethods): Add "parse_and_eval". gdb/testsuite * gdb.python/py-value.exp (test_parse_and_eval): New function. gdb/doc * gdb.texinfo (Basic Python): Document gdb.parse_and_eval.
Diffstat (limited to 'gdb/python/python.c')
-rw-r--r--gdb/python/python.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 77a0069..23e94a5 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -323,6 +323,26 @@ execute_gdb_command (PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+/* Parse a string and evaluate it as an expression. */
+static PyObject *
+gdbpy_parse_and_eval (PyObject *self, PyObject *args)
+{
+ char *expr_str;
+ struct value *result = NULL;
+ volatile struct gdb_exception except;
+
+ if (!PyArg_ParseTuple (args, "s", &expr_str))
+ return NULL;
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ result = parse_and_eval (expr_str);
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
+
+ return value_to_value_object (result);
+}
+
/* Printing. */
@@ -680,6 +700,11 @@ Return a string explaining unwind stop reason." },
"lookup_type (name [, block]) -> type\n\
Return a Type corresponding to the given name." },
+ { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
+ "parse_and_eval (String) -> Value.\n\
+Parse String as an expression, evaluate it, and return the result as a Value."
+ },
+
{ "write", gdbpy_write, METH_VARARGS,
"Write a string using gdb's filtered stream." },
{ "flush", gdbpy_flush, METH_NOARGS,