gdb python pretty printer for DIEs
diff mbox

Message ID 54876561.5080404@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez Dec. 9, 2014, 9:10 p.m. UTC
I am tired of dumping entire DIEs just to see what type they are.  With 
this patch, we get:

(gdb) print context_die
$5 = <dw_die_ref 0x7ffff6de0230 DW_TAG_module <parent=0x7ffff6de0000 
DW_TAG_compile_unit>>

I know it's past the end of stage1, but this debugging aid can help in 
fixing bugs in stage >= 3.

I am committing this to the [debug-early] branch, but I am hoping I can 
also commit it to mainline and avoid dragging it along.

OK for mainline?
commit e20f40f92eeba51f9a1ffb078e060366e7beb471
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Dec 9 13:04:46 2014 -0800

    	* gdbhooks.py (class DWDieRefPrinter): New class.
    	(build_pretty_printer): Register dw_die_ref's.

Comments

Jeff Law Dec. 9, 2014, 11:04 p.m. UTC | #1
On 12/09/14 14:10, Aldy Hernandez wrote:
> I am tired of dumping entire DIEs just to see what type they are.  With
> this patch, we get:
>
> (gdb) print context_die
> $5 = <dw_die_ref 0x7ffff6de0230 DW_TAG_module <parent=0x7ffff6de0000
> DW_TAG_compile_unit>>
>
> I know it's past the end of stage1, but this debugging aid can help in
> fixing bugs in stage >= 3.
>
> I am committing this to the [debug-early] branch, but I am hoping I can
> also commit it to mainline and avoid dragging it along.
>
> OK for mainline?
OK.

BTW, you might want to familiarize yourself with Petr's dwgrep as 
another tool for poking at things.


Jeff
David Malcolm Dec. 10, 2014, 2:21 p.m. UTC | #2
On Tue, 2014-12-09 at 13:10 -0800, Aldy Hernandez wrote:
>                              From: 
> Aldy Hernandez <aldyh@redhat.com>
>                                To: 
> jason merrill <jason@redhat.com>
>                                Cc: 
> David Malcolm
> <dmalcolm@redhat.com>, gcc-patches
> <gcc-patches@gcc.gnu.org>
>                           Subject: 
> [patch] gdb python pretty printer
> for DIEs
>                              Date: 
> Tue, 09 Dec 2014 13:10:57 -0800
> (12/09/2014 04:10:57 PM)
> 
> 
> I am tired of dumping entire DIEs just to see what type they are.
> With 
> this patch, we get:
> 
> (gdb) print context_die
> $5 = <dw_die_ref 0x7ffff6de0230 DW_TAG_module <parent=0x7ffff6de0000 
> DW_TAG_compile_unit>>
> 
> I know it's past the end of stage1, but this debugging aid can help
> in 
> fixing bugs in stage >= 3.
> 
> I am committing this to the [debug-early] branch, but I am hoping I
> can 
> also commit it to mainline and avoid dragging it along.
> 
> OK for mainline?


> --- a/gcc/gdbhooks.py
> +++ b/gcc/gdbhooks.py
> @@ -253,6 +253,26 @@ class CGraphNodePrinter:
>          return result
>  
>  ######################################################################
> +# Dwarf DIE pretty-printers
> +######################################################################
> +
> +class DWDieRefPrinter:
> +    def __init__(self, gdbval):
> +        self.gdbval = gdbval
> +
> +    def to_string (self):
> +        result = '<dw_die_ref 0x%x' % long(self.gdbval)

A minor nit: for the NULL case, you're doing slightly more work than
necessary: you start building "result" above...

> +        if long(self.gdbval) == 0:
> +            return '<dw_die_ref 0x0>'

...then discard it at the return here.  You could move the "result
= ..." line to after the "if ... == 0" conditional.

> +        result += ' %s' % self.gdbval['die_tag']
> +        if long(self.gdbval['die_parent']) != 0:
> +            result += ' <parent=0x%x %s>' %
> (long(self.gdbval['die_parent']),
> +
> self.gdbval['die_parent']['die_tag'])
> +                                             
> +        result += '>'
> +        return result

Patch
diff mbox

diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index a74e712..26affd9 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -253,6 +253,26 @@  class CGraphNodePrinter:
         return result
 
 ######################################################################
+# Dwarf DIE pretty-printers
+######################################################################
+
+class DWDieRefPrinter:
+    def __init__(self, gdbval):
+        self.gdbval = gdbval
+
+    def to_string (self):
+        result = '<dw_die_ref 0x%x' % long(self.gdbval)
+        if long(self.gdbval) == 0:
+            return '<dw_die_ref 0x0>'
+        result += ' %s' % self.gdbval['die_tag']
+        if long(self.gdbval['die_parent']) != 0:
+            result += ' <parent=0x%x %s>' % (long(self.gdbval['die_parent']),
+                                             self.gdbval['die_parent']['die_tag'])
+                                             
+        result += '>'
+        return result
+
+######################################################################
 
 class GimplePrinter:
     def __init__(self, gdbval):
@@ -455,6 +475,8 @@  def build_pretty_printer():
                              'tree', TreePrinter)
     pp.add_printer_for_types(['cgraph_node *'],
                              'cgraph_node', CGraphNodePrinter)
+    pp.add_printer_for_types(['dw_die_ref'],
+                             'dw_die_ref', DWDieRefPrinter)
     pp.add_printer_for_types(['gimple', 'gimple_statement_base *',
 
                               # Keep this in the same order as gimple.def: