aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-01-24 15:19:43 +0000
committerAndrew Burgess <aburgess@redhat.com>2022-01-26 21:58:12 +0000
commit30a87e90be195dcce555a0904cc5dbd960349271 (patch)
tree0d2c98c5a8416afabe6a39e141928b1fb15d0a56 /gdb/python
parent51d185a65f3679f887d456e20d22475ac8586938 (diff)
downloadbinutils-30a87e90be195dcce555a0904cc5dbd960349271.zip
binutils-30a87e90be195dcce555a0904cc5dbd960349271.tar.gz
binutils-30a87e90be195dcce555a0904cc5dbd960349271.tar.bz2
gdb/python: add gdb.history_count function
Add a new function gdb.history_count to the Python api, this function returns an integer, the number of items in GDB's value history. This is useful if you want to pull items from the history by their absolute number, for example, if you wanted to show a complete history list. Previously we could figure out how many items are in the history list by trying to fetch the items, and then catching the exception when the item is not available, but having this function seems nicer.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-value.c8
-rw-r--r--gdb/python/python-internal.h1
-rw-r--r--gdb/python/python.c2
3 files changed, 11 insertions, 0 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index d6ceb54..6401d96 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -2012,6 +2012,14 @@ gdbpy_add_history (PyObject *self, PyObject *args)
return nullptr;
}
+/* Return an integer, the number of items in GDB's history. */
+
+PyObject *
+gdbpy_history_count (PyObject *self, PyObject *args)
+{
+ return gdb_py_object_from_ulongest (value_history_count ()).release ();
+}
+
/* 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 ccea5c4..5e15f62 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);
+extern PyObject *gdbpy_history_count (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 7ddc170..2c8081e 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -2212,6 +2212,8 @@ PyMethodDef python_GdbMethods[] =
"Get a value from history" },
{ "add_history", gdbpy_add_history, METH_VARARGS,
"Add a value to the value history list" },
+ { "history_count", gdbpy_history_count, METH_NOARGS,
+ "Return an integer, the number of values in GDB's value history" },
{ "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\