diff options
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-value.c | 77 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 2 | ||||
-rw-r--r-- | gdb/python/python.c | 8 |
3 files changed, 87 insertions, 0 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index bba6d0b..30a0082 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1746,6 +1746,83 @@ gdbpy_history (PyObject *self, PyObject *args) return value_to_value_object (res_val); } +/* Return the value of a convenience variable. */ +PyObject * +gdbpy_convenience_variable (PyObject *self, PyObject *args) +{ + const char *varname; + struct value *res_val = NULL; + + if (!PyArg_ParseTuple (args, "s", &varname)) + return NULL; + + TRY + { + struct internalvar *var = lookup_only_internalvar (varname); + + if (var != NULL) + { + res_val = value_of_internalvar (python_gdbarch, var); + if (TYPE_CODE (value_type (res_val)) == TYPE_CODE_VOID) + res_val = NULL; + } + } + CATCH (except, RETURN_MASK_ALL) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + END_CATCH + + if (res_val == NULL) + Py_RETURN_NONE; + + return value_to_value_object (res_val); +} + +/* Set the value of a convenience variable. */ +PyObject * +gdbpy_set_convenience_variable (PyObject *self, PyObject *args) +{ + const char *varname; + PyObject *value_obj; + struct value *value = NULL; + + if (!PyArg_ParseTuple (args, "sO", &varname, &value_obj)) + return NULL; + + /* None means to clear the variable. */ + if (value_obj != Py_None) + { + value = convert_value_from_python (value_obj); + if (value == NULL) + return NULL; + } + + TRY + { + if (value == NULL) + { + struct internalvar *var = lookup_only_internalvar (varname); + + if (var != NULL) + clear_internalvar (var); + } + else + { + struct internalvar *var = lookup_internalvar (varname); + + set_internalvar (var, value); + } + } + CATCH (except, RETURN_MASK_ALL) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + END_CATCH + + Py_RETURN_NONE; +} + /* Returns 1 in OBJ is a gdb.Value object, 0 otherwise. */ int diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 26400f4..495655e 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -477,6 +477,8 @@ extern enum ext_lang_rc gdbpy_get_matching_xmethod_workers PyObject *gdbpy_history (PyObject *self, PyObject *args); +PyObject *gdbpy_convenience_variable (PyObject *self, PyObject *args); +PyObject *gdbpy_set_convenience_variable (PyObject *self, PyObject *args); PyObject *gdbpy_breakpoints (PyObject *, PyObject *); PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *); PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw); diff --git a/gdb/python/python.c b/gdb/python/python.c index c29e7d7..1805c90 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -2132,6 +2132,14 @@ Return a tuple containing all inferiors." }, Invalidate any cached frame objects in gdb.\n\ Intended for internal use only." }, + { "convenience_variable", gdbpy_convenience_variable, METH_VARARGS, + "convenience_variable (NAME) -> value.\n\ +Return the value of the convenience variable $NAME,\n\ +or None if not set." }, + { "set_convenience_variable", gdbpy_set_convenience_variable, METH_VARARGS, + "convenience_variable (NAME, VALUE) -> None.\n\ +Set the value of the convenience variable $NAME." }, + {NULL, NULL, 0, NULL} }; |