Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Paul Koning <paulkoning@comcast.net>
To: gdb-patches@sourceware.org, Tom Tromey <tromey@redhat.com>
Cc: Doug Evans <dje@google.com>
Subject: [RFA] Python: iterator for deep traversal of gdb.Type struct/union fields
Date: Thu, 27 Oct 2011 21:56:00 -0000	[thread overview]
Message-ID: <66CAE6F8-F396-468B-A5CF-8D542A8A2E3D@comcast.net> (raw)
In-Reply-To: <09787EF419216C41A903FD14EE5506DD030CF168FB@AUSX7MCPC103.AMER.DELL.COM>

> -----Original Message-----
> From: Tom Tromey [mailto:tromey@redhat.com] 
> Sent: Thursday, October 27, 2011 3:57 PM
> To: Koning, Paul
> Cc: dje@google.com; gdb-patches@sourceware.org
> Subject: Re: [RFA] Python: iterator for deep traversal of gdb.Type struct/union fields
> 
>>>>>> "Paul" ==   <Paul_Koning@Dell.com> writes:
> 
>>> Hi.  Is it too late to change the name to deep_items?
>>> 
>>> I like consistency in the user-facing API and we've been using 
>>> foo_bar (as does PEP008).
>>> 
>>> [Or is there a special reason for eliding the underscore?]
> 
> Paul> No problem that I know of.  It's a trivial change to make if 
> Paul> that's desired.
> 
> Yeah, I think so.
> 
> I was unaware that this is in PEP 8.
> 
> Also, could you write a NEWS item?  I'd like to try to put all Python additions into NEWS.

Like this?

	paul

ChangeLog:

2011-10-27  Paul Koning  <paul_koning@dell.com>

	* python/lib/gdb/types.py (deep_items): Rename from deepitems.
	* NEWS: Mention deep_items.

doc/ChangeLog:

2011-10-27  Paul Koning  <paul_koning@dell.com>

	* gdb.texinfo (gdb.types): Rename deepitems to deep_items.

testsuite/ChangeLog:

2011-10-27  Paul Koning  <paul_koning@dell.com>

	* gdb.python/lib-types.exp (deep_items): Rename from deepitems.

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.461
diff -u -r1.461 NEWS
--- NEWS	24 Oct 2011 11:49:26 -0000	1.461
+++ NEWS	27 Oct 2011 21:21:31 -0000
@@ -56,6 +56,12 @@
   ** A new event "gdb.new_objfile" has been added, triggered by loading a
      new object file.
 
+  ** A new function, "deep_items" has been added to the gdb.types
+     module in the GDB Python modules library.  This function returns
+     an iterator over the fields of a struct or union type.  Unlike
+     the standard Python "iteritems" method, it will recursively traverse
+     any anonymous fields.
+
 * libthread-db-search-path now supports two special values: $sdir and $pdir.
   $sdir specifies the default system locations of shared libraries.
   $pdir specifies the directory where the libpthread used by the application
Index: python/lib/gdb/types.py
===================================================================
RCS file: /cvs/src/src/gdb/python/lib/gdb/types.py,v
retrieving revision 1.3
diff -u -r1.3 types.py
--- python/lib/gdb/types.py	26 Oct 2011 15:09:40 -0000	1.3
+++ python/lib/gdb/types.py	27 Oct 2011 21:21:35 -0000
@@ -91,7 +91,7 @@
     return enum_dict
 
 
-def deepitems (type_):
+def deep_items (type_):
     """Return an iterator that recursively traverses anonymous fields.
 
     Arguments:
@@ -107,5 +107,5 @@
         if k:
             yield k, v
         else:
-            for i in deepitems (v.type):
+            for i in deep_items (v.type):
                 yield i
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.883
diff -u -r1.883 gdb.texinfo
--- doc/gdb.texinfo	27 Oct 2011 11:04:26 -0000	1.883
+++ doc/gdb.texinfo	27 Oct 2011 21:21:35 -0000
@@ -24438,10 +24438,10 @@
 @item make_enum_dict (@var{enum_type})
 Return a Python @code{dictionary} type produced from @var{enum_type}.
 
-@item deepitems (@var{type})
+@item deep_items (@var{type})
 Returns a Python iterator similar to the standard
 @code{gdb.Type.iteritems} method, except that the iterator returned
-by @code{deepitems} will recursively traverse anonymous struct or
+by @code{deep_items} will recursively traverse anonymous struct or
 union fields.  For example:
 
 @smallexample
@@ -24462,7 +24462,7 @@
 (@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
 (@value{GDBP}) python print struct_a.keys ()
 @{['a', '']@}
-(@value{GDBP}) python print [k for k,v in gdb.types.deepitems(struct_a)]
+(@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
 @{['a', 'b0', 'b1']@}
 @end smallexample
 
Index: testsuite/gdb.python/lib-types.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/lib-types.exp,v
retrieving revision 1.4
diff -u -r1.4 lib-types.exp
--- testsuite/gdb.python/lib-types.exp	26 Oct 2011 15:10:11 -0000	1.4
+++ testsuite/gdb.python/lib-types.exp	27 Oct 2011 21:21:36 -0000
@@ -139,7 +139,7 @@
 gdb_test_no_output "python enum1_list.sort ()"
 gdb_test "python print enum1_list" {\[\('A', 0L\), \('B', 1L\), \('C', 2L\)\]}
 
-# test deepitems
+# test deep_items
 gdb_test_no_output "python struct_a = gdb.lookup_type ('struct A')"
 gdb_test "python print struct_a.keys ()" {\['a', '', 'c', ''\]}
-gdb_test "python print \[k for k,v in gdb.types.deepitems(struct_a)\]" {\['a', 'b0', 'b1', 'bb0', 'bb1', 'bbb0', 'bbb1', 'c', 'dd0', 'dd1', 'd2', 'd3'\]}
+gdb_test "python print \[k for k,v in gdb.types.deep_items(struct_a)\]" {\['a', 'b0', 'b1', 'bb0', 'bb1', 'bbb0', 'bbb1', 'c', 'dd0', 'dd1', 'd2', 'd3'\]}


  parent reply	other threads:[~2011-10-27 21:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-30 11:04 [PATCH v2] gdb/python: add missing handling for anonymous members of struct and union Li Yu
2011-09-30 16:15 ` Paul Koning
2011-10-01 14:01   ` Li Yu
2011-10-01 18:54     ` Paul Koning
2011-10-04 16:37 ` Tom Tromey
2011-10-04 18:05   ` Paul Koning
2011-10-04 20:24     ` Tom Tromey
2011-10-04 20:41       ` Paul Koning
2011-10-19 20:52         ` Tom Tromey
2011-10-19 20:59           ` Paul Koning
2011-10-20 18:49             ` Tom Tromey
2011-10-25 18:34               ` [RFA] Python: iterator for deep traversal of gdb.Type struct/union fields Paul Koning
2011-10-25 19:03                 ` Paul Koning
2011-10-25 20:16                   ` Eli Zaretskii
2011-10-26 17:14                     ` Paul Koning
2011-10-27 13:01                       ` Doug Evans
2011-10-27 14:52                         ` Paul_Koning
2011-10-27 19:57                           ` Tom Tromey
     [not found]                             ` <09787EF419216C41A903FD14EE5506DD030CF168FB@AUSX7MCPC103.AMER.DELL.COM>
2011-10-27 21:56                               ` Paul Koning [this message]
2011-10-27 22:14                                 ` Eli Zaretskii
2011-10-28 14:55                                   ` Paul Koning

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=66CAE6F8-F396-468B-A5CF-8D542A8A2E3D@comcast.net \
    --to=paulkoning@comcast.net \
    --cc=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /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