diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-07-30 12:56:34 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-09-07 10:54:07 +0100 |
commit | 540bf37b2539923dc70b96eea7cb870522ffd7ec (patch) | |
tree | 8ae12cd4c68badb1f42eee23980e369ef68ed473 /gdb/python | |
parent | 3f1a2892e1fea343880b276474cb44db3abcaa9a (diff) | |
download | gdb-540bf37b2539923dc70b96eea7cb870522ffd7ec.zip gdb-540bf37b2539923dc70b96eea7cb870522ffd7ec.tar.gz gdb-540bf37b2539923dc70b96eea7cb870522ffd7ec.tar.bz2 |
gdb/python: new function to add values into GDB's history
The guile API has (history-append! <value>) to add values into GDB's
history list. There is currently no equivalent in the Python API.
This commit adds gdb.add_history(<value>) to the Python API, this
function takes <value> 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.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-value.c | 27 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 1 | ||||
-rw-r--r-- | gdb/python/python.c | 2 |
3 files changed, 30 insertions, 0 deletions
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) diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 690d2fb..0e140f1 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -412,6 +412,7 @@ extern enum ext_lang_rc gdbpy_get_matching_xmethod_workers PyObject *gdbpy_history (PyObject *self, PyObject *args); +PyObject *gdbpy_add_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 *); diff --git a/gdb/python/python.c b/gdb/python/python.c index e42cbc4..6af9c72 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -2076,6 +2076,8 @@ PyMethodDef python_GdbMethods[] = { { "history", gdbpy_history, METH_VARARGS, "Get a value from history" }, + { "add_history", gdbpy_add_history, METH_VARARGS, + "Add a value to the value history list" }, { "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS, "execute (command [, from_tty] [, to_string]) -> [String]\n\ Evaluate command, a string, as a gdb CLI command. Optionally returns\n\ |