Fix type casts losing typedefs and reimplement "whatis" typedef stripping
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prettyprint.py
index c56f5643bc7152941aeef2bcec02d00438576926..ec845e46575aa31779a5c95a1769cce4d509fdf8 100644 (file)
@@ -227,6 +227,13 @@ class pp_eval_type (object):
         gdb.execute("bt", to_string=True)
         return "eval=<" + str(gdb.parse_and_eval("eval_func (123456789, 2, 3, 4, 5, 6, 7, 8)")) + ">"
 
+class pp_int_typedef (object):
+    def __init__(self, val):
+        self.val = val
+
+    def to_string(self):
+        return "type=%s, val=%s" % (self.val.type, int(self.val))
+
 def lookup_function (val):
     "Look-up and return a pretty-printer that can print val."
 
@@ -263,6 +270,26 @@ def disable_lookup_function ():
 def enable_lookup_function ():
     lookup_function.enabled = True
 
+# Lookup a printer for VAL in the typedefs dict.
+def lookup_typedefs_function (val):
+    "Look-up and return a pretty-printer that can print val (typedefs)."
+
+    # Get the type.
+    type = val.type
+
+    if type == None or type.name == None or type.code != gdb.TYPE_CODE_TYPEDEF:
+        return None
+
+    # Iterate over local dictionary of typedef types to determine if a
+    # printer is registered for that type.  Return an instantiation of
+    # the printer if found.
+    for function in typedefs_pretty_printers_dict:
+        if function.match (type.name):
+            return typedefs_pretty_printers_dict[function] (val)
+
+    # Cannot find a pretty printer.
+    return None
+
 def register_pretty_printers ():
     pretty_printers_dict[re.compile ('^struct s$')]   = pp_s
     pretty_printers_dict[re.compile ('^s$')]   = pp_s
@@ -309,7 +336,14 @@ def register_pretty_printers ():
 
     pretty_printers_dict[re.compile ('^eval_type_s$')] = pp_eval_type
 
+    typedefs_pretty_printers_dict[re.compile ('^int_type$')] = pp_int_typedef
+    typedefs_pretty_printers_dict[re.compile ('^int_type2$')] = pp_int_typedef
+
+# Dict for struct types with typedefs fully stripped.
 pretty_printers_dict = {}
+# Dict for typedef types.
+typedefs_pretty_printers_dict = {}
 
 register_pretty_printers ()
 gdb.pretty_printers.append (lookup_function)
+gdb.pretty_printers.append (lookup_typedefs_function)
This page took 0.025631 seconds and 4 git commands to generate.