This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 1/2] gdbhooks.py: use strip_typedefs to simplify matching type names
- From: Vladislav Ivanishin <vlad at ispras dot ru>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Mon, 01 Jul 2019 12:50:43 +0300
- Subject: [PATCH 1/2] gdbhooks.py: use strip_typedefs to simplify matching type names
Hi!
GDB's Python API provides strip_typedefs method that can be instrumental
for writing DRY code. Using it at least partially obviates the need for
the add_printer_for_types method we have in gdbhooks.py (it takes a list
of typenames to match and is usually used to deal with typedefs).
I think, the code can be simplified further (there's still
['tree_node *', 'const tree_node *'], which is a little awkward) if we
deal with pointer types in a uniform fashion (I'll touch on this in the
description of the second patch). But that can be improved separately.
The gimple_statement_cond, etc. part has been dysfunctional for a while
(namely since gimple-classes-v2-option-3 branch was merged). I updated
it to use the new classes' names. That seems to work (though it doesn't
output much info anyway: pretty
<gimple_phi 0x7ffff78c0200> vs.
(gphi *) 0x7ffff78c0200
in the raw version).
I changed the name passed to pp.add_printer_for_types() for scalar_mode
and friends -- so they all share the same name now -- but I don't
believe the name is used in any context where it would matter.
This is just a clean up of gdbhooks.py. OK to commit?
gcc/
* gdbhooks.py (GdbPrettyPrinters.__call__): canonicalize any variants of
a type name using strip_typdefs.
(build_pretty_printer): Use canonical names for types and otherwise
simplify the code. Clean up gimple_sth, gimple_statement_sth cruft.
---
gcc/gdbhooks.py | 48 +++++++++++++++++++-----------------------------
1 file changed, 19 insertions(+), 29 deletions(-)
diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index 26a09749aa3..b036704b86a 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -528,7 +528,7 @@ class GdbPrettyPrinters(gdb.printing.PrettyPrinter):
self.subprinters.append(GdbSubprinterRegex(regex, name, class_))
def __call__(self, gdbval):
- type_ = gdbval.type.unqualified()
+ type_ = gdbval.type.unqualified().strip_typedefs()
str_type = str(type_)
for printer in self.subprinters:
if printer.enabled and printer.handles_type(str_type):
@@ -540,7 +540,7 @@ class GdbPrettyPrinters(gdb.printing.PrettyPrinter):
def build_pretty_printer():
pp = GdbPrettyPrinters('gcc')
- pp.add_printer_for_types(['tree', 'const_tree'],
+ pp.add_printer_for_types(['tree_node *', 'const tree_node *'],
'tree', TreePrinter)
pp.add_printer_for_types(['cgraph_node *', 'varpool_node *', 'symtab_node *'],
'symtab_node', SymtabNodePrinter)
@@ -548,32 +548,25 @@ def build_pretty_printer():
'cgraph_edge', CgraphEdgePrinter)
pp.add_printer_for_types(['ipa_ref *'],
'ipa_ref', IpaReferencePrinter)
- pp.add_printer_for_types(['dw_die_ref'],
+ pp.add_printer_for_types(['die_struct *'],
'dw_die_ref', DWDieRefPrinter)
pp.add_printer_for_types(['gimple', 'gimple *',
# Keep this in the same order as gimple.def:
- 'gimple_cond', 'const_gimple_cond',
- 'gimple_statement_cond *',
- 'gimple_debug', 'const_gimple_debug',
- 'gimple_statement_debug *',
- 'gimple_label', 'const_gimple_label',
- 'gimple_statement_label *',
- 'gimple_switch', 'const_gimple_switch',
- 'gimple_statement_switch *',
- 'gimple_assign', 'const_gimple_assign',
- 'gimple_statement_assign *',
- 'gimple_bind', 'const_gimple_bind',
- 'gimple_statement_bind *',
- 'gimple_phi', 'const_gimple_phi',
- 'gimple_statement_phi *'],
+ 'gcond', 'gcond *',
+ 'gdebug', 'gdebug *',
+ 'glabel', 'glabel *',
+ 'gswitch', 'gswitch *',
+ 'gassign', 'gassign *',
+ 'gbind', 'gbind *',
+ 'gphi', 'gphi *'],
'gimple',
GimplePrinter)
- pp.add_printer_for_types(['basic_block', 'basic_block_def *'],
+ pp.add_printer_for_types(['basic_block_def *'],
'basic_block',
BasicBlockPrinter)
- pp.add_printer_for_types(['edge', 'edge_def *'],
+ pp.add_printer_for_types(['edge_def *'],
'edge',
CfgEdgePrinter)
pp.add_printer_for_types(['rtx_def *'], 'rtx_def', RtxPrinter)
@@ -585,18 +578,15 @@ def build_pretty_printer():
pp.add_printer_for_regex(r'opt_mode<(\S+)>',
'opt_mode', OptMachineModePrinter)
- pp.add_printer_for_types(['opt_scalar_int_mode',
- 'opt_scalar_float_mode',
- 'opt_scalar_mode'],
- 'opt_mode', OptMachineModePrinter)
pp.add_printer_for_regex(r'pod_mode<(\S+)>',
'pod_mode', MachineModePrinter)
- pp.add_printer_for_types(['scalar_int_mode_pod',
- 'scalar_mode_pod'],
- 'pod_mode', MachineModePrinter)
- for mode in ('scalar_mode', 'scalar_int_mode', 'scalar_float_mode',
- 'complex_mode'):
- pp.add_printer_for_types([mode], mode, MachineModePrinter)
+
+ pp.add_printer_for_types(['scalar_mode',
+ 'scalar_int_mode',
+ 'scalar_float_mode',
+ 'complex_mode'],
+ 'scalar & complex modes',
+ MachineModePrinter)
return pp
--
2.22.0
--
Vlad