From: Eli Bendersky Date: Sun, 31 Mar 2013 00:23:36 +0000 (-0700) Subject: Fix the way an include directory is inferred for a file in line programs. X-Git-Tag: v0.21~18 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7eba71836d7e133ad0778f8bb1a32caa3808fd9c;p=pyelftools.git Fix the way an include directory is inferred for a file in line programs. Applies only to readelf.py at this point, because the Dwarf APIs don't provide this functionality directly. --- diff --git a/scripts/readelf.py b/scripts/readelf.py index 33fa957..29efb7f 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -566,7 +566,8 @@ class ReadElf(object): self._format_hex(cu['unit_length']), '%s-bit' % cu.dwarf_format())) self._emitline(' Version: %s' % cu['version']), - self._emitline(' Abbrev Offset: %s' % cu['debug_abbrev_offset']), + self._emitline(' Abbrev Offset: %s' % ( + self._format_hex(cu['debug_abbrev_offset']))), self._emitline(' Pointer Size: %s' % cu['address_size']) # The nesting depth of each DIE within the tree of DIEs must be @@ -611,13 +612,14 @@ class ReadElf(object): for cu in self._dwarfinfo.iter_CUs(): lineprogram = self._dwarfinfo.line_program_for_CU(cu) - cu_filename = '' + cu_filename = bytes2str(lineprogram['file_entry'][0].name) if len(lineprogram['include_directory']) > 0: - cu_filename = '%s/%s' % ( - bytes2str(lineprogram['include_directory'][0]), - bytes2str(lineprogram['file_entry'][0].name)) - else: - cu_filename = bytes2str(lineprogram['file_entry'][0].name) + dir_index = lineprogram['file_entry'][0].dir_index + if dir_index > 0: + dir = lineprogram['include_directory'][dir_index - 1] + else: + dir = '.' + cu_filename = '%s/%s' % (bytes2str(dir), cu_filename) self._emitline('CU: %s:' % cu_filename) self._emitline('File name Line number Starting address')