public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] [python] Add gdb.value_history_count()
@ 2009-12-13 21:22 Matt McCormick (thewtex)
  2009-12-13 21:22 ` [PATCH 2/2] [python] Document gdb.value_history_count() Matt McCormick (thewtex)
  0 siblings, 1 reply; 16+ messages in thread
From: Matt McCormick (thewtex) @ 2009-12-13 21:22 UTC (permalink / raw)
  To: archer; +Cc: Matt McCormick (thewtex)

From: Matt McCormick (thewtex) <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/python/py-value.c        |    7 +++++++
 gdb/python/python-internal.h |    1 +
 gdb/python/python.c          |    5 +++++
 gdb/value.c                  |    6 ++++++
 gdb/value.h                  |    4 ++++
 5 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 14efd79..17c1aee 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 Py_BuildValue("i", 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/value.c b/gdb/value.c
index 2f31185..a9e8ec3 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..cfe6618 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -48,6 +48,10 @@ struct value;
 
 struct value *value_next (struct value *);
 
+/* Abs number of last entry stored */
+
+int get_value_history_count();
+
 /* Type of the value.  */
 
 extern struct type *value_type (struct value *);
-- 
1.6.5.5

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 2/2] [python] Document gdb.value_history_count()
  2009-12-13 21:22 [PATCH 1/2] [python] Add gdb.value_history_count() Matt McCormick (thewtex)
@ 2009-12-13 21:22 ` Matt McCormick (thewtex)
  2009-12-15  5:51   ` Matthew McCormick (thewtex)
  0 siblings, 1 reply; 16+ messages in thread
From: Matt McCormick (thewtex) @ 2009-12-13 21:22 UTC (permalink / raw)
  To: archer; +Cc: Matt McCormick (thewtex)

From: Matt McCormick (thewtex) <matt@mmmccormick.com>

---
 gdb/doc/gdb.texinfo |    6 ++++++
 1 files changed, 6 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,
-- 
1.6.5.5

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/2] [python] Document gdb.value_history_count()
  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)
  0 siblings, 1 reply; 16+ messages in thread
From: Matthew McCormick (thewtex) @ 2009-12-15  5:51 UTC (permalink / raw)
  To: archer

Will resubmit patches with commit message in gnu ChangeLog format,
since that seems to be the popular thing.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/2] [python] Add gdb.value_history_count()
  2009-12-15  5:51   ` Matthew McCormick (thewtex)
@ 2009-12-15  5:55     ` Matt McCormick (thewtex)
  2009-12-15  5:55       ` [PATCH 2/2] [python] Document gdb.value_history_count Matt McCormick (thewtex)
  2009-12-17  8:59       ` [PATCH 1/2] [python] Add gdb.value_history_count() Phil Muldoon
  0 siblings, 2 replies; 16+ messages in thread
From: Matt McCormick (thewtex) @ 2009-12-15  5:55 UTC (permalink / raw)
  To: archer; +Cc: Matt McCormick (thewtex)

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

	* gdb/python/py-value.c (gdbpy_value_history_count): Implement
	gdb.value_history_count()
	* gdb/python/python-internal.h (thread_object): Python extension
	definition.
	* gdb/python/python.c (GdbMethods): Register in module methods.
	* gdb/value.c (get_value_history_count): New Function.
	* gdb/value.h (get_value_history_count): New Function.
---
 gdb/python/py-value.c        |    7 +++++++
 gdb/python/python-internal.h |    1 +
 gdb/python/python.c          |    5 +++++
 gdb/value.c                  |    6 ++++++
 gdb/value.h                  |    4 ++++
 5 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 14efd79..a607b9a 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 Py_BuildValue("i", 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/value.c b/gdb/value.c
index 2f31185..a9e8ec3 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..cfe6618 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -48,6 +48,10 @@ struct value;
 
 struct value *value_next (struct value *);
 
+/* Abs number of last entry stored */
+
+int get_value_history_count();
+
 /* Type of the value.  */
 
 extern struct type *value_type (struct value *);
-- 
1.6.5.6

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 2/2] [python] Document gdb.value_history_count
  2009-12-15  5:55     ` [PATCH 1/2] [python] Add gdb.value_history_count() Matt McCormick (thewtex)
@ 2009-12-15  5:55       ` Matt McCormick (thewtex)
       [not found]         ` <4B29F581.1020601@redhat.com>
  2009-12-17  8:59       ` [PATCH 1/2] [python] Add gdb.value_history_count() Phil Muldoon
  1 sibling, 1 reply; 16+ messages in thread
From: Matt McCormick (thewtex) @ 2009-12-15  5:55 UTC (permalink / raw)
  To: archer; +Cc: Matt McCormick (thewtex)

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

	* gdb/doc/gdb.texinfo: Document gdb.value_history_count.
---
 gdb/doc/gdb.texinfo |    6 ++++++
 1 files changed, 6 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,
-- 
1.6.5.6

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] [python] Add gdb.value_history_count()
  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)
@ 2009-12-17  8:59       ` Phil Muldoon
  2009-12-17 14:34         ` Matthew McCormick (thewtex)
  2009-12-30 17:06         ` Matthew McCormick (thewtex)
  1 sibling, 2 replies; 16+ messages in thread
From: Phil Muldoon @ 2009-12-17  8:59 UTC (permalink / raw)
  To: Matt McCormick (thewtex); +Cc: archer

On 12/15/2009 05:54 AM, Matt McCormick (thewtex) wrote:

On the whole this looks ok: a few nits from me.  This is not an
official review though, Tom will have to look at it.


> 2009-12-14  Matt McCormick  <matt@mmmccormick.com>
> 
> 	* gdb/python/py-value.c (gdbpy_value_history_count): Implement
> 	gdb.value_history_count()
> 	* gdb/python/python-internal.h (thread_object): Python extension
> 	definition.
> 	* gdb/python/python.c (GdbMethods): Register in module methods.
> 	* gdb/value.c (get_value_history_count): New Function.
> 	* gdb/value.h (get_value_history_count): New Function.


The paths here seem wrong.  For items in the python directory, the
entries belong in the ChangeLog in the src/gdb directory.  It should
read:


2009-12-14  Matt McCormick  <matt@mmmccormick.com>
 
  	* python/py-value.c (gdbpy_value_history_count): Implement
 	gdb.value_history_count()

and so on for all ChangeLog entries.


> +/* Implementation of gdb.value_history_count. */


For FSF C style, two spaces after the period, please.


> +PyObject *
> +gdbpy_value_history_count (PyObject *self, PyObject *args)
> +{
> +  return Py_BuildValue("i", get_value_history_count());
> +}


Similarly a space before '(' in a function.  So:


> +  return Py_BuildValue ("i", get_value_history_count ());


While there is nothing wrong with Py_BuildValue, if it is certain that
the value is a long or an int, why not use PyLong_AsLong or PyInt_AsLong?
I'm purely curious.


>  /* Accessor methods.  */
>  
> +int
> +get_value_history_count()
> +{
> +  return value_history_count;
> +}
> +


Space after '('.


>  
> +/* Abs number of last entry stored */
> +
> +int get_value_history_count();
> +

Comments need to be full sentences, with a period.  Two spaces at the
end please. ;)

Even though this is pretty straight-forward, when I add any
functionality accessible to the user via the API, I like to add a test
to demonstrate it works.  This also helps catch regressions in the
future.  This should be pretty simple to code up. What do you think?

Cheers,

Phil





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/2] [python] Document gdb.value_history_count
       [not found]         ` <4B29F581.1020601@redhat.com>
@ 2009-12-17  9:13           ` Phil Muldoon
  0 siblings, 0 replies; 16+ messages in thread
From: Phil Muldoon @ 2009-12-17  9:13 UTC (permalink / raw)
  To: Matt McCormick (thewtex), Project Archer


Apologies, hit reply instead of reply-all. Reply as forwarded.

On 12/17/2009 09:10 AM, Phil Muldoon wrote:
> On 12/15/2009 05:54 AM, Matt McCormick (thewtex) wrote:
> 
>> 2009-12-14  Matt McCormick  <matt@mmmccormick.com>
>>
>> 	* gdb/doc/gdb.texinfo: Document gdb.value_history_count.
> 
> ChangeLog entries corresponding to documentation patches belong in the
> ChangeLog located in: src/gdb/doc.  Also you need to indicate the
> section the documentation patch is altering.  So I would write the
> entry as:
> 
>> 2009-12-14  Matt McCormick  <matt@mmmccormick.com>
>>
>> 	* gdb.texinfo (Basic Python) : Document gdb.value_history_count.
> 
> 
> Cheers,
> 
> Phil

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] [python] Add gdb.value_history_count()
  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)
  1 sibling, 0 replies; 16+ messages in thread
From: Matthew McCormick (thewtex) @ 2009-12-17 14:34 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: archer

On Thu, Dec 17, 2009 at 2:59 AM, Phil Muldoon <pmuldoon@redhat.com> wrote:
> On 12/15/2009 05:54 AM, Matt McCormick (thewtex) wrote:
>
> On the whole this looks ok: a few nits from me.  This is not an
> official review though, Tom will have to look at it.
>
>
>> 2009-12-14  Matt McCormick  <matt@mmmccormick.com>
>>
>>       * gdb/python/py-value.c (gdbpy_value_history_count): Implement
>>       gdb.value_history_count()
>>       * gdb/python/python-internal.h (thread_object): Python extension
>>       definition.
>>       * gdb/python/python.c (GdbMethods): Register in module methods.
>>       * gdb/value.c (get_value_history_count): New Function.
>>       * gdb/value.h (get_value_history_count): New Function.
>
>
> The paths here seem wrong.  For items in the python directory, the
> entries belong in the ChangeLog in the src/gdb directory.  It should
> read:
>
>
> 2009-12-14  Matt McCormick  <matt@mmmccormick.com>
>
>        * python/py-value.c (gdbpy_value_history_count): Implement
>        gdb.value_history_count()
>
> and so on for all ChangeLog entries.
>
>
>> +/* Implementation of gdb.value_history_count. */
>
>
> For FSF C style, two spaces after the period, please.
>
>
>> +PyObject *
>> +gdbpy_value_history_count (PyObject *self, PyObject *args)
>> +{
>> +  return Py_BuildValue("i", get_value_history_count());
>> +}
>
>
> Similarly a space before '(' in a function.  So:
>
>
>> +  return Py_BuildValue ("i", get_value_history_count ());
>
>
> While there is nothing wrong with Py_BuildValue, if it is certain that
> the value is a long or an int, why not use PyLong_AsLong or PyInt_AsLong?
> I'm purely curious.
>
>
>>  /* Accessor methods.  */
>>
>> +int
>> +get_value_history_count()
>> +{
>> +  return value_history_count;
>> +}
>> +
>
>
> Space after '('.
>
>
>>
>> +/* Abs number of last entry stored */
>> +
>> +int get_value_history_count();
>> +
>
> Comments need to be full sentences, with a period.  Two spaces at the
> end please. ;)
>
> Even though this is pretty straight-forward, when I add any
> functionality accessible to the user via the API, I like to add a test
> to demonstrate it works.  This also helps catch regressions in the
> future.  This should be pretty simple to code up. What do you think?
>
> Cheers,
>
> Phil
>

Thank you very much for the comments.  I'll make the changes and
submit an update.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] [python] Add gdb.value_history_count()
  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
  1 sibling, 1 reply; 16+ messages in thread
From: Matthew McCormick (thewtex) @ 2009-12-30 17:06 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: archer

On Thu, Dec 17, 2009 at 2:59 AM, Phil Muldoon <pmuldoon@redhat.com> wrote:
> On 12/15/2009 05:54 AM, Matt McCormick (thewtex) wrote:
>
> On the whole this looks ok: a few nits from me.  This is not an
> official review though, Tom will have to look at it.
>

Thank you for the comments.  An updated patch will follow.

>
>> 2009-12-14  Matt McCormick  <matt@mmmccormick.com>
>>
>>       * gdb/python/py-value.c (gdbpy_value_history_count): Implement
>>       gdb.value_history_count()
>>       * gdb/python/python-internal.h (thread_object): Python extension
>>       definition.
>>       * gdb/python/python.c (GdbMethods): Register in module methods.
>>       * gdb/value.c (get_value_history_count): New Function.
>>       * gdb/value.h (get_value_history_count): New Function.
>
>
> The paths here seem wrong.  For items in the python directory, the
> entries belong in the ChangeLog in the src/gdb directory.  It should
> read:
>
>
> 2009-12-14  Matt McCormick  <matt@mmmccormick.com>
>
>        * python/py-value.c (gdbpy_value_history_count): Implement
>        gdb.value_history_count()
>
> and so on for all ChangeLog entries.
>

Thank you for the note.  I have looked at the GNU documentation on
ChangeLog's and some of your commits, and I will try to follow their
lead.  I am hacking together a git hook to prototype the commit
message correctly.  If anything else in the future is not as it should
be, let me know.

>
>> +/* Implementation of gdb.value_history_count. */
>
>
> For FSF C style, two spaces after the period, please.
>

ok.

>
>> +PyObject *
>> +gdbpy_value_history_count (PyObject *self, PyObject *args)
>> +{
>> +  return Py_BuildValue("i", get_value_history_count());
>> +}
>
>
> Similarly a space before '(' in a function.  So:
>
>
>> +  return Py_BuildValue ("i", get_value_history_count ());
>

ok.

>
> While there is nothing wrong with Py_BuildValue, if it is certain that
> the value is a long or an int, why not use PyLong_AsLong or PyInt_AsLong?
> I'm purely curious.
>

Good point.  PyInt_AsLong is not appropriate since the argument is not
a PyObject *, but I changed it to

PyInt_FromLong ((long) get_value_history_count());

>
>>  /* Accessor methods.  */
>>
>> +int
>> +get_value_history_count()
>> +{
>> +  return value_history_count;
>> +}
>> +
>
>
> Space after '('.
>

ok.

>
>>
>> +/* Abs number of last entry stored */
>> +
>> +int get_value_history_count();
>> +
>
> Comments need to be full sentences, with a period.  Two spaces at the
> end please. ;)
>

Fixed.

> Even though this is pretty straight-forward, when I add any
> functionality accessible to the user via the API, I like to add a test
> to demonstrate it works.  This also helps catch regressions in the
> future.  This should be pretty simple to code up. What do you think?

I coded a test case and submit that too.

Thanks,
Matt

>
> Cheers,
>
> Phil
>
>
>
>
>
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH] [python] Add gdb.value_history_count()
  2009-12-30 17:06         ` Matthew McCormick (thewtex)
@ 2009-12-30 17:09           ` Matt McCormick
  2009-12-30 17:17             ` Matt McCormick
  0 siblings, 1 reply; 16+ messages in thread
From: Matt McCormick @ 2009-12-30 17:09 UTC (permalink / raw)
  To: archer; +Cc: Matt McCormick

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.

gdb/ChangeLog

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

        * gdb/value.c (get_value_history_count): New function.
        * gdb/value.h: Likewise.
        * gdb/python/py-value.c (gdbpy_value_history_count): New function.
        * gdb/python/python.c (GdbMethods): Register in module methods.
        * gdb/python/python-internal.h: Python extension definition.

gdb/doc/ChangeLog

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

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

gdb/testsuite/ChangeLog

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

        * gdb/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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH] [python] Add gdb.value_history_count()
  2009-12-30 17:09           ` [PATCH] " Matt McCormick
@ 2009-12-30 17:17             ` Matt McCormick
  2010-01-05 14:51               ` Phil Muldoon
  0 siblings, 1 reply; 16+ messages in thread
From: Matt McCormick @ 2009-12-30 17:17 UTC (permalink / raw)
  To: archer; +Cc: Matt McCormick

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] [python] Add gdb.value_history_count()
  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)
  0 siblings, 2 replies; 16+ messages in thread
From: Phil Muldoon @ 2010-01-05 14:51 UTC (permalink / raw)
  To: Matt McCormick; +Cc: archer

On 12/30/2009 05:16 PM, Matt McCormick wrote:

Looks good.  As this is Tom's branch he will have to note whether it
can be checked in or not.  Some small nits:



> gdb/doc/ChangeLog
> 
> 2009-30-12  Matt McCormick  <matt@mmmccormick.com>
> 
>         * doc/gdb.texinfo (Basic Python): Document gdb.value_history_count.


As there is a ChangeLog in the doc/ directory, the paths should be
relative to the ChangeLog.  So in this case, the doc/ prefix is not
necessary.


> 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.


Same here with testsuite/.

> +@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


Missing period at the end of that sentence.

>  
> +/* This returns the number of entries in the value history.  */
> +
> +int get_value_history_count();
> +

Need a space before the '('.

And git diff --check reports a rogue whitespace ;)

git diff --check
gdb/testsuite/gdb.python/py-value.exp:277: trailing whitespace.

Cheers!

Phil

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] [python] Add gdb.value_history_count()
  2010-01-05 14:51               ` Phil Muldoon
@ 2010-01-05 19:49                 ` Tom Tromey
  2010-01-06  5:10                 ` Matthew McCormick (thewtex)
  1 sibling, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2010-01-05 19:49 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: Matt McCormick, archer

>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

Phil> Looks good.  As this is Tom's branch he will have to note whether
Phil> it can be checked in or not.

Matt, do you have paperwork on file with the FSF?
I can't remember asking you this before.

For a non-trivial patch, we need this before we can put it in.

If you don't have it, I can get you started, just send me email.

Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] [python] Add gdb.value_history_count()
  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
  1 sibling, 1 reply; 16+ messages in thread
From: Matthew McCormick (thewtex) @ 2010-01-06  5:10 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: archer

Thanks for your suggestions.

On Tue, Jan 5, 2010 at 8:50 AM, Phil Muldoon <pmuldoon@redhat.com> wrote:
> On 12/30/2009 05:16 PM, Matt McCormick wrote:
>
> Looks good.  As this is Tom's branch he will have to note whether it
> can be checked in or not.  Some small nits:
>
>
>
>> gdb/doc/ChangeLog
>>
>> 2009-30-12  Matt McCormick  <matt@mmmccormick.com>
>>
>>         * doc/gdb.texinfo (Basic Python): Document gdb.value_history_count.
>
>
> As there is a ChangeLog in the doc/ directory, the paths should be
> relative to the ChangeLog.  So in this case, the doc/ prefix is not
> necessary.
>

Logical.

>
>> 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.
>
>
> Same here with testsuite/.
>
>> +@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
>
>
> Missing period at the end of that sentence.
>
>>
>> +/* This returns the number of entries in the value history.  */
>> +
>> +int get_value_history_count();
>> +
>
> Need a space before the '('.
>
> And git diff --check reports a rogue whitespace ;)
>
> git diff --check
> gdb/testsuite/gdb.python/py-value.exp:277: trailing whitespace.
>

Git + extra whitespace = bull + red flag.

> Cheers!
>
> Phil
>

Thanks, Phil.  Will post an update.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH] [python] Add gdb.value_history_count()
  2010-01-06  5:10                 ` Matthew McCormick (thewtex)
@ 2010-01-06  5:11                   ` Matt McCormick
  2010-01-17 19:40                     ` Matt McCormick
  0 siblings, 1 reply; 16+ messages in thread
From: Matt McCormick @ 2010-01-06  5:11 UTC (permalink / raw)
  To: archer; +Cc: Matt McCormick

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>

        * 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.
---
 gdb/doc/gdb.texinfo                   |    6 ++++++
 gdb/python/lib/gdb/pretty/ipython.py  |   12 ++++++++++++
 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 ++++
 8 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 gdb/python/lib/gdb/pretty/ipython.py

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 18ffb09..944410c 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/lib/gdb/pretty/ipython.py b/gdb/python/lib/gdb/pretty/ipython.py
new file mode 100644
index 0000000..2b9cd65
--- /dev/null
+++ b/gdb/python/lib/gdb/pretty/ipython.py
@@ -0,0 +1,12 @@
+# IPython needs a sys.argv[0].
+import sys
+try:
+    sys.argv[0]
+except:
+    sys.argv = ['gdb']
+
+# The embedded IPython shell.
+# This API requires IPython 0.11 or greater.
+from IPython import embed
+
+import readline
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..601a80b 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..8befed5 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH] [python] Add gdb.value_history_count()
  2010-01-06  5:11                   ` Matt McCormick
@ 2010-01-17 19:40                     ` Matt McCormick
  0 siblings, 0 replies; 16+ messages in thread
From: Matt McCormick @ 2010-01-17 19:40 UTC (permalink / raw)
  To: archer; +Cc: Matt McCormick

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-01-17 19:40 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-13 21:22 [PATCH 1/2] [python] Add gdb.value_history_count() 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 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).