From 540bf37b2539923dc70b96eea7cb870522ffd7ec Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Fri, 30 Jul 2021 12:56:34 +0100 Subject: gdb/python: new function to add values into GDB's history The guile API has (history-append! ) to add values into GDB's history list. There is currently no equivalent in the Python API. This commit adds gdb.add_history() to the Python API, this function takes a gdb.Value (or anything that can be passed to the constructor of gdb.Value), and adds the value it represents to GDB's history list. The index of the newly added value is returned. --- gdb/python/py-value.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gdb/python/py-value.c') diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 8df8a15..26d5940 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1960,6 +1960,33 @@ gdbpy_history (PyObject *self, PyObject *args) return value_to_value_object (res_val); } +/* Add a gdb.Value into GDB's history, and return (as an integer) the + position of the newly added value. */ +PyObject * +gdbpy_add_history (PyObject *self, PyObject *args) +{ + PyObject *value_obj; + + if (!PyArg_ParseTuple (args, "O", &value_obj)) + return nullptr; + + struct value *value = convert_value_from_python (value_obj); + if (value == nullptr) + return nullptr; + + try + { + int idx = record_latest_value (value); + return gdb_py_object_from_longest (idx).release (); + } + catch (const gdb_exception &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + + return nullptr; +} + /* Return the value of a convenience variable. */ PyObject * gdbpy_convenience_variable (PyObject *self, PyObject *args) -- cgit v1.1