From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 929 invoked by alias); 18 Jan 2010 07:57:16 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 920 invoked by uid 22791); 18 Jan 2010 07:57:16 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org From: Matt McCormick Subject: [PATCH 2/3] [python] Create gdb.pretty.register. To: archer@sourceware.org Date: Mon, 18 Jan 2010 07:57:00 -0000 Message-ID: <20100118075707.2095.6863.stgit@localhost> In-Reply-To: References: User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-SW-Source: 2010-q1/txt/msg00019.txt.bz2 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 * 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 . + +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)