gdb python pretty printer for DIEs
diff mbox

Message ID 5488D2A5.4090407@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez Dec. 10, 2014, 11:09 p.m. UTC
On 12/10/14 06:21, David Malcolm wrote:
> 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...

Thanks.  Tom also pointed the same thing.  Ooops.

I'm committing the attached patch.

Aldy
commit d3f07cb1cbae79b10dc01affb863302e3f5e444d
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.

Patch
diff mbox

diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index a74e712..6d9e41e 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):
+        if long(self.gdbval) == 0:
+            return '<dw_die_ref 0x0>'
+        result = '<dw_die_ref 0x%x' % long(self.gdbval)
+        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: