From: Eli Bendersky Date: Sun, 2 Jul 2017 16:11:50 +0000 (-0700) Subject: Cosmetic fixups X-Git-Tag: v0.25~38 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=edd48cb0878a7fc609cfce6ad1dec099317e3799;p=pyelftools.git Cosmetic fixups --- diff --git a/elftools/elf/elffile.py b/elftools/elf/elffile.py index e4b9f96..6fd2a73 100644 --- a/elftools/elf/elffile.py +++ b/elftools/elf/elffile.py @@ -52,8 +52,9 @@ class ELFFile(object): boolean - specifies the target machine's endianness elftype: - string or int, either known value of E_TYPE enum defining ELF type - (e.g. executable, dynamic library or core dump) or integral unparsed value + string or int, either known value of E_TYPE enum defining ELF + type (e.g. executable, dynamic library or core dump) or integral + unparsed value header: the complete ELF file header @@ -159,17 +160,17 @@ class ELFFile(object): # Sections that aren't found will be passed as None to DWARFInfo. # - section_names = ('.debug_info', '.debug_aranges', '.debug_abbrev', '.debug_str', - '.debug_line', '.debug_frame', + section_names = ('.debug_info', '.debug_aranges', '.debug_abbrev', + '.debug_str', '.debug_line', '.debug_frame', '.debug_loc', '.debug_ranges') compressed = bool(self.get_section_by_name('.zdebug_info')) if compressed: section_names = tuple(map(lambda x: '.z' + x[1:], section_names)) - debug_info_sec_name, debug_aranges_sec_name, debug_abbrev_sec_name, debug_str_sec_name, \ - debug_line_sec_name, debug_frame_sec_name, debug_loc_sec_name, \ - debug_ranges_sec_name = section_names + (debug_info_sec_name, debug_aranges_sec_name, debug_abbrev_sec_name, + debug_str_sec_name, debug_line_sec_name, debug_frame_sec_name, + debug_loc_sec_name, debug_ranges_sec_name) = section_names debug_sections = {} for secname in section_names: diff --git a/elftools/elf/structs.py b/elftools/elf/structs.py index b7a76eb..7c2c5d1 100644 --- a/elftools/elf/structs.py +++ b/elftools/elf/structs.py @@ -45,7 +45,7 @@ class ELFStructs(object): self.elfclass = elfclass def create_basic_structs(self): - """ Create word-size related structs and ehdr struct needed for + """ Create word-size related structs and ehdr struct needed for initial determining of ELF type. """ if self.little_endian: @@ -72,7 +72,8 @@ class ELFStructs(object): def create_advanced_structs(self, elftype=None): """ Create all ELF structs except the ehdr. They may possibly depend - on provided #elftype previously parsed from ehdr. """ + on provided #elftype previously parsed from ehdr. + """ self._create_phdr() self._create_shdr() self._create_sym() @@ -280,12 +281,14 @@ class ELFStructs(object): self.Elf_Nhdr = Struct('Elf_Nhdr', self.Elf_word('n_namesz'), self.Elf_word('n_descsz'), - Enum(self.Elf_word('n_type'), **(ENUM_NOTE_N_TYPE if elftype != "ET_CORE" else ENUM_CORE_NOTE_N_TYPE)), + Enum(self.Elf_word('n_type'), + **(ENUM_NOTE_N_TYPE if elftype != "ET_CORE" + else ENUM_CORE_NOTE_N_TYPE)), ) # A process psinfo structure according to # http://elixir.free-electrons.com/linux/v2.6.35/source/include/linux/elfcore.h#L84 - if self.elfclass == 32: + if self.elfclass == 32: self.Elf_Prpsinfo = Struct('Elf_Prpsinfo', self.Elf_byte('pr_state'), String('pr_sname', 1), @@ -319,7 +322,6 @@ class ELFStructs(object): String('pr_psargs', 80), ) - def _create_stabs(self): # Structure of one stabs entry, see binutils/bfd/stabs.c # Names taken from https://sourceware.org/gdb/current/onlinedocs/stabs.html#Overview diff --git a/test/run_readelf_tests.py b/test/run_readelf_tests.py index f7eff8c..f999174 100755 --- a/test/run_readelf_tests.py +++ b/test/run_readelf_tests.py @@ -56,9 +56,9 @@ def run_test_on_file(filename, verbose=False): '--debug-dump=aranges']: if verbose: testlog.info("..option='%s'" % option) - # TODO(zlobober): this is a dirty hack to make tests work for ELF core dump notes. - # Making it work properly requires a pretty deep investigation of how original readelf - # formats the output. + # TODO(zlobober): this is a dirty hack to make tests work for ELF core + # dump notes. Making it work properly requires a pretty deep + # investigation of how original readelf formats the output. if "core" in filename and option == "-n": if verbose: testlog.warning("....will fail because corresponding part of readelf.py is not implemented yet") @@ -205,7 +205,6 @@ def main(): # If file names are given as command-line arguments, only these files # are taken as inputs. Otherwise, autodiscovery is performed. - # if len(args) > 0: filenames = args else: diff --git a/test/test_core_notes.py b/test/test_core_notes.py index fd28e72..41ee6f8 100644 --- a/test/test_core_notes.py +++ b/test/test_core_notes.py @@ -12,13 +12,12 @@ from elftools.elf.segments import NoteSegment class TestCoreNotes(unittest.TestCase): """ This test makes sure than core dump specific - sections are properly analyzed. + sections are properly analyzed. """ def test_core_prpsinfo(self): - """ Test ... - """ - with open(os.path.join('test', 'testfiles_for_unittests', 'core_linux64.elf'), + with open(os.path.join('test', + 'testfiles_for_unittests', 'core_linux64.elf'), 'rb') as f: elf = ELFFile(f) for segment in elf.iter_segments(): @@ -40,5 +39,9 @@ class TestCoreNotes(unittest.TestCase): self.assertEquals(desc['pr_ppid'], 23187) self.assertEquals(desc['pr_pgrp'], 23395) self.assertEquals(desc['pr_sid'], 23187) - self.assertEquals(desc['pr_fname'], b'coredump_self\x00\x00\x00') - self.assertEquals(desc['pr_psargs'], b'./coredump_self foo bar 42 ' + b'\x00' * (80 - 27)) + self.assertEquals( + desc['pr_fname'], + b'coredump_self\x00\x00\x00') + self.assertEquals( + desc['pr_psargs'], + b'./coredump_self foo bar 42 ' + b'\x00' * (80 - 27))