This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[PATCH 2/3] [python] Create gdb.pretty.register
- From: Matt McCormick <matt at mmmccormick dot com>
- To: archer at sourceware dot org
- Cc: Matt McCormick <matt at mmmccormick dot com>
- Date: Thu, 31 Dec 2009 08:59:41 -0600
- Subject: [PATCH 2/3] [python] Create gdb.pretty.register
- References: <1262271582-23248-1-git-send-email-matt@mmmccormick.com>
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 <matt@mmmccormick.com>
* 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 <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)
+
--
1.6.6