From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20876 invoked by alias); 31 Dec 2009 15:00:20 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 20864 invoked by uid 22791); 31 Dec 2009 15:00:19 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org From: Matt McCormick To: archer@sourceware.org Cc: Matt McCormick Subject: [PATCH 2/3] [python] Create gdb.pretty.register Date: Thu, 31 Dec 2009 15:00:00 -0000 Message-Id: <1262271582-23248-2-git-send-email-matt@mmmccormick.com> In-Reply-To: <1262271582-23248-1-git-send-email-matt@mmmccormick.com> References: <1262271582-23248-1-git-send-email-matt@mmmccormick.com> X-SW-Source: 2009-q4/txt/msg00140.txt.bz2 A common gdb.pretty.register function serves two purposes: reduces redundant code and makes the 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 * python/lib/gdb/pretty/__init__.py (register): New function. --- gdb/python/lib/gdb/pretty/__init__.py | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/gdb/python/lib/gdb/pretty/__init__.py b/gdb/python/lib/gdb/pretty/__init__.py index be8a854..e75f757 100644 --- a/gdb/python/lib/gdb/pretty/__init__.py +++ b/gdb/python/lib/gdb/pretty/__init__.py @@ -14,3 +14,30 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + +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) + -- 1.6.6