From: eliben Date: Thu, 22 Sep 2011 10:54:26 +0000 (+0300) Subject: adding some useful attributes & method to DIE X-Git-Tag: v0.10~98 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3addea51717c68df20eecabab525b1aa8077c1b2;p=pyelftools.git adding some useful attributes & method to DIE --- diff --git a/elftools/dwarf/die.py b/elftools/dwarf/die.py index f4fc2cb..fba5ed2 100644 --- a/elftools/dwarf/die.py +++ b/elftools/dwarf/die.py @@ -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 b41b70c..ea7c762 100644 --- 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')