public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Matt McCormick <matt@mmmccormick.com>
To: archer@sourceware.org
Subject: [PATCH 2/3] [python] Create gdb.pretty.register.
Date: Mon, 18 Jan 2010 07:57:00 -0000	[thread overview]
Message-ID: <20100118075707.2095.6863.stgit@localhost> (raw)
In-Reply-To: <f23d1cbc1001171943y447c46f1wa7d6f6c1bfc52a68@mail.gmail.com>

A common gdb.pretty.register function serves two purposes: reduces redundant
code and makes registering more concise for the objfile-gdb.py files.

Instead of

     def register_printers (objfile):
	 objfile.pretty_printers.add (str_lookup_function)

repeated in all the pretty printer code and

     import gdb.libstdcxx.v6
     gdb.libstdcxx.v6.register_printers (gdb.current_objfile ())
     import gdb.otherprinter
     gdb.otherprinter.register_printers (gdb.current_objfile ())

in the objfile-gdb.py files

     import gdb.pretty
     gdb.pretty.register ('gdb.libstdcxx.v6.printers', gdb.current_objfile ())
     gdb.pretty.register ('gdb.otherprinter', gdb.current_objfile ())

Is only required in the objfile-gdb.py files.  This requires the convention that
a function called 'lookup_function' exists the pretty-printer module.

gdb/ChangeLog

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

        * python/lib/gdb/pretty/__init__.py (register): New function.
---

 gdb/python/lib/gdb/pretty/__init__.py |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/gdb/python/lib/gdb/pretty/__init__.py b/gdb/python/lib/gdb/pretty/__init__.py
index be8a854..3cd9174 100644
--- a/gdb/python/lib/gdb/pretty/__init__.py
+++ b/gdb/python/lib/gdb/pretty/__init__.py
@@ -14,3 +14,29 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+
+import gdb
+
+def register (module_path, obj):
+    """Register the objfile with the pretty-printer module.
+
+    The module should define a lookup function called *lookup_function*
+    that returns the gdb pretty-printer or None.
+
+    Arguments
+    ---------
+    module_path: string
+        String specifying the module path.  E.g.
+        'libstdcxx.v6.printer'
+    obj: gdb.Obj
+        Object the printer will be registered with.  If None, the pretty-printer
+        is appended to global gdb module.
+"""
+    if obj == None:
+        obj = gdb
+
+    top_mod = __import__ (module_path, globals(), locals(), ['lookup_function'])
+    mod = sys.modules[module_path]
+    obj.pretty_printers.append (mod.lookup_function)

  parent reply	other threads:[~2010-01-18  7:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-31 15:00 [PATCH 1/3] [rfc][python] Create gdb.python package Matt McCormick
2009-12-31 15:00 ` [PATCH 2/3] [python] Create gdb.pretty.register Matt McCormick
2009-12-31 15:00   ` [PATCH 3/3] [python] Create pretty-printer lookup_function classes Matt McCormick
2010-01-18  3:43   ` [PATCH 2/3] [python] Create gdb.pretty.register Matthew McCormick (thewtex)
2010-01-18  7:57     ` [PATCH 1/3] [python] Create gdb.pretty package Matt McCormick
2010-01-18  8:05       ` [Archer] " Joel Brobecker
2010-01-18 16:20         ` Matthew McCormick (thewtex)
2010-01-18  7:57     ` Matt McCormick [this message]
2010-01-18  7:57     ` [PATCH 3/3] [python] Create pretty-printer lookup_function classes Matt McCormick

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=20100118075707.2095.6863.stgit@localhost \
    --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).