gdbhooks: Add new pretty-printers for: varpool_node, symtab_node, cgraph_edge and ipa_ref.

Message ID e9d66c26-4065-70aa-7784-b41f7ab93828@suse.cz
State New
Headers show
Series
  • gdbhooks: Add new pretty-printers for: varpool_node, symtab_node, cgraph_edge and ipa_ref.
Related show

Commit Message

Martin Liška April 10, 2018, 12:45 p.m.
Hi.

I'm bit ashamed that I tasted our gdb pretty-printers today for the first time.
It's working nice and I would like to extend it a bit for classes that I print/debug often.

gcc/ChangeLog:

2018-04-10  Martin Liska  <mliska@suse.cz>

	* gdbhooks.py: Add pretty-printers for varpool_node, symtab_node,
	cgraph_edge and ipa_ref.
---
 gcc/gdbhooks.py | 45 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 7 deletions(-)

Comments

David Malcolm April 10, 2018, 2:10 p.m. | #1
On Tue, 2018-04-10 at 14:45 +0200, Martin Liška wrote:
> Hi.
> 
> I'm bit ashamed that I tasted our gdb pretty-printers today for the
> first time.
> It's working nice and I would like to extend it a bit for classes
> that I print/debug often.

This looks good from the gdbhooks.py side; I'll assume that this is
sane from the cgraph/IPA side.

You might want to add an example of how each of cgraph_edge and ipa_ref
get printed to the "Examples of output using the pretty-printers"
comment (after the cgraph_node example).

OK with that change.

> gcc/ChangeLog:
> 
> 2018-04-10  Martin Liska  <mliska@suse.cz>
> 
> 	* gdbhooks.py: Add pretty-printers for varpool_node,
> symtab_node,
> 	cgraph_edge and ipa_ref.
> ---
>  gcc/gdbhooks.py | 45 ++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 38 insertions(+), 7 deletions(-)
> 
>
Martin Liška April 10, 2018, 2:43 p.m. | #2
On 04/10/2018 04:10 PM, David Malcolm wrote:
> On Tue, 2018-04-10 at 14:45 +0200, Martin Liška wrote:
>> Hi.
>>
>> I'm bit ashamed that I tasted our gdb pretty-printers today for the
>> first time.
>> It's working nice and I would like to extend it a bit for classes
>> that I print/debug often.
> 
> This looks good from the gdbhooks.py side; I'll assume that this is
> sane from the cgraph/IPA side.
> 
> You might want to add an example of how each of cgraph_edge and ipa_ref
> get printed to the "Examples of output using the pretty-printers"
> comment (after the cgraph_node example).
> 
> OK with that change.

Thanks for feedback, do that in r259283.

Martin

> 
>> gcc/ChangeLog:
>>
>> 2018-04-10  Martin Liska  <mliska@suse.cz>
>>
>> 	* gdbhooks.py: Add pretty-printers for varpool_node,
>> symtab_node,
>> 	cgraph_edge and ipa_ref.
>> ---
>>  gcc/gdbhooks.py | 45 ++++++++++++++++++++++++++++++++++++++-------
>>  1 file changed, 38 insertions(+), 7 deletions(-)
>>
>>

Patch

diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index f13e4e67402..e439942531a 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -105,10 +105,10 @@  it's a quick way of getting lots of debuggability quickly.
 Callgraph nodes are printed with the name of the function decl, if
 available:
   (gdb) frame 5
-  #5  0x00000000006c288a in expand_function (node=<cgraph_node* 0x7ffff0312720 "foo">) at ../../src/gcc/cgraphunit.c:1594
+  #5  0x00000000006c288a in expand_function (node=<cgraph_node* 0x7ffff0312720 "foo"/12345>) at ../../src/gcc/cgraphunit.c:1594
   1594	  execute_pass_list (g->get_passes ()->all_passes);
   (gdb) p node
-  $1 = <cgraph_node* 0x7ffff0312720 "foo">
+  $1 = <cgraph_node* 0x7ffff0312720 "foo"/12345>
 
 vec<> pointers are printed as the address followed by the elements in
 braces.  Here's a length 2 vec:
@@ -245,18 +245,45 @@  class TreePrinter:
 # Callgraph pretty-printers
 ######################################################################
 
-class CGraphNodePrinter:
+class SymtabNodePrinter:
     def __init__(self, gdbval):
         self.gdbval = gdbval
 
     def to_string (self):
-        result = '<cgraph_node* 0x%x' % intptr(self.gdbval)
+        t = str(self.gdbval.type)
+        result = '<%s 0x%x' % (t, intptr(self.gdbval))
         if intptr(self.gdbval):
             # symtab_node::name calls lang_hooks.decl_printable_name
             # default implementation (lhd_decl_printable_name) is:
             #    return IDENTIFIER_POINTER (DECL_NAME (decl));
             tree_decl = Tree(self.gdbval['decl'])
-            result += ' "%s"' % tree_decl.DECL_NAME().IDENTIFIER_POINTER()
+            result += ' "%s"/%d' % (tree_decl.DECL_NAME().IDENTIFIER_POINTER(), self.gdbval['order'])
+        result += '>'
+        return result
+
+class CgraphEdgePrinter:
+    def __init__(self, gdbval):
+        self.gdbval = gdbval
+
+    def to_string (self):
+        result = '<cgraph_edge* 0x%x' % intptr(self.gdbval)
+        if intptr(self.gdbval):
+            src = SymtabNodePrinter(self.gdbval['caller']).to_string()
+            dest = SymtabNodePrinter(self.gdbval['callee']).to_string()
+            result += ' (%s -> %s)' % (src, dest)
+        result += '>'
+        return result
+
+class IpaReferencePrinter:
+    def __init__(self, gdbval):
+        self.gdbval = gdbval
+
+    def to_string (self):
+        result = '<ipa_ref* 0x%x' % intptr(self.gdbval)
+        if intptr(self.gdbval):
+            src = SymtabNodePrinter(self.gdbval['referring']).to_string()
+            dest = SymtabNodePrinter(self.gdbval['referred']).to_string()
+            result += ' (%s -> %s:%s)' % (src, dest, str(self.gdbval['use']))
         result += '>'
         return result
 
@@ -503,8 +530,12 @@  def build_pretty_printer():
     pp = GdbPrettyPrinters('gcc')
     pp.add_printer_for_types(['tree'],
                              'tree', TreePrinter)
-    pp.add_printer_for_types(['cgraph_node *'],
-                             'cgraph_node', CGraphNodePrinter)
+    pp.add_printer_for_types(['cgraph_node *', 'varpool_node *', 'symtab_node *'],
+                             'symtab_node', SymtabNodePrinter)
+    pp.add_printer_for_types(['cgraph_edge *'],
+                             'cgraph_edge', CgraphEdgePrinter)
+    pp.add_printer_for_types(['ipa_ref *'],
+                             'ipa_ref', IpaReferencePrinter)
     pp.add_printer_for_types(['dw_die_ref'],
                              'dw_die_ref', DWDieRefPrinter)
     pp.add_printer_for_types(['gimple', 'gimple *',