mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-31 18:20:12 +08:00
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.
This commit is contained in:
@ -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)
|
||||
|
@ -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 *);
|
||||
|
@ -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\
|
||||
|
Reference in New Issue
Block a user