# First pass: parse all DIEs and place them into self._dielist
die_offset = self.cu_die_offset
while die_offset < cu_boundary:
- die = DIE(cu=self, stream=self.dwarfinfo.stream, offset=die_offset)
+ die = DIE(
+ cu=self,
+ stream=self.dwarfinfo.debug_info_sec.stream,
+ offset=die_offset)
self._dielist.append(die)
die_offset += die.size
#-------------------------------------------------------------------------------
def _describe_attr_ref(attr, die, section_offset):
- return '<0x%x>' % (attr.value + die.cu.cu_offset - section_offset)
+ return '<0x%x>' % (attr.value + die.cu.cu_offset)
def _describe_attr_value_passthrough(attr, die, section_offset):
return attr.value
# The offset of the .debug_info section in the stream. Used to compute
# relative offset of attribute values to the beginning of the section.
- section_offset = self.dwarfinfo.debug_info_loc.offset
-
- # Some attribute values need relocations. These are computed with the
- # help of a DWARFRelocationManager for .debug_info, which is held by
- # DWARFInfo for this purpose.
- relocation_manager = self.dwarfinfo.relocation_manager['.debug_info']
+ section_offset = self.dwarfinfo.debug_info_sec.global_offset
# Guided by the attributes listed in the abbreviation declaration, parse
# values from the stream.
attr_offset = self.stream.tell()
raw_value = struct_parse(structs.Dwarf_dw_form[form], self.stream)
- # raw_value may need to be relocated, if there's a relocation
- # registered for this offset in the relocation manager.
- # Relocations are listed by offset relative to the beginning of
- # the section.
- offset_from_section = attr_offset - section_offset
- if relocation_manager.has_relocation(offset_from_section):
- # Applying the relocation may change the stream, so preserve it
- with preserve_stream_pos(self.stream):
- raw_value = relocation_manager.apply_relocation(
- offset=offset_from_section,
- value=raw_value)
-
value = self._translate_attr_value(form, raw_value)
self.attributes[name] = AttributeValue(
name=name,
if offset not in self._abbrevtable_cache:
self._abbrevtable_cache[offset] = AbbrevTable(
structs=self.structs,
- stream=self.stream,
+ stream=self.debug_abbrev_sec.stream,
offset=offset)
return self._abbrevtable_cache[offset]
"""
return struct_parse(
CString(''),
- self.stream,
+ self.debug_str_sec.stream,
stream_pos=offset)
#------ PRIVATE ------#
# instance suitable for this CU and use it to parse the rest.
#
initial_length = struct_parse(
- self.structs.Dwarf_uint32(''), self.stream, offset)
+ self.structs.Dwarf_uint32(''), self.debug_info_sec.stream, offset)
dwarf_format = 64 if initial_length == 0xFFFFFFFF else 32
# At this point we still haven't read the whole header, so we don't
address_size=4)
cu_header = struct_parse(
- cu_structs.Dwarf_CU_header, self.stream, offset)
+ cu_structs.Dwarf_CU_header, self.debug_info_sec.stream, offset)
if cu_header['address_size'] == 8:
cu_structs = DWARFStructs(
little_endian=self.little_endian,
dwarf_format=dwarf_format,
address_size=8)
- cu_die_offset = self.stream.tell()
+ cu_die_offset = self.debug_info_sec.stream.tell()
dwarf_assert(
self._is_supported_version(cu_header['version']),
"Expected supported DWARF version. Got '%s'" % cu_header['version'])
from elftools.common.exceptions import ELFError
from elftools.elf.elffile import ELFFile
from elftools.elf.segments import InterpSegment
-from elftools.elf.sections import SymbolTableSection, RelocationSection
+from elftools.elf.sections import SymbolTableSection
+from elftools.elf.relocation import RelocationSection
from elftools.elf.descriptions import (
describe_ei_class, describe_ei_data, describe_ei_version,
describe_ei_osabi, describe_e_type, describe_e_machine,
describe_symbol_type, describe_symbol_bind, describe_symbol_visibility,
describe_symbol_shndx, describe_reloc_type,
)
-from elftools.dwarf.dwarfinfo import DWARFInfo, DebugSectionLocator
+from elftools.dwarf.dwarfinfo import DWARFInfo
from elftools.dwarf.descriptions import describe_attr_value
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
+ section_offset = self._dwarfinfo.debug_info_sec.global_offset
- print '&&& section_offset', section_offset
-
for cu in self._dwarfinfo.iter_CUs():
self._emitline(' Compilation Unit @ offset %s:' %
- self._format_hex(cu.cu_offset - section_offset))
+ self._format_hex(cu.cu_offset))
self._emitline(' Length: %s (%s)' % (
self._format_hex(cu['unit_length']),
'%s-bit' % cu.dwarf_format()))
continue
self._emitline(' <%s><%x>: Abbrev Number: %s (%s)' % (
die_depth,
- die.offset - section_offset,
+ die.offset,
die.abbrev_code,
die.tag))
for attr in die.attributes.itervalues():
self._emitline(' <%2x> %-18s: %s' % (
- attr.offset - section_offset,
+ attr.offset,
attr.name,
describe_attr_value(
attr, die, section_offset)))
print topdie
dinfo_sec = efile.get_section_by_name('.debug_info')
-relman = DWARFRelocationManager(efile, dinfo_sec.name)
-
-print relman._reloc_section.name, relman._reloc_section['sh_offset']
-#pprint.pprint(relman._relocs)