[PATCH] [python] Add gdb.value_history_count()
Matt McCormick
matt@mmmccormick.com
Wed Dec 30 17:17:00 GMT 2009
An example use cause is trying to log related data with a pretty-printer. For
example, save a file with the same name as the current history number.
This patch revision contains fixes suggested by Phil Muldoon. And actually
strip the 'gdb/' path prefix in the ChangeLog this time.
gdb/ChangeLog
2009-30-12 Matt McCormick <matt@mmmccormick.com>
* value.c (get_value_history_count): New function.
* value.h: Likewise.
* python/py-value.c (gdbpy_value_history_count): New function.
* python/python.c (GdbMethods): Register in module methods.
* python/python-internal.h: Python extension definition.
gdb/doc/ChangeLog
2009-30-12 Matt McCormick <matt@mmmccormick.com>
* doc/gdb.texinfo (Basic Python): Document gdb.value_history_count.
gdb/testsuite/ChangeLog
2009-30-12 Matt McCormick <matt@mmmccormick.com>
* testsuite/gdb.python/py-value.exp (test_value_history_count): Test
gdb.value_history_count.
---
gdb/doc/gdb.texinfo | 6 ++++++
gdb/python/py-value.c | 7 +++++++
gdb/python/python-internal.h | 1 +
gdb/python/python.c | 5 +++++
gdb/testsuite/gdb.python/py-value.exp | 17 +++++++++++++++++
gdb/value.c | 6 ++++++
gdb/value.h | 4 ++++
7 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 18ffb09..fe08630 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18932,6 +18932,12 @@ If no exception is raised, the return value is always an instance of
@code{gdb.Value} (@pxref{Values From Inferior}).
@end defun
+@findex gdb.value_history_count
+@defun value_history_count
+Return an int corresponding to the number of entries in the value history
+(@pxref{Value History}).
+@end defun
+
@findex gdb.parse_and_eval
@defun parse_and_eval expression
Parse @var{expression} as an expression in the current language,
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 14efd79..1d185e7 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -403,6 +403,13 @@ valpy_get_is_optimized_out (PyObject *self, void *closure)
Py_RETURN_FALSE;
}
+/* Implementation of gdb.value_history_count. */
+PyObject *
+gdbpy_value_history_count (PyObject *self, PyObject *args)
+{
+ return PyInt_FromLong ((long) get_value_history_count());
+}
+
enum valpy_opcode
{
VALPY_ADD,
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 47662d9..8056ba8 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -93,6 +93,7 @@ PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
+PyObject *gdbpy_value_history_count (PyObject *self, PyObject* args);
PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 707b700..debf189 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1007,6 +1007,11 @@ Return a string explaining unwind stop reason." },
"lookup_type (name [, block]) -> type\n\
Return a Type corresponding to the given name." },
+ { "value_history_count", (PyCFunction) gdbpy_value_history_count,
+ METH_VARARGS,
+ "value_history_count () -> int.\n\
+Return an int corresponding to the number of entries in the value history." },
+
{ "lookup_symbol", (PyCFunction) gdbpy_lookup_symbol,
METH_VARARGS | METH_KEYWORDS,
"lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
index b9f2c3c..2fd7ddd 100644
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -265,6 +265,22 @@ proc test_objfiles {} {
"pretty_printers attribute must be a list.*Error while executing Python code."
}
+# Test the python interface to the value history count.
+proc test_value_history_count {} {
+ global srcdir subdir binfile
+
+ # Start with a fresh gdb so we have a fresh value history count..
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ gdb_test "print 1" " = 1"
+ gdb_test "print 2" " = 2"
+ gdb_test "print 3" " = 3"
+ gdb_test "python print gdb.value_history_count()" "3"
+}
+
proc test_value_after_death {} {
# Construct a type while the inferior is still running.
gdb_py_test_silent_cmd "python ptrtype = gdb.lookup_type('PTR')" \
@@ -397,6 +413,7 @@ test_value_numeric_ops
test_value_boolean
test_value_compare
test_objfiles
+test_value_history_count
# The following tests require execution.
diff --git a/gdb/value.c b/gdb/value.c
index 2f31185..1e906ff 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -343,6 +343,12 @@ allocate_computed_value (struct type *type,
/* Accessor methods. */
+int
+get_value_history_count ()
+{
+ return value_history_count;
+}
+
struct value *
value_next (struct value *value)
{
diff --git a/gdb/value.h b/gdb/value.h
index 0da7031..8d51821 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -48,6 +48,10 @@ struct value;
struct value *value_next (struct value *);
+/* This returns the number of entries in the value history. */
+
+int get_value_history_count();
+
/* Type of the value. */
extern struct type *value_type (struct value *);
--
1.6.6
More information about the Archer
mailing list