diff options
author | dim <dim@FreeBSD.org> | 2011-02-20 12:57:14 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-02-20 12:57:14 +0000 |
commit | cbb70ce070d220642b038ea101d9c0f9fbf860d6 (patch) | |
tree | d2b61ce94e654cb01a254d2195259db5f9cc3f3c /test/Scripts | |
parent | 4ace901e87dac5bbbac78ed325e75462e48e386e (diff) | |
download | FreeBSD-src-cbb70ce070d220642b038ea101d9c0f9fbf860d6.zip FreeBSD-src-cbb70ce070d220642b038ea101d9c0f9fbf860d6.tar.gz |
Vendor import of llvm trunk r126079:
http://llvm.org/svn/llvm-project/llvm/trunk@126079
Diffstat (limited to 'test/Scripts')
-rwxr-xr-x | test/Scripts/coff-dump.py | 1008 | ||||
-rw-r--r-- | test/Scripts/coff-dump.py.bat | 5 | ||||
-rw-r--r-- | test/Scripts/common_dump.py | 46 | ||||
-rwxr-xr-x | test/Scripts/elf-dump | 231 | ||||
-rw-r--r-- | test/Scripts/elf-dump.bat | 7 | ||||
-rwxr-xr-x | test/Scripts/macho-dumpx (renamed from test/Scripts/macho-dump) | 11 | ||||
-rw-r--r-- | test/Scripts/macho-dumpx.bat (renamed from test/Scripts/macho-dump.bat) | 0 |
7 files changed, 812 insertions, 496 deletions
diff --git a/test/Scripts/coff-dump.py b/test/Scripts/coff-dump.py index 0af3d36..36ec539 100755 --- a/test/Scripts/coff-dump.py +++ b/test/Scripts/coff-dump.py @@ -13,216 +13,217 @@ # def string_table_entry (offset): - return ('ptr', '+ + PointerToSymbolTable * NumberOfSymbols 18 %s' % offset, ('scalar', 'cstr', '%s')) + return ('ptr', '+ + PointerToSymbolTable * NumberOfSymbols 18 %s' % offset, ('scalar', 'cstr', '%s')) def secname(value): - if value[0] == '/': - return string_table_entry (value [1:].rstrip('\0')) - else: - return '%s' + if value[0] == '/': + return string_table_entry(value[1:].rstrip('\0')) + else: + return '%s' def symname(value): - parts = struct.unpack("<2L", value) - if parts [0] == 0: - return string_table_entry (parts [1]) - else: - return '%s' + parts = struct.unpack("<2L", value) + if parts[0] == 0: + return string_table_entry(parts[1]) + else: + return '%s' file = ('struct', [ - ('MachineType', ('enum', '<H', '0x%X', { - 0x0: 'IMAGE_FILE_MACHINE_UNKNOWN', - 0x1d3: 'IMAGE_FILE_MACHINE_AM33', - 0x8664: 'IMAGE_FILE_MACHINE_AMD64', - 0x1c0: 'IMAGE_FILE_MACHINE_ARM', - 0xebc: 'IMAGE_FILE_MACHINE_EBC', - 0x14c: 'IMAGE_FILE_MACHINE_I386', - 0x200: 'IMAGE_FILE_MACHINE_IA64', - 0x904: 'IMAGE_FILE_MACHINE_M32R', - 0x266: 'IMAGE_FILE_MACHINE_MIPS16', - 0x366: 'IMAGE_FILE_MACHINE_MIPSFPU', - 0x466: 'IMAGE_FILE_MACHINE_MIPSFPU16', - 0x1f0: 'IMAGE_FILE_MACHINE_POWERPC', - 0x1f1: 'IMAGE_FILE_MACHINE_POWERPCFP', - 0x166: 'IMAGE_FILE_MACHINE_R4000', - 0x1a2: 'IMAGE_FILE_MACHINE_SH3', - 0x1a3: 'IMAGE_FILE_MACHINE_SH3DSP', - 0x1a6: 'IMAGE_FILE_MACHINE_SH4', - 0x1a8: 'IMAGE_FILE_MACHINE_SH5', - 0x1c2: 'IMAGE_FILE_MACHINE_THUMB', - 0x169: 'IMAGE_FILE_MACHINE_WCEMIPSV2', - })), - ('NumberOfSections', ('scalar', '<H', '%d')), - ('TimeDateStamp', ('scalar', '<L', '%d')), - ('PointerToSymbolTable', ('scalar', '<L', '0x%0X')), - ('NumberOfSymbols', ('scalar', '<L', '%d')), - ('SizeOfOptionalHeader', ('scalar', '<H', '%d')), - ('Characteristics', ('flags', '<H', '0x%x', [ - (0x0001, 'IMAGE_FILE_RELOCS_STRIPPED', ), - (0x0002, 'IMAGE_FILE_EXECUTABLE_IMAGE', ), - (0x0004, 'IMAGE_FILE_LINE_NUMS_STRIPPED', ), - (0x0008, 'IMAGE_FILE_LOCAL_SYMS_STRIPPED', ), - (0x0010, 'IMAGE_FILE_AGGRESSIVE_WS_TRIM', ), - (0x0020, 'IMAGE_FILE_LARGE_ADDRESS_AWARE', ), - (0x0080, 'IMAGE_FILE_BYTES_REVERSED_LO', ), - (0x0100, 'IMAGE_FILE_32BIT_MACHINE', ), - (0x0200, 'IMAGE_FILE_DEBUG_STRIPPED', ), - (0x0400, 'IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP', ), - (0x0800, 'IMAGE_FILE_NET_RUN_FROM_SWAP', ), - (0x1000, 'IMAGE_FILE_SYSTEM', ), - (0x2000, 'IMAGE_FILE_DLL', ), - (0x4000, 'IMAGE_FILE_UP_SYSTEM_ONLY', ), - (0x8000, 'IMAGE_FILE_BYTES_REVERSED_HI', ), - ])), - ('Sections', ('array', 'NumberOfSections', ('struct', [ - ('Name', ('scalar', '<8s', secname)), - ('VirtualSize', ('scalar', '<L', '%d' )), - ('VirtualAddress', ('scalar', '<L', '%d' )), - ('SizeOfRawData', ('scalar', '<L', '%d' )), - ('PointerToRawData', ('scalar', '<L', '0x%X' )), - ('PointerToRelocations', ('scalar', '<L', '0x%X' )), - ('PointerToLineNumbers', ('scalar', '<L', '0x%X' )), - ('NumberOfRelocations', ('scalar', '<H', '%d' )), - ('NumberOfLineNumbers', ('scalar', '<H', '%d' )), - ('Charateristics', ('flags', '<L', '0x%X', [ - (0x00000008, 'IMAGE_SCN_TYPE_NO_PAD'), - (0x00000020, 'IMAGE_SCN_CNT_CODE'), - (0x00000040, 'IMAGE_SCN_CNT_INITIALIZED_DATA'), - (0x00000080, 'IMAGE_SCN_CNT_UNINITIALIZED_DATA'), - (0x00000100, 'IMAGE_SCN_LNK_OTHER'), - (0x00000200, 'IMAGE_SCN_LNK_INFO'), - (0x00000800, 'IMAGE_SCN_LNK_REMOVE'), - (0x00001000, 'IMAGE_SCN_LNK_COMDAT'), - (0x00008000, 'IMAGE_SCN_GPREL'), - (0x00020000, 'IMAGE_SCN_MEM_PURGEABLE'), - (0x00020000, 'IMAGE_SCN_MEM_16BIT'), - (0x00040000, 'IMAGE_SCN_MEM_LOCKED'), - (0x00080000, 'IMAGE_SCN_MEM_PRELOAD'), - (0x00F00000, 'IMAGE_SCN_ALIGN', { - 0x00100000: 'IMAGE_SCN_ALIGN_1BYTES', - 0x00200000: 'IMAGE_SCN_ALIGN_2BYTES', - 0x00300000: 'IMAGE_SCN_ALIGN_4BYTES', - 0x00400000: 'IMAGE_SCN_ALIGN_8BYTES', - 0x00500000: 'IMAGE_SCN_ALIGN_16BYTES', - 0x00600000: 'IMAGE_SCN_ALIGN_32BYTES', - 0x00700000: 'IMAGE_SCN_ALIGN_64BYTES', - 0x00800000: 'IMAGE_SCN_ALIGN_128BYTES', - 0x00900000: 'IMAGE_SCN_ALIGN_256BYTES', - 0x00A00000: 'IMAGE_SCN_ALIGN_512BYTES', - 0x00B00000: 'IMAGE_SCN_ALIGN_1024BYTES', - 0x00C00000: 'IMAGE_SCN_ALIGN_2048BYTES', - 0x00D00000: 'IMAGE_SCN_ALIGN_4096BYTES', - 0x00E00000: 'IMAGE_SCN_ALIGN_8192BYTES', - }), - (0x01000000, 'IMAGE_SCN_LNK_NRELOC_OVFL'), - (0x02000000, 'IMAGE_SCN_MEM_DISCARDABLE'), - (0x04000000, 'IMAGE_SCN_MEM_NOT_CACHED'), - (0x08000000, 'IMAGE_SCN_MEM_NOT_PAGED'), - (0x10000000, 'IMAGE_SCN_MEM_SHARED'), - (0x20000000, 'IMAGE_SCN_MEM_EXECUTE'), - (0x40000000, 'IMAGE_SCN_MEM_READ'), - (0x80000000, 'IMAGE_SCN_MEM_WRITE'), - ])), - ('SectionData', ('ptr', 'PointerToRawData', ('blob', 'SizeOfRawData'))), - ('Relocations', ('ptr', 'PointerToRelocations', ('array', 'NumberOfRelocations', ('struct', [ - ('VirtualAddress', ('scalar', '<L', '0x%X')), - ('SymbolTableIndex', ('scalar', '<L', '%d' )), - ('Type', ('enum', '<H', '%d', ('MachineType', { - 0x14c: { - 0x0000: 'IMAGE_REL_I386_ABSOLUTE', - 0x0001: 'IMAGE_REL_I386_DIR16', - 0x0002: 'IMAGE_REL_I386_REL16', - 0x0006: 'IMAGE_REL_I386_DIR32', - 0x0007: 'IMAGE_REL_I386_DIR32NB', - 0x0009: 'IMAGE_REL_I386_SEG12', - 0x000A: 'IMAGE_REL_I386_SECTION', - 0x000B: 'IMAGE_REL_I386_SECREL', - 0x000C: 'IMAGE_REL_I386_TOKEN', - 0x000D: 'IMAGE_REL_I386_SECREL7', - 0x0014: 'IMAGE_REL_I386_REL32', - }, - 0x8664: { - 0x0000: 'IMAGE_REL_AMD64_ABSOLUTE', - 0x0001: 'IMAGE_REL_AMD64_ADDR64', - 0x0002: 'IMAGE_REL_AMD64_ADDR32', - 0x0003: 'IMAGE_REL_AMD64_ADDR32NB', - 0x0004: 'IMAGE_REL_AMD64_REL32', - 0x0005: 'IMAGE_REL_AMD64_REL32_1', - 0x0006: 'IMAGE_REL_AMD64_REL32_2', - 0x0007: 'IMAGE_REL_AMD64_REL32_3', - 0x0008: 'IMAGE_REL_AMD64_REL32_4', - 0x0009: 'IMAGE_REL_AMD64_REL32_5', - 0x000A: 'IMAGE_REL_AMD64_SECTION', - 0x000B: 'IMAGE_REL_AMD64_SECREL', - 0x000C: 'IMAGE_REL_AMD64_SECREL7', - 0x000D: 'IMAGE_REL_AMD64_TOKEN', - 0x000E: 'IMAGE_REL_AMD64_SREL32', - 0x000F: 'IMAGE_REL_AMD64_PAIR', - 0x0010: 'IMAGE_REL_AMD64_SSPAN32', - }, - }))), - ('SymbolName', ('ptr', '+ PointerToSymbolTable * - SymbolTableIndex 1 18', ('scalar', '<8s', symname))) - ])))), - ]))), - ('Symbols', ('ptr', 'PointerToSymbolTable', ('byte-array', '* NumberOfSymbols 18', ('struct', [ - ('Name', ('scalar', '<8s', symname)), - ('Value', ('scalar', '<L', '%d' )), - ('SectionNumber', ('scalar', '<H', '%d' )), - ('SimpleType', ('enum', '<B', '%d', { - 0: 'IMAGE_SYM_TYPE_NULL', - 1: 'IMAGE_SYM_TYPE_VOID', - 2: 'IMAGE_SYM_TYPE_CHAR', - 3: 'IMAGE_SYM_TYPE_SHORT', - 4: 'IMAGE_SYM_TYPE_INT', - 5: 'IMAGE_SYM_TYPE_LONG', - 6: 'IMAGE_SYM_TYPE_FLOAT', - 7: 'IMAGE_SYM_TYPE_DOUBLE', - 8: 'IMAGE_SYM_TYPE_STRUCT', - 9: 'IMAGE_SYM_TYPE_UNION', - 10: 'IMAGE_SYM_TYPE_ENUM', - 11: 'IMAGE_SYM_TYPE_MOE', - 12: 'IMAGE_SYM_TYPE_BYTE', - 13: 'IMAGE_SYM_TYPE_WORD', - 14: 'IMAGE_SYM_TYPE_UINT', - 15: 'IMAGE_SYM_TYPE_DWORD', - })), - ('ComplexType', ('enum', '<B', '%d', { - 0: 'IMAGE_SYM_DTYPE_NULL', - 1: 'IMAGE_SYM_DTYPE_POINTER', - 2: 'IMAGE_SYM_DTYPE_FUNCTION', - 3: 'IMAGE_SYM_DTYPE_ARRAY', - })), - ('StorageClass', ('enum', '<B', '%d', { - -1: 'IMAGE_SYM_CLASS_END_OF_FUNCTION', - 0: 'IMAGE_SYM_CLASS_NULL', - 1: 'IMAGE_SYM_CLASS_AUTOMATIC', - 2: 'IMAGE_SYM_CLASS_EXTERNAL', - 3: 'IMAGE_SYM_CLASS_STATIC', - 4: 'IMAGE_SYM_CLASS_REGISTER', - 5: 'IMAGE_SYM_CLASS_EXTERNAL_DEF', - 6: 'IMAGE_SYM_CLASS_LABEL', - 7: 'IMAGE_SYM_CLASS_UNDEFINED_LABEL', - 8: 'IMAGE_SYM_CLASS_MEMBER_OF_STRUCT', - 9: 'IMAGE_SYM_CLASS_ARGUMENT', - 10: 'IMAGE_SYM_CLASS_STRUCT_TAG', - 11: 'IMAGE_SYM_CLASS_MEMBER_OF_UNION', - 12: 'IMAGE_SYM_CLASS_UNION_TAG', - 13: 'IMAGE_SYM_CLASS_TYPE_DEFINITION', - 14: 'IMAGE_SYM_CLASS_UNDEFINED_STATIC', - 15: 'IMAGE_SYM_CLASS_ENUM_TAG', - 16: 'IMAGE_SYM_CLASS_MEMBER_OF_ENUM', - 17: 'IMAGE_SYM_CLASS_REGISTER_PARAM', - 18: 'IMAGE_SYM_CLASS_BIT_FIELD', - 100: 'IMAGE_SYM_CLASS_BLOCK', - 101: 'IMAGE_SYM_CLASS_FUNCTION', - 102: 'IMAGE_SYM_CLASS_END_OF_STRUCT', - 103: 'IMAGE_SYM_CLASS_FILE', - 104: 'IMAGE_SYM_CLASS_SECTION', - 105: 'IMAGE_SYM_CLASS_WEAK_EXTERNAL', - 107: 'IMAGE_SYM_CLASS_CLR_TOKEN', - })), - ('NumberOfAuxSymbols', ('scalar', '<B', '%d' )), - ('AuxillaryData', ('blob', '* NumberOfAuxSymbols 18')), - ])))), + ('MachineType', ('enum', '<H', '0x%X', { + 0x0: 'IMAGE_FILE_MACHINE_UNKNOWN', + 0x1d3: 'IMAGE_FILE_MACHINE_AM33', + 0x8664: 'IMAGE_FILE_MACHINE_AMD64', + 0x1c0: 'IMAGE_FILE_MACHINE_ARM', + 0xebc: 'IMAGE_FILE_MACHINE_EBC', + 0x14c: 'IMAGE_FILE_MACHINE_I386', + 0x200: 'IMAGE_FILE_MACHINE_IA64', + 0x904: 'IMAGE_FILE_MACHINE_M32R', + 0x266: 'IMAGE_FILE_MACHINE_MIPS16', + 0x366: 'IMAGE_FILE_MACHINE_MIPSFPU', + 0x466: 'IMAGE_FILE_MACHINE_MIPSFPU16', + 0x1f0: 'IMAGE_FILE_MACHINE_POWERPC', + 0x1f1: 'IMAGE_FILE_MACHINE_POWERPCFP', + 0x166: 'IMAGE_FILE_MACHINE_R4000', + 0x1a2: 'IMAGE_FILE_MACHINE_SH3', + 0x1a3: 'IMAGE_FILE_MACHINE_SH3DSP', + 0x1a6: 'IMAGE_FILE_MACHINE_SH4', + 0x1a8: 'IMAGE_FILE_MACHINE_SH5', + 0x1c2: 'IMAGE_FILE_MACHINE_THUMB', + 0x169: 'IMAGE_FILE_MACHINE_WCEMIPSV2', + })), + ('NumberOfSections', ('scalar', '<H', '%d')), + ('TimeDateStamp', ('scalar', '<L', '%d')), + ('PointerToSymbolTable', ('scalar', '<L', '0x%0X')), + ('NumberOfSymbols', ('scalar', '<L', '%d')), + ('SizeOfOptionalHeader', ('scalar', '<H', '%d')), + ('Characteristics', ('flags', '<H', '0x%x', [ + (0x0001, 'IMAGE_FILE_RELOCS_STRIPPED', ), + (0x0002, 'IMAGE_FILE_EXECUTABLE_IMAGE', ), + (0x0004, 'IMAGE_FILE_LINE_NUMS_STRIPPED', ), + (0x0008, 'IMAGE_FILE_LOCAL_SYMS_STRIPPED', ), + (0x0010, 'IMAGE_FILE_AGGRESSIVE_WS_TRIM', ), + (0x0020, 'IMAGE_FILE_LARGE_ADDRESS_AWARE', ), + (0x0080, 'IMAGE_FILE_BYTES_REVERSED_LO', ), + (0x0100, 'IMAGE_FILE_32BIT_MACHINE', ), + (0x0200, 'IMAGE_FILE_DEBUG_STRIPPED', ), + (0x0400, 'IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP', ), + (0x0800, 'IMAGE_FILE_NET_RUN_FROM_SWAP', ), + (0x1000, 'IMAGE_FILE_SYSTEM', ), + (0x2000, 'IMAGE_FILE_DLL', ), + (0x4000, 'IMAGE_FILE_UP_SYSTEM_ONLY', ), + (0x8000, 'IMAGE_FILE_BYTES_REVERSED_HI', ), + ])), + ('Sections', ('array', '1', 'NumberOfSections', ('struct', [ + ('Name', ('scalar', '<8s', secname)), + ('VirtualSize', ('scalar', '<L', '%d' )), + ('VirtualAddress', ('scalar', '<L', '%d' )), + ('SizeOfRawData', ('scalar', '<L', '%d' )), + ('PointerToRawData', ('scalar', '<L', '0x%X' )), + ('PointerToRelocations', ('scalar', '<L', '0x%X' )), + ('PointerToLineNumbers', ('scalar', '<L', '0x%X' )), + ('NumberOfRelocations', ('scalar', '<H', '%d' )), + ('NumberOfLineNumbers', ('scalar', '<H', '%d' )), + ('Charateristics', ('flags', '<L', '0x%X', [ + (0x00000008, 'IMAGE_SCN_TYPE_NO_PAD'), + (0x00000020, 'IMAGE_SCN_CNT_CODE'), + (0x00000040, 'IMAGE_SCN_CNT_INITIALIZED_DATA'), + (0x00000080, 'IMAGE_SCN_CNT_UNINITIALIZED_DATA'), + (0x00000100, 'IMAGE_SCN_LNK_OTHER'), + (0x00000200, 'IMAGE_SCN_LNK_INFO'), + (0x00000800, 'IMAGE_SCN_LNK_REMOVE'), + (0x00001000, 'IMAGE_SCN_LNK_COMDAT'), + (0x00008000, 'IMAGE_SCN_GPREL'), + (0x00020000, 'IMAGE_SCN_MEM_PURGEABLE'), + (0x00020000, 'IMAGE_SCN_MEM_16BIT'), + (0x00040000, 'IMAGE_SCN_MEM_LOCKED'), + (0x00080000, 'IMAGE_SCN_MEM_PRELOAD'), + (0x00F00000, 'IMAGE_SCN_ALIGN', { + 0x00100000: 'IMAGE_SCN_ALIGN_1BYTES', + 0x00200000: 'IMAGE_SCN_ALIGN_2BYTES', + 0x00300000: 'IMAGE_SCN_ALIGN_4BYTES', + 0x00400000: 'IMAGE_SCN_ALIGN_8BYTES', + 0x00500000: 'IMAGE_SCN_ALIGN_16BYTES', + 0x00600000: 'IMAGE_SCN_ALIGN_32BYTES', + 0x00700000: 'IMAGE_SCN_ALIGN_64BYTES', + 0x00800000: 'IMAGE_SCN_ALIGN_128BYTES', + 0x00900000: 'IMAGE_SCN_ALIGN_256BYTES', + 0x00A00000: 'IMAGE_SCN_ALIGN_512BYTES', + 0x00B00000: 'IMAGE_SCN_ALIGN_1024BYTES', + 0x00C00000: 'IMAGE_SCN_ALIGN_2048BYTES', + 0x00D00000: 'IMAGE_SCN_ALIGN_4096BYTES', + 0x00E00000: 'IMAGE_SCN_ALIGN_8192BYTES', + }), + (0x01000000, 'IMAGE_SCN_LNK_NRELOC_OVFL'), + (0x02000000, 'IMAGE_SCN_MEM_DISCARDABLE'), + (0x04000000, 'IMAGE_SCN_MEM_NOT_CACHED'), + (0x08000000, 'IMAGE_SCN_MEM_NOT_PAGED'), + (0x10000000, 'IMAGE_SCN_MEM_SHARED'), + (0x20000000, 'IMAGE_SCN_MEM_EXECUTE'), + (0x40000000, 'IMAGE_SCN_MEM_READ'), + (0x80000000, 'IMAGE_SCN_MEM_WRITE'), + ])), + ('SectionData', ('ptr', 'PointerToRawData', ('blob', 'SizeOfRawData'))), + ('Relocations', ('ptr', 'PointerToRelocations', ('array', '0', 'NumberOfRelocations', ('struct', [ + ('VirtualAddress', ('scalar', '<L', '0x%X')), + ('SymbolTableIndex', ('scalar', '<L', '%d' )), + ('Type', ('enum', '<H', '%d', ('MachineType', { + 0x14c: { + 0x0000: 'IMAGE_REL_I386_ABSOLUTE', + 0x0001: 'IMAGE_REL_I386_DIR16', + 0x0002: 'IMAGE_REL_I386_REL16', + 0x0006: 'IMAGE_REL_I386_DIR32', + 0x0007: 'IMAGE_REL_I386_DIR32NB', + 0x0009: 'IMAGE_REL_I386_SEG12', + 0x000A: 'IMAGE_REL_I386_SECTION', + 0x000B: 'IMAGE_REL_I386_SECREL', + 0x000C: 'IMAGE_REL_I386_TOKEN', + 0x000D: 'IMAGE_REL_I386_SECREL7', + 0x0014: 'IMAGE_REL_I386_REL32', + }, + 0x8664: { + 0x0000: 'IMAGE_REL_AMD64_ABSOLUTE', + 0x0001: 'IMAGE_REL_AMD64_ADDR64', + 0x0002: 'IMAGE_REL_AMD64_ADDR32', + 0x0003: 'IMAGE_REL_AMD64_ADDR32NB', + 0x0004: 'IMAGE_REL_AMD64_REL32', + 0x0005: 'IMAGE_REL_AMD64_REL32_1', + 0x0006: 'IMAGE_REL_AMD64_REL32_2', + 0x0007: 'IMAGE_REL_AMD64_REL32_3', + 0x0008: 'IMAGE_REL_AMD64_REL32_4', + 0x0009: 'IMAGE_REL_AMD64_REL32_5', + 0x000A: 'IMAGE_REL_AMD64_SECTION', + 0x000B: 'IMAGE_REL_AMD64_SECREL', + 0x000C: 'IMAGE_REL_AMD64_SECREL7', + 0x000D: 'IMAGE_REL_AMD64_TOKEN', + 0x000E: 'IMAGE_REL_AMD64_SREL32', + 0x000F: 'IMAGE_REL_AMD64_PAIR', + 0x0010: 'IMAGE_REL_AMD64_SSPAN32', + }, + }))), + ('SymbolName', ('ptr', '+ PointerToSymbolTable * SymbolTableIndex 18', ('scalar', '<8s', symname))) + ])))), + ]))), + ('Symbols', ('ptr', 'PointerToSymbolTable', ('byte-array', '18', '* NumberOfSymbols 18', ('struct', [ + ('Name', ('scalar', '<8s', symname)), + ('Value', ('scalar', '<L', '%d' )), + ('SectionNumber', ('scalar', '<H', '%d' )), + ('_Type', ('scalar', '<H', None )), + ('SimpleType', ('enum', '& _Type 15', '%d', { + 0: 'IMAGE_SYM_TYPE_NULL', + 1: 'IMAGE_SYM_TYPE_VOID', + 2: 'IMAGE_SYM_TYPE_CHAR', + 3: 'IMAGE_SYM_TYPE_SHORT', + 4: 'IMAGE_SYM_TYPE_INT', + 5: 'IMAGE_SYM_TYPE_LONG', + 6: 'IMAGE_SYM_TYPE_FLOAT', + 7: 'IMAGE_SYM_TYPE_DOUBLE', + 8: 'IMAGE_SYM_TYPE_STRUCT', + 9: 'IMAGE_SYM_TYPE_UNION', + 10: 'IMAGE_SYM_TYPE_ENUM', + 11: 'IMAGE_SYM_TYPE_MOE', + 12: 'IMAGE_SYM_TYPE_BYTE', + 13: 'IMAGE_SYM_TYPE_WORD', + 14: 'IMAGE_SYM_TYPE_UINT', + 15: 'IMAGE_SYM_TYPE_DWORD', + })), # (Type & 0xF0) >> 4 + ('ComplexType', ('enum', '>> & _Type 240 4', '%d', { + 0: 'IMAGE_SYM_DTYPE_NULL', + 1: 'IMAGE_SYM_DTYPE_POINTER', + 2: 'IMAGE_SYM_DTYPE_FUNCTION', + 3: 'IMAGE_SYM_DTYPE_ARRAY', + })), + ('StorageClass', ('enum', '<B', '%d', { + -1: 'IMAGE_SYM_CLASS_END_OF_FUNCTION', + 0: 'IMAGE_SYM_CLASS_NULL', + 1: 'IMAGE_SYM_CLASS_AUTOMATIC', + 2: 'IMAGE_SYM_CLASS_EXTERNAL', + 3: 'IMAGE_SYM_CLASS_STATIC', + 4: 'IMAGE_SYM_CLASS_REGISTER', + 5: 'IMAGE_SYM_CLASS_EXTERNAL_DEF', + 6: 'IMAGE_SYM_CLASS_LABEL', + 7: 'IMAGE_SYM_CLASS_UNDEFINED_LABEL', + 8: 'IMAGE_SYM_CLASS_MEMBER_OF_STRUCT', + 9: 'IMAGE_SYM_CLASS_ARGUMENT', + 10: 'IMAGE_SYM_CLASS_STRUCT_TAG', + 11: 'IMAGE_SYM_CLASS_MEMBER_OF_UNION', + 12: 'IMAGE_SYM_CLASS_UNION_TAG', + 13: 'IMAGE_SYM_CLASS_TYPE_DEFINITION', + 14: 'IMAGE_SYM_CLASS_UNDEFINED_STATIC', + 15: 'IMAGE_SYM_CLASS_ENUM_TAG', + 16: 'IMAGE_SYM_CLASS_MEMBER_OF_ENUM', + 17: 'IMAGE_SYM_CLASS_REGISTER_PARAM', + 18: 'IMAGE_SYM_CLASS_BIT_FIELD', + 100: 'IMAGE_SYM_CLASS_BLOCK', + 101: 'IMAGE_SYM_CLASS_FUNCTION', + 102: 'IMAGE_SYM_CLASS_END_OF_STRUCT', + 103: 'IMAGE_SYM_CLASS_FILE', + 104: 'IMAGE_SYM_CLASS_SECTION', + 105: 'IMAGE_SYM_CLASS_WEAK_EXTERNAL', + 107: 'IMAGE_SYM_CLASS_CLR_TOKEN', + })), + ('NumberOfAuxSymbols', ('scalar', '<B', '%d' )), + ('AuxillaryData', ('blob', '* NumberOfAuxSymbols 18')), + ])))), ]) # @@ -239,328 +240,351 @@ Indent = 0 NewLine = True def indent(): - global Indent - Indent += 1 + global Indent + Indent += 1 def dedent(): - global Indent - Indent -= 1 + global Indent + Indent -= 1 def write(input): - global NewLine - output = "" - - for char in input: - - if NewLine: - output += Indent * ' ' - NewLine = False - - output += char - - if char == '\n': - NewLine = True - - sys.stdout.write (output) + global NewLine + output = "" + + for char in input: + + if NewLine: + output += Indent * ' ' + NewLine = False + + output += char + + if char == '\n': + NewLine = True + + sys.stdout.write(output) def read(format): - return struct.unpack (format, Input.read(struct.calcsize(format))) - -def read_cstr (): - output = "" - while True: - char = Input.read (1) - if len (char) == 0: - raise RuntimeError ("EOF while reading cstr") - if char == '\0': - break - output += char - return output + return struct.unpack(format, Input.read(struct.calcsize(format))) + +def read_cstr(): + output = "" + while True: + char = Input.read(1) + if len(char) == 0: + raise RuntimeError ("EOF while reading cstr") + if char == '\0': + break + output += char + return output def push_pos(seek_to = None): - Stack [0:0] = [Input.tell ()] - if seek_to: - Input.seek (seek_to) + Stack [0:0] = [Input.tell()] + if seek_to: + Input.seek(seek_to) def pop_pos(): - assert(len (Stack) > 0) - Input.seek (Stack [0]) - del Stack [0] + assert(len(Stack) > 0) + Input.seek(Stack[0]) + del Stack[0] def print_binary_data(size): - value = "" - while size > 0: - if size >= 16: - data = Input.read(16) - size -= 16 - else: - data = Input.read(size) - size = 0 - value += data - bytes = "" - text = "" - for index in xrange (16): - if index < len (data): - if index == 8: - bytes += "- " - ch = ord (data [index]) - bytes += "%02X " % ch - if ch >= 0x20 and ch <= 0x7F: - text += data [index] - else: - text += "." - else: - if index == 8: - bytes += " " - bytes += " " - - write ("%s|%s|\n" % (bytes, text)) - return value - -idlit = re.compile ("[a-zA-Z][a-zA-Z0-9_-]*") -numlit = re.compile ("[0-9]+") + value = "" + while size > 0: + if size >= 16: + data = Input.read(16) + size -= 16 + else: + data = Input.read(size) + size = 0 + value += data + bytes = "" + text = "" + for index in xrange(16): + if index < len(data): + if index == 8: + bytes += "- " + ch = ord(data[index]) + bytes += "%02X " % ch + if ch >= 0x20 and ch <= 0x7F: + text += data[index] + else: + text += "." + else: + if index == 8: + bytes += " " + bytes += " " + + write("%s|%s|\n" % (bytes, text)) + return value + +idlit = re.compile("[a-zA-Z_][a-zA-Z0-9_-]*") +numlit = re.compile("[0-9]+") def read_value(expr): - input = iter (expr.split ()) - - def eval(): - - token = input.next () - - if expr == 'cstr': - return read_cstr () - if expr == 'true': - return True - if expr == 'false': - return False - - if len (token) > 1 and token [0] in ('=', '@', '<', '!', '>'): - val = read(expr) - assert (len (val) == 1) - return val [0] - - if token == '+': - return eval () + eval () - if token == '-': - return eval () - eval () - if token == '*': - return eval () * eval () - if token == '/': - return eval () / eval () - - if idlit.match (token): - return Fields [token] - if numlit.match (token): - return int (token) - - raise RuntimeError ("unexpected token %s" % repr(token)) - - value = eval () - - try: - input.next () - except StopIteration: - return value - raise RuntimeError("unexpected input at end of expression") + input = iter(expr.split()) + + def eval(): + + token = input.next() + + if expr == 'cstr': + return read_cstr() + if expr == 'true': + return True + if expr == 'false': + return False + + if token == '+': + return eval() + eval() + if token == '-': + return eval() - eval() + if token == '*': + return eval() * eval() + if token == '/': + return eval() / eval() + if token == '&': + return eval() & eval() + if token == '|': + return eval() | eval() + if token == '>>': + return eval() >> eval() + if token == '<<': + return eval() << eval() + + if len(token) > 1 and token[0] in ('=', '@', '<', '!', '>'): + val = read(expr) + assert(len(val) == 1) + return val[0] + + if idlit.match(token): + return Fields[token] + if numlit.match(token): + return int(token) + + raise RuntimeError("unexpected token %s" % repr(token)) + + value = eval() + + try: + input.next() + except StopIteration: + return value + raise RuntimeError("unexpected input at end of expression") def write_value(format,value): - format_type = type (format) - if format_type is types.StringType: - write (format%value) - elif format_type is types.FunctionType: - write_value (format (value), value) - elif format_type is types.TupleType: - Fields ['this'] = value - handle_element (format) - else: - raise RuntimeError("unexpected type: %s" % repr(format_type)) + format_type = type(format) + if format_type is types.StringType: + write(format % value) + elif format_type is types.FunctionType: + write_value(format(value), value) + elif format_type is types.TupleType: + Fields['this'] = value + handle_element(format) + elif format_type is types.NoneType: + pass + else: + raise RuntimeError("unexpected type: %s" % repr(format_type)) def handle_scalar(entry): - iformat = entry [1] - oformat = entry [2] - - value = read_value (iformat) - - write_value (oformat, value) - - return value + iformat = entry[1] + oformat = entry[2] + + value = read_value(iformat) + + write_value(oformat, value) + + return value def handle_enum(entry): - iformat = entry [1] - oformat = entry [2] - definitions = entry [3] - - value = read_value (iformat) - - if type (definitions) is types.TupleType: - selector = read_value (definitions [0]) - definitions = definitions [1] [selector] - - if value in definitions: - description = definitions[value] - else: - description = "unknown" - - write ("%s (" % description) - write_value (oformat, value) - write (")") - - return value + iformat = entry[1] + oformat = entry[2] + definitions = entry[3] + + value = read_value(iformat) + + if type(definitions) is types.TupleType: + selector = read_value(definitions[0]) + definitions = definitions[1][selector] + + if value in definitions: + description = definitions[value] + else: + description = "unknown" + + write("%s (" % description) + write_value(oformat, value) + write(")") + + return value def handle_flags(entry): - iformat = entry [1] - oformat = entry [2] - definitions = entry [3] - - value = read_value (iformat) - - write_value (oformat, value) - - indent () - for entry in definitions: - mask = entry [0] - name = entry [1] - if len (entry) == 3: - map = entry [2] - selection = value & mask - if selection in map: - write("\n%s" % map[selection]) - else: - write("\n%s <%d>" % (name, selection)) - elif len (entry) == 2: - if value & mask != 0: - write("\n%s" % name) - dedent () - - return value + iformat = entry[1] + oformat = entry[2] + definitions = entry[3] + + value = read_value(iformat) + + write_value(oformat, value) + + indent() + for entry in definitions: + mask = entry[0] + name = entry[1] + if len (entry) == 3: + map = entry[2] + selection = value & mask + if selection in map: + write("\n%s" % map[selection]) + else: + write("\n%s <%d>" % (name, selection)) + elif len(entry) == 2: + if value & mask != 0: + write("\n%s" % name) + dedent() + + return value def handle_struct(entry): - global Fields - members = entry [1] - - newFields = {} - - write ("{\n"); - indent () - - for member in members: - name = member [0] - type = member [1] - - write("%s = "%name.ljust(24)) - - value = handle_element(type) - - write("\n") - - Fields [name] = value - newFields [name] = value - - dedent () - write ("}") - - return newFields + global Fields + members = entry[1] + + newFields = {} + + write("{\n"); + indent() + + for member in members: + name = member[0] + type = member[1] + + if name[0] != "_": + write("%s = " % name.ljust(24)) + + value = handle_element(type) + + if name[0] != "_": + write("\n") + + Fields[name] = value + newFields[name] = value + + dedent() + write("}") + + return newFields def handle_array(entry): - length = entry [1] - element = entry [2] - - newItems = [] - - write ("[\n") - indent () - - value = read_value (length) - - for index in xrange (value): - write ("%d = "%index) - value = handle_element(element) - write ("\n") - newItems.append (value) - - dedent () - write ("]") - - return newItems + start_index = entry[1] + length = entry[2] + element = entry[3] + + newItems = [] + + write("[\n") + indent() + + start_index = read_value(start_index) + value = read_value(length) + + for index in xrange(value): + write("%d = " % (index + start_index)) + value = handle_element(element) + write("\n") + newItems.append(value) + + dedent() + write("]") + + return newItems def handle_byte_array(entry): - length = entry [1] - element = entry [2] - - newItems = [] - - write ("[\n") - indent () - - value = read_value (length) - end_of_array = Input.tell () + value - - index = 0 - while Input.tell () < end_of_array: - write ("%d = "%index) - value = handle_element(element) - write ("\n") - newItems.append (value) - index += 1 - - dedent () - write ("]") - - return newItems + ent_size = entry[1] + length = entry[2] + element = entry[3] + + newItems = [] + + write("[\n") + indent() + + item_size = read_value(ent_size) + value = read_value(length) + end_of_array = Input.tell() + value + + prev_loc = Input.tell() + index = 0 + while Input.tell() < end_of_array: + write("%d = " % index) + value = handle_element(element) + write("\n") + newItems.append(value) + index += (Input.tell() - prev_loc) / item_size + prev_loc = Input.tell() + + dedent() + write("]") + + return newItems def handle_ptr(entry): - offset = entry[1] - element = entry [2] - - value = None - offset = read_value (offset) - - if offset != 0: - - push_pos (offset) - - value = handle_element (element) - - pop_pos () - - else: - write ("None") - - return value + offset = entry[1] + element = entry[2] + + value = None + offset = read_value(offset) + + if offset != 0: + + push_pos(offset) + + value = handle_element(element) + + pop_pos() + + else: + write("None") + + return value def handle_blob(entry): - length = entry [1] - - write ("\n") - indent () - - value = print_binary_data (read_value (length)) - - dedent () - - return value + length = entry[1] + + write("\n") + indent() + + value = print_binary_data(read_value(length)) + + dedent() + + return value def handle_element(entry): - handlers = { - 'struct': handle_struct, - 'scalar': handle_scalar, - 'enum': handle_enum, - 'flags': handle_flags, - 'ptr': handle_ptr, - 'blob': handle_blob, - 'array': handle_array, - 'byte-array': handle_byte_array, - } - - if not entry [0] in handlers: - raise RuntimeError ("unexpected type '%s'" % str (entry[0])) - - return handlers [entry [0]] (entry) - -Input = open (sys.argv [1], "rb") + handlers = { + 'struct': handle_struct, + 'scalar': handle_scalar, + 'enum': handle_enum, + 'flags': handle_flags, + 'ptr': handle_ptr, + 'blob': handle_blob, + 'array': handle_array, + 'byte-array': handle_byte_array, + } + + if not entry[0] in handlers: + raise RuntimeError ("unexpected type '%s'" % str (entry[0])) + + return handlers[entry[0]](entry) + +if len(sys.argv) <= 1 or sys.argv[1] == '-': + import StringIO + Input = StringIO.StringIO(sys.stdin.read()) +else: + Input = open (sys.argv[1], "rb") + try: - handle_element (file) + handle_element(file) finally: - Input.close () - Input = None + Input.close() + Input = None diff --git a/test/Scripts/coff-dump.py.bat b/test/Scripts/coff-dump.py.bat index cc83eba..56428e1 100644 --- a/test/Scripts/coff-dump.py.bat +++ b/test/Scripts/coff-dump.py.bat @@ -1,4 +1,7 @@ @echo off -%PYTHON_EXECUTABLE% %LLVM_SRC_ROOT%\test\Scripts\coff-dump.py %1 %2 %3 %4 %5 %6 %7 %8 %9 +@rem We need to set -u to treat stdin as binary. Python 3 has support for doing +@rem this in code, but I haven't found a way to do this in 2.6 yet. + +%PYTHON_EXECUTABLE% -u %LLVM_SRC_ROOT%\test\Scripts\coff-dump.py %1 %2 %3 %4 %5 %6 %7 %8 %9 diff --git a/test/Scripts/common_dump.py b/test/Scripts/common_dump.py new file mode 100644 index 0000000..3d69c3f --- /dev/null +++ b/test/Scripts/common_dump.py @@ -0,0 +1,46 @@ +def dataToHex(d): + """ Convert the raw data in 'd' to an hex string with a space every 4 bytes. + """ + bytes = [] + for i,c in enumerate(d): + byte = ord(c) + hex_byte = hex(byte)[2:] + if byte <= 0xf: + hex_byte = '0' + hex_byte + if i % 4 == 3: + hex_byte += ' ' + bytes.append(hex_byte) + return ''.join(bytes).strip() + +def dataToHexUnified(d): + """ Convert the raw data in 'd' to an hex string with a space every 4 bytes. + Each 4byte number is prefixed with 0x for easy sed/rx + Fixme: convert all MC tests to use this routine instead of the above + """ + bytes = [] + for i,c in enumerate(d): + byte = ord(c) + hex_byte = hex(byte)[2:] + if byte <= 0xf: + hex_byte = '0' + hex_byte + if i % 4 == 0: + hex_byte = '0x' + hex_byte + if i % 4 == 3: + hex_byte += ' ' + bytes.append(hex_byte) + return ''.join(bytes).strip() + + +def HexDump(val, numBits=32): + """ + 1. do not print 'L' + 2. Handle negatives and large numbers by mod (2^numBits) + 3. print fixed length, prepend with zeros. + Length is exactly 2+(numBits/4) + 4. Do print 0x Why? + so that they can be easily distinguished using sed/rx + """ + val = val & (( 1 << numBits) - 1) + newFmt = "0x%0" + "%d" % (numBits / 4) + "x" + return newFmt % val + diff --git a/test/Scripts/elf-dump b/test/Scripts/elf-dump new file mode 100755 index 0000000..76cdbf9 --- /dev/null +++ b/test/Scripts/elf-dump @@ -0,0 +1,231 @@ +#!/usr/bin/env python + +import struct +import sys +import StringIO + +import common_dump + +class Reader: + def __init__(self, path): + if path == "-": + # Snarf all the data so we can seek. + self.file = StringIO.StringIO(sys.stdin.read()) + else: + self.file = open(path, "rb") + self.isLSB = None + self.is64Bit = None + + def seek(self, pos): + self.file.seek(pos) + + def read(self, N): + data = self.file.read(N) + if len(data) != N: + raise ValueError, "Out of data!" + return data + + def read8(self): + return ord(self.read(1)) + + def read16(self): + return struct.unpack('><'[self.isLSB] + 'H', self.read(2))[0] + + def read32(self): + return struct.unpack('><'[self.isLSB] + 'I', self.read(4))[0] + + def read32S(self): + return struct.unpack('><'[self.isLSB] + 'i', self.read(4))[0] + + def read64(self): + return struct.unpack('><'[self.isLSB] + 'Q', self.read(8))[0] + + def read64S(self): + return struct.unpack('><'[self.isLSB] + 'q', self.read(8))[0] + + def readWord(self): + if self.is64Bit: + return self.read64() + else: + return self.read32() + + def readWordS(self): + if self.is64Bit: + return self.read64S() + else: + return self.read32S() + +class StringTable: + def __init__(self, strings): + self.string_table = strings + + def __getitem__(self, index): + end = self.string_table.index('\x00', index) + return self.string_table[index:end] + +class Section: + def __init__(self, f): + self.sh_name = f.read32() + self.sh_type = f.read32() + self.sh_flags = f.readWord() + self.sh_addr = f.readWord() + self.sh_offset = f.readWord() + self.sh_size = f.readWord() + self.sh_link = f.read32() + self.sh_info = f.read32() + self.sh_addralign = f.readWord() + self.sh_entsize = f.readWord() + + def dump(self, shstrtab, f, strtab, dumpdata): + print " (('sh_name', %s)" % common_dump.HexDump(self.sh_name), "# %r" % shstrtab[self.sh_name] + print " ('sh_type', %s)" % common_dump.HexDump(self.sh_type) + print " ('sh_flags', %s)" % common_dump.HexDump(self.sh_flags) + print " ('sh_addr', %s)" % common_dump.HexDump(self.sh_addr) + print " ('sh_offset', %s)" % common_dump.HexDump(self.sh_offset) + print " ('sh_size', %s)" % common_dump.HexDump(self.sh_size) + print " ('sh_link', %s)" % common_dump.HexDump(self.sh_link) + print " ('sh_info', %s)" % common_dump.HexDump(self.sh_info) + print " ('sh_addralign', %s)" % common_dump.HexDump(self.sh_addralign) + print " ('sh_entsize', %s)" % common_dump.HexDump(self.sh_entsize) + if self.sh_type == 2: # SHT_SYMTAB + print " ('_symbols', [" + dumpSymtab(f, self, strtab) + print " ])" + elif self.sh_type == 4 or self.sh_type == 9: # SHT_RELA / SHT_REL + print " ('_relocations', [" + dumpRel(f, self, self.sh_type == 4) + print " ])" + elif dumpdata: + f.seek(self.sh_offset) + if self.sh_type != 8: # != SHT_NOBITS + data = f.read(self.sh_size) + print " ('_section_data', '%s')" % common_dump.dataToHex(data) + else: + print " ('_section_data', '')" + print " )," + +def dumpSymtab(f, section, strtab): + entries = section.sh_size // section.sh_entsize + + for index in range(entries): + f.seek(section.sh_offset + index * section.sh_entsize) + print " # Symbol %s" % common_dump.HexDump(index) + name = f.read32() + print " (('st_name', %s)" % common_dump.HexDump(name), "# %r" % strtab[name] + if not f.is64Bit: + print " ('st_value', %s)" % common_dump.HexDump(f.read32()) + print " ('st_size', %s)" % common_dump.HexDump(f.read32()) + st_info = f.read8() + print " ('st_bind', %s)" % common_dump.HexDump((st_info >> 4)) + print " ('st_type', %s)" % common_dump.HexDump((st_info & 0xf)) + print " ('st_other', %s)" % common_dump.HexDump(f.read8()) + print " ('st_shndx', %s)" % common_dump.HexDump(f.read16()) + if f.is64Bit: + print " ('st_value', %s)" % common_dump.HexDump(f.read64(), 64) + print " ('st_size', %s)" % common_dump.HexDump(f.read64(), 64) + print " )," + +def dumpRel(f, section, dumprela = False): + entries = section.sh_size // section.sh_entsize + + for index in range(entries): + f.seek(section.sh_offset + index * section.sh_entsize) + print " # Relocation %s" % common_dump.HexDump(index) + print " (('r_offset', %s)" % common_dump.HexDump(f.readWord()) + r_info = f.readWord() + if f.is64Bit: + print " ('r_sym', %s)" % common_dump.HexDump((r_info >> 32)) + print " ('r_type', %s)" % common_dump.HexDump((r_info & 0xffffffff)) + else: + print " ('r_sym', %s)" % common_dump.HexDump((r_info >> 8)) + print " ('r_type', %s)" % common_dump.HexDump((r_info & 0xff)) + if dumprela: + print " ('r_addend', %s)" % common_dump.HexDump(f.readWordS()) + print " )," + +def dumpELF(path, opts): + f = Reader(path) + + magic = f.read(4) + assert magic == '\x7FELF' + + fileclass = f.read8() + if fileclass == 1: # ELFCLASS32 + f.is64Bit = False + elif fileclass == 2: # ELFCLASS64 + f.is64Bit = True + else: + raise ValueError, "Unknown file class %s" % common_dump.HexDump(fileclass) + print "('e_indent[EI_CLASS]', %s)" % common_dump.HexDump(fileclass) + + byteordering = f.read8() + if byteordering == 1: # ELFDATA2LSB + f.isLSB = True + elif byteordering == 2: # ELFDATA2MSB + f.isLSB = False + else: + raise ValueError, "Unknown byte ordering %s" % common_dump.HexDump(byteordering) + print "('e_indent[EI_DATA]', %s)" % common_dump.HexDump(byteordering) + + print "('e_indent[EI_VERSION]', %s)" % common_dump.HexDump(f.read8()) + print "('e_indent[EI_OSABI]', %s)" % common_dump.HexDump(f.read8()) + print "('e_indent[EI_ABIVERSION]', %s)" % common_dump.HexDump(f.read8()) + + f.seek(16) # Seek to end of e_ident. + + print "('e_type', %s)" % common_dump.HexDump(f.read16()) + print "('e_machine', %s)" % common_dump.HexDump(f.read16()) + print "('e_version', %s)" % common_dump.HexDump(f.read32()) + print "('e_entry', %s)" % common_dump.HexDump(f.readWord()) + print "('e_phoff', %s)" % common_dump.HexDump(f.readWord()) + e_shoff = f.readWord() + print "('e_shoff', %s)" % common_dump.HexDump(e_shoff) + print "('e_flags', %s)" % common_dump.HexDump(f.read32()) + print "('e_ehsize', %s)" % common_dump.HexDump(f.read16()) + print "('e_phentsize', %s)" % common_dump.HexDump(f.read16()) + print "('e_phnum', %s)" % common_dump.HexDump(f.read16()) + e_shentsize = f.read16() + print "('e_shentsize', %s)" % common_dump.HexDump(e_shentsize) + e_shnum = f.read16() + print "('e_shnum', %s)" % common_dump.HexDump(e_shnum) + e_shstrndx = f.read16() + print "('e_shstrndx', %s)" % common_dump.HexDump(e_shstrndx) + + # Read all section headers + sections = [] + for index in range(e_shnum): + f.seek(e_shoff + index * e_shentsize) + s = Section(f) + sections.append(s) + + # Read .shstrtab so we can resolve section names + f.seek(sections[e_shstrndx].sh_offset) + shstrtab = StringTable(f.read(sections[e_shstrndx].sh_size)) + + # Get the symbol string table + strtab = None + for section in sections: + if shstrtab[section.sh_name] == ".strtab": + f.seek(section.sh_offset) + strtab = StringTable(f.read(section.sh_size)) + break + + print "('_sections', [" + for index in range(e_shnum): + print " # Section %s" % common_dump.HexDump(index) + sections[index].dump(shstrtab, f, strtab, opts.dumpSectionData) + print "])" + +if __name__ == "__main__": + from optparse import OptionParser, OptionGroup + parser = OptionParser("usage: %prog [options] {files}") + parser.add_option("", "--dump-section-data", dest="dumpSectionData", + help="Dump the contents of sections", + action="store_true", default=False) + (opts, args) = parser.parse_args() + + if not args: + args.append('-') + + for arg in args: + dumpELF(arg, opts) diff --git a/test/Scripts/elf-dump.bat b/test/Scripts/elf-dump.bat new file mode 100644 index 0000000..9c70808 --- /dev/null +++ b/test/Scripts/elf-dump.bat @@ -0,0 +1,7 @@ +@echo off + +@rem We need to set -u to treat stdin as binary. Python 3 has support for doing +@rem this in code, but I haven't found a way to do this in 2.6 yet. + +%PYTHON_EXECUTABLE% -u %LLVM_SRC_ROOT%\test\Scripts\elf-dump %1 %2 %3 %4 %5 %6 %7 %8 %9 + diff --git a/test/Scripts/macho-dump b/test/Scripts/macho-dumpx index 72f8339..71e06d8 100755 --- a/test/Scripts/macho-dump +++ b/test/Scripts/macho-dumpx @@ -4,6 +4,8 @@ import struct import sys import StringIO +import common_dump + class Reader: def __init__(self, path): if path == '-': @@ -41,7 +43,10 @@ class Reader: return int(Value) def read64(self): - return struct.unpack('><'[self.isLSB] + 'Q', self.read(8))[0] + Value = struct.unpack('><'[self.isLSB] + 'Q', self.read(8))[0] + if Value == int(Value): + Value = int(Value) + return Value def registerStringTable(self, strings): if self.string_table is not None: @@ -77,7 +82,7 @@ def dumpmacho(path, opts): print "('filetype', %r)" % filetype numLoadCommands = f.read32() - print "('num_load_commands', %r)" % filetype + print "('num_load_commands', %r)" % numLoadCommands loadCommandsSize = f.read32() print "('load_commands_size', %r)" % loadCommandsSize @@ -267,7 +272,7 @@ def dumpSection(f, i, opts, is64Bit): if opts.dumpSectionData: f.seek(offset) - print " ('_section_data', %r)" % f.read(size) + print " ('_section_data', '%s')" % common_dump.dataToHex(f.read(size)) f.seek(prev_pos) diff --git a/test/Scripts/macho-dump.bat b/test/Scripts/macho-dumpx.bat index 81484f6..81484f6 100644 --- a/test/Scripts/macho-dump.bat +++ b/test/Scripts/macho-dumpx.bat |