This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/3] [python] Create gdb.pretty.register.


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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]