adding some useful attributes & method to DIE
authoreliben <devnull@localhost>
Thu, 22 Sep 2011 10:54:26 +0000 (13:54 +0300)
committereliben <devnull@localhost>
Thu, 22 Sep 2011 10:54:26 +0000 (13:54 +0300)
elftools/dwarf/die.py
z.py

index f4fc2cb01d862268531ec64f0e96e7ba4a1cfd3f..fba5ed29e2b9465ee4222be32ff910b93a0d9106 100644 (file)
@@ -60,8 +60,18 @@ class DIE(object):
         self.dwarfinfo = self.cu.dwarfinfo # get DWARFInfo context
         self.stream = stream
         self.offset = offset
+        
         self.attributes = OrderedDict()
-        self._parse_DIE()
+        self.tag = None
+        self.has_children = None
+        self.size = 0
+        
+        self._parse_DIE()   
+    
+    def is_null(self):
+        """ Is this a null entry?
+        """
+        return self.tag is None
     
     def _parse_DIE(self):
         """ Parses the DIE info from the section, based on the abbreviation
@@ -76,14 +86,22 @@ class DIE(object):
         #
         abbrev_code = struct_parse(
             structs.Dwarf_uleb128(''), self.stream, self.offset)
+        
+        # This may be a null entry
+        if abbrev_code == 0:
+            self.size = self.stream.tell() - self.offset
+            return
+        
         with preserve_stream_pos(self.stream):
             abbrev_decl = self.cu.get_abbrev_table().get_abbrev(abbrev_code)
+        self.tag = abbrev_decl['tag']
         self.has_children = abbrev_decl.has_children()
         
         # Guided by the attributes listed in the abbreviation declaration, parse
         # values from the stream.
         #
         for name, form in abbrev_decl.iter_attr_specs():
+            print '**', self.stream.tell()
             raw_value = struct_parse(structs.Dwarf_dw_form[form], self.stream)
             value = self._translate_attr_value(form, raw_value)            
             self.attributes[name] = AttributeValue(form, value, raw_value)
diff --git a/z.py b/z.py
index b41b70c51b22ca21c0bf7db8e460e9627c917995..ea7c762a628d6beeddd1aa27d1da84322c7bd499 100644 (file)
--- a/z.py
+++ b/z.py
@@ -26,7 +26,8 @@ cu = dwarfinfo.get_CU(1)
 print 'CU header', cu.header
 topdie = cu.get_top_DIE()
 
-print topdie.size, topdie.attributes
+print topdie.size, topdie.tag
+print topdie.attributes
 
 #~ print dwarfinfo.structs.Dwarf_abbrev_entry.parse('\x13\x01\x01\x03\x50\x04\x00\x00')