@@ -13,6 +13,13 @@ class FormatError(Exception):
1313 def __init__ (self , s ):
1414 Exception .__init__ (self , s )
1515
16+ def decorate_di (di , f , a , sa ):
17+ di ._format = f
18+ di ._arch_code = a
19+ di ._start_address = sa
20+ di ._frames = None
21+ di ._use_siblings = not (f in (0 , 4 ) and a in ("EM_PPC" , 'EM_PPC64' ))
22+
1623def read_pe (filename ):
1724 from filebytes .pe import PE , IMAGE_FILE_MACHINE , BinaryError
1825 import struct , zlib
@@ -76,9 +83,7 @@ def read_section(name, is_compressed, section, virtual_size, raw_size):
7683 gnu_debugaltlink_sec = data .get ('.gnu_debugaltlink' ),
7784 debug_types_sec = data .get ('.debug_types' )
7885 )
79- di ._format = 2
80- di ._arch_code = machine
81- di ._start_address = pefile .imageNtHeaders .header .OptionalHeader .ImageBase
86+ decorate_di (di , 2 , machine , pefile .imageNtHeaders .header .OptionalHeader .ImageBase )
8287 di ._frames = None
8388 return di
8489 except BinaryError as err :
@@ -328,14 +333,11 @@ def string_at(off):
328333 gnu_debugaltlink_sec = data .get ('__gnu_debugaltlink' ),
329334 debug_types_sec = data .get ('__debug_types' ),
330335 )
336+ text_cmd = next ((cmd for cmd in macho .loadCommands if cmd .header .cmd in (LC .SEGMENT , LC .SEGMENT_64 ) and cmd .name == "__TEXT" ), False )
337+ decorate_di (di , 1 , macho_arch_code (macho ), text_cmd .header .vmaddr if text_cmd else 0 )
331338 di ._unwind_sec = sections .get ('__unwind_info' ) # VERY unlikely to be None
332- di ._format = 1 # Will be adjusted later if Mach-O within A within fat Mach-O
333- di ._arch_code = macho_arch_code (macho )
334339 di ._slice_code = slice_code
335340 di ._uuid = uuid
336- text_cmd = next ((cmd for cmd in macho .loadCommands if cmd .header .cmd in (LC .SEGMENT , LC .SEGMENT_64 ) and cmd .name == "__TEXT" ), False )
337- di ._start_address = text_cmd .header .vmaddr if text_cmd else 0
338- di ._frames = None
339341 di ._has_exec = False
340342 return di
341343
@@ -495,10 +497,7 @@ def read_wasm(file):
495497 gnu_debugaltlink_sec = None ,
496498 debug_types_sec = data .get ('.debug_types' )
497499 )
498- di ._format = 3
499- di ._arch_code = None #N/A
500- di ._start_address = 0
501- di ._frames = None
500+ decorate_di (di , 3 , None , 0 )
502501 return di
503502
504503# Filename is only needed for supplemental DWARF resolution
@@ -519,10 +518,7 @@ def read_elf(file, filename):
519518 di = parse_dwarf1 (elffile )
520519
521520 if di :
522- di ._format = 0
523- di ._start_address = start_address
524- di ._arch_code = elffile .header .e_machine
525- di ._frames = None
521+ decorate_di (di , 0 , elffile .header .e_machine , start_address )
526522 return di
527523
528524###########################################################################
0 commit comments