small fixes to have formatting consistent with readelf
authoreliben <devnull@localhost>
Mon, 14 Nov 2011 15:53:23 +0000 (17:53 +0200)
committereliben <devnull@localhost>
Mon, 14 Nov 2011 15:53:23 +0000 (17:53 +0200)
scripts/readelf.py
z.py

index 13bd4a745ff28398a3b3248a57672ac89548b483..228d7a2ab179f55f639366a486ae8530eaeb5788 100755 (executable)
@@ -489,11 +489,13 @@ class ReadElf(object):
     def _dump_debug_info(self):
         """ Dump the debugging info section.
         """
+        self._emitline('Contents of the .debug_info section:\n')
+        
         # Offset of the .debug_info section in the stream
         section_offset = self._dwarfinfo.debug_info_loc.offset
         
         for cu in self._dwarfinfo.iter_CUs():
-            self._emitline('  Compilation Unit @ offset %s' %
+            self._emitline('  Compilation Unit @ offset %s:' %
                 self._format_hex(cu.cu_offset - section_offset))
             self._emitline('   Length:        %s (%s)' % (
                 self._format_hex(cu['unit_length']),
diff --git a/z.py b/z.py
index 2a492ef4723643d2d8c2e37cc5b5b568df11a3dd..2cffb7445053b2da81c32f937943208ba2150292 100644 (file)
--- a/z.py
+++ b/z.py
@@ -10,33 +10,33 @@ from elftools.elf.sections import *
 # read a little-endian, 64-bit file
 es = ELFStructs(True, 64)
 
-stream = open('tests/testfiles/exe_simple64.elf', 'rb')
+stream = open('tests/testfiles/penalty_64.o.elf', 'rb')
 #stream = open('binfiles/z32.elf', 'rb')
 
 efile = ELFFile(stream)
-print efile.elfclass, efile.little_endian
+print 'elfclass', efile.elfclass
 print '===> %s sections!' % efile.num_sections() 
 
 #~ print efile.has_dwarf_info()
 
-#~ dwarfinfo = efile.get_dwarf_info()
+dwarfinfo = efile.get_dwarf_info()
+print dwarfinfo.get_string_from_table(0x4bc0)
+cu = dwarfinfo.get_CU(0)
 
-#~ cu = dwarfinfo.get_CU(3)
-#~ print 'CU header', cu.header
-#~ topdie = cu.get_top_DIE()
+print cu.structs.Dwarf_dw_form['DW_FORM_strp'].parse('\x01\x00\x00\x00\x01\x00\x00\x00')
+print 'CU header', cu.header
+topdie = cu.get_top_DIE()
 
-#~ c = topdie.iter_children().next()
-
-#~ print c
+print topdie
 
 #~ print 'siblings.....'
 
 #~ for s in c.iter_siblings():
     #~ print s
 
-from elftools.dwarf.location_expr import DW_OP_name2opcode, DW_OP_opcode2name
+#~ from elftools.dwarf.location_expr import DW_OP_name2opcode, DW_OP_opcode2name
 
-print hex(DW_OP_name2opcode['DW_OP_lit14'])
-print DW_OP_opcode2name[0x0e]
+#~ print hex(DW_OP_name2opcode['DW_OP_lit14'])
+#~ print DW_OP_opcode2name[0x0e]