public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Matt McCormick <matt@mmmccormick.com>
To: archer@sourceware.org
Cc: Matt McCormick <matt@mmmccormick.com>
Subject: [PATCH] [python] Add gdb.value_history_count()
Date: Sun, 17 Jan 2010 19:40:00 -0000	[thread overview]
Message-ID: <1263757180-4438-1-git-send-email-matt@mmmccormick.com> (raw)
In-Reply-To: <1262754692-28749-1-git-send-email-matt@mmmccormick.com>

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.

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>

        * gdb.texinfo (Basic Python): Document gdb.value_history_count.

gdb/testsuite/ChangeLog

2009-30-12  Matt McCormick  <matt@mmmccormick.com>

        * gdb.python/py-value.exp (test_value_history_count): Test
	gdb.value_history_count.
---
This patch has been rebased against archer-tromey python and regression tested.

 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 6d73fc5..1cd7908 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19515,6 +19515,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 2896f7d..4c684bb 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -435,6 +435,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 5230a8c..9d842f4 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -95,6 +95,7 @@ PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
 PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
 PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
 					   const char *encoding, struct type *type);
+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 171cd5b..1154cd3 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1012,6 +1012,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 f87277d..d201f25 100644
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -278,6 +278,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')" \
@@ -422,6 +438,7 @@ test_value_boolean
 test_value_compare
 test_objfiles
 test_parse_and_eval
+test_value_history_count
 
 # The following tests require execution.
 
diff --git a/gdb/value.c b/gdb/value.c
index 1839216..c7141f3 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -350,6 +350,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 eea0cc9..54026ee 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

      reply	other threads:[~2010-01-17 19:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-13 21:22 [PATCH 1/2] " Matt McCormick (thewtex)
2009-12-13 21:22 ` [PATCH 2/2] [python] Document gdb.value_history_count() Matt McCormick (thewtex)
2009-12-15  5:51   ` Matthew McCormick (thewtex)
2009-12-15  5:55     ` [PATCH 1/2] [python] Add gdb.value_history_count() Matt McCormick (thewtex)
2009-12-15  5:55       ` [PATCH 2/2] [python] Document gdb.value_history_count Matt McCormick (thewtex)
     [not found]         ` <4B29F581.1020601@redhat.com>
2009-12-17  9:13           ` Phil Muldoon
2009-12-17  8:59       ` [PATCH 1/2] [python] Add gdb.value_history_count() Phil Muldoon
2009-12-17 14:34         ` Matthew McCormick (thewtex)
2009-12-30 17:06         ` Matthew McCormick (thewtex)
2009-12-30 17:09           ` [PATCH] " Matt McCormick
2009-12-30 17:17             ` Matt McCormick
2010-01-05 14:51               ` Phil Muldoon
2010-01-05 19:49                 ` Tom Tromey
2010-01-06  5:10                 ` Matthew McCormick (thewtex)
2010-01-06  5:11                   ` Matt McCormick
2010-01-17 19:40                     ` Matt McCormick [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1263757180-4438-1-git-send-email-matt@mmmccormick.com \
    --to=matt@mmmccormick.com \
    --cc=archer@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).