PR python/17364
[deliverable/binutils-gdb.git] / gdb / python / lib / gdb / printing.py
index b4e798da231177e55de01ac32f4f018052d79991..ff5250a8093608e37b56c4733323b42aa8bc5011 100644 (file)
@@ -1,5 +1,5 @@
 # Pretty-printer utilities.
-# Copyright (C) 2010-2012 Free Software Foundation, Inc.
+# Copyright (C) 2010-2014 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 import gdb
 import gdb.types
 import re
+import sys
 
+if sys.version_info[0] > 2:
+    # Python 3 removed basestring and long
+    basestring = str
+    long = int
 
 class PrettyPrinter(object):
     """A basic pretty-printer.
@@ -194,6 +199,8 @@ class RegexpCollectionPrettyPrinter(PrettyPrinter):
 
         # Get the type name.
         typename = gdb.types.get_basic_type(val.type).tag
+        if not typename:
+            typename = val.type.name
         if not typename:
             return None
 
@@ -256,3 +263,17 @@ class FlagEnumerationPrinter(PrettyPrinter):
             return _EnumInstance(self.enumerators, val)
         else:
             return None
+
+
+# Builtin pretty-printers.
+# The set is defined as empty, and files in printing/*.py add their printers
+# to this with add_builtin_pretty_printer.
+
+_builtin_pretty_printers = RegexpCollectionPrettyPrinter("builtin")
+
+register_pretty_printer(None, _builtin_pretty_printers)
+
+# Add a builtin pretty-printer.
+
+def add_builtin_pretty_printer(name, regexp, printer):
+    _builtin_pretty_printers.add_printer(name, regexp, printer)
This page took 0.024751 seconds and 4 git commands to generate.