From 7e87373e91afe6a9ed1ead63d9d02448f02213d3 Mon Sep 17 00:00:00 2001 From: Nico Rieck Date: Fri, 12 Apr 2013 04:07:13 +0000 Subject: [PATCH] Remove obsolete object file dumpers git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179362 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Makefile.tests | 2 +- test/Scripts/README.txt | 2 - test/Scripts/coff-dump.py | 590 ---------------------------------- test/Scripts/coff-dump.py.bat | 7 - test/Scripts/common_dump.py | 48 --- test/Scripts/elf-dump | 285 ---------------- test/Scripts/elf-dump.bat | 7 - test/Scripts/ignore | 10 - test/Scripts/macho-dumpx | 294 ----------------- test/Scripts/macho-dumpx.bat | 7 - test/lit.cfg | 11 +- 11 files changed, 2 insertions(+), 1261 deletions(-) delete mode 100644 test/Scripts/README.txt delete mode 100755 test/Scripts/coff-dump.py delete mode 100755 test/Scripts/coff-dump.py.bat delete mode 100644 test/Scripts/common_dump.py delete mode 100755 test/Scripts/elf-dump delete mode 100755 test/Scripts/elf-dump.bat delete mode 100755 test/Scripts/ignore delete mode 100755 test/Scripts/macho-dumpx delete mode 100644 test/Scripts/macho-dumpx.bat diff --git a/test/Makefile.tests b/test/Makefile.tests index aeb5871e7cd..c60c90c075d 100644 --- a/test/Makefile.tests +++ b/test/Makefile.tests @@ -38,7 +38,7 @@ LCCFLAGS += -O2 -Wall LCXXFLAGS += -O2 -Wall LLCFLAGS = TESTRUNR = @echo Running test: $<; \ - PATH="$(LLVMTOOLCURRENT):$(LLVM_SRC_ROOT)/test/Scripts:$(PATH)" \ + PATH="$(LLVMTOOLCURRENT):$(PATH)" \ $(LLVM_SRC_ROOT)/test/TestRunner.sh LLCLIBS := $(LLCLIBS) -lm diff --git a/test/Scripts/README.txt b/test/Scripts/README.txt deleted file mode 100644 index b0b11050375..00000000000 --- a/test/Scripts/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -This directory contains scripts which are used by the TestRunner style -tests, which allows them to be simpler and more direct. diff --git a/test/Scripts/coff-dump.py b/test/Scripts/coff-dump.py deleted file mode 100755 index 36ec53932c6..00000000000 --- a/test/Scripts/coff-dump.py +++ /dev/null @@ -1,590 +0,0 @@ -#!/usr/bin/env python -#===-- coff-dump.py - COFF object file dump utility-------------------------===# -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -#===------------------------------------------------------------------------===# - -# -# COFF File Definition -# - -def string_table_entry (offset): - 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' - -def symname(value): - parts = struct.unpack("<2L", value) - if parts[0] == 0: - return string_table_entry(parts[1]) - else: - return '%s' - -file = ('struct', [ - ('MachineType', ('enum', '> 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', ' 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]+") - -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 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) - 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 - -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 - -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 - -def handle_struct(entry): - 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): - 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): - 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 - -def handle_blob(entry): - 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) - -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) -finally: - Input.close() - Input = None diff --git a/test/Scripts/coff-dump.py.bat b/test/Scripts/coff-dump.py.bat deleted file mode 100755 index 56428e1a605..00000000000 --- a/test/Scripts/coff-dump.py.bat +++ /dev/null @@ -1,7 +0,0 @@ -@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\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 deleted file mode 100644 index fd58993c058..00000000000 --- a/test/Scripts/common_dump.py +++ /dev/null @@ -1,48 +0,0 @@ -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(valPair): - """ - 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, numBits = valPair - assert 0 <= val < (1 << numBits) - - 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 deleted file mode 100755 index 61342d8f98e..00000000000 --- a/test/Scripts/elf-dump +++ /dev/null @@ -1,285 +0,0 @@ -#!/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 - self.isN64 = False - - 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)), 8) - - def read16(self): - return (struct.unpack('><'[self.isLSB] + 'H', self.read(2))[0], 16) - - def read32(self): - return (struct.unpack('><'[self.isLSB] + 'I', self.read(4))[0], 32) - - def read64(self): - return (struct.unpack('><'[self.isLSB] + 'Q', self.read(8))[0], 64) - - def readWord(self): - if self.is64Bit: - return self.read64() - else: - return self.read32() - -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 ProgramHeader: - def __init__(self, f): - self.p_type = f.read32() - if f.is64Bit: - self.p_flags = f.read32() - self.p_offset = f.readWord() - self.p_vaddr = f.readWord() - self.p_paddr = f.readWord() - self.p_filesz = f.readWord() - self.p_memsz = f.readWord() - if not f.is64Bit: - self.p_flags = f.read32() - self.p_align = f.readWord() - - def dump(self): - print " (('p_type', %s)" % common_dump.HexDump(self.p_type) - print " ('p_flags', %s)" % common_dump.HexDump(self.p_flags) - print " ('p_offset', %s)" % common_dump.HexDump(self.p_offset) - print " ('p_vaddr', %s)" % common_dump.HexDump(self.p_vaddr) - print " ('p_paddr', %s)" % common_dump.HexDump(self.p_paddr) - print " ('p_filesz', %s)" % common_dump.HexDump(self.p_filesz) - print " ('p_memsz', %s)" % common_dump.HexDump(self.p_memsz) - print " ('p_align', %s)" % common_dump.HexDump(self.p_align) - print " )," - -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[0]] - 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[0] == 2: # SHT_SYMTAB - print " ('_symbols', [" - dumpSymtab(f, self, strtab) - print " ])" - elif self.sh_type[0] == 4 or self.sh_type[0] == 9: # SHT_RELA / SHT_REL - print " ('_relocations', [" - dumpRel(f, self, self.sh_type[0] == 4) - print " ])" - elif dumpdata: - f.seek(self.sh_offset[0]) - if self.sh_type != 8: # != SHT_NOBITS - data = f.read(self.sh_size[0]) - print " ('_section_data', '%s')" % common_dump.dataToHex(data) - else: - print " ('_section_data', '')" - print " )," - -def dumpSymtab(f, section, strtab): - entries = section.sh_size[0] // section.sh_entsize[0] - - for index in range(entries): - f.seek(section.sh_offset[0] + index * section.sh_entsize[0]) - print " # Symbol %s" % index - name = f.read32() - print " (('st_name', %s)" % common_dump.HexDump(name), "# %r" % strtab[name[0]] - 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()[0] - st_bind = (st_info >> 4, 4) - st_type = (st_info & 0xf, 4) - print " ('st_bind', %s)" % common_dump.HexDump(st_bind) - print " ('st_type', %s)" % common_dump.HexDump(st_type) - 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()) - print " ('st_size', %s)" % common_dump.HexDump(f.read64()) - print " )," - -def dumpRel(f, section, dumprela = False): - entries = section.sh_size[0] // section.sh_entsize[0] - - for index in range(entries): - f.seek(section.sh_offset[0] + index * section.sh_entsize[0]) - print " # Relocation %s" % index - print " (('r_offset', %s)" % common_dump.HexDump(f.readWord()) - - if f.isN64: - r_sym = f.read32() - r_ssym = f.read8() - r_type3 = f.read8() - r_type2 = f.read8() - r_type = f.read8() - print " ('r_sym', %s)" % common_dump.HexDump(r_sym) - print " ('r_ssym', %s)" % common_dump.HexDump(r_ssym) - print " ('r_type3', %s)" % common_dump.HexDump(r_type3) - print " ('r_type2', %s)" % common_dump.HexDump(r_type2) - print " ('r_type', %s)" % common_dump.HexDump(r_type) - else: - r_info = f.readWord()[0] - if f.is64Bit: - r_sym = (r_info >> 32, 32) - r_type = (r_info & 0xffffffff, 32) - else: - r_sym = (r_info >> 8, 24) - r_type = (r_info & 0xff, 8) - print " ('r_sym', %s)" % common_dump.HexDump(r_sym) - print " ('r_type', %s)" % common_dump.HexDump(r_type) - if dumprela: - print " ('r_addend', %s)" % common_dump.HexDump(f.readWord()) - print " )," - -def dumpELF(path, opts): - f = Reader(path) - - magic = f.read(4) - assert magic == '\x7FELF' - - fileclass = f.read8() - if fileclass[0] == 1: # ELFCLASS32 - f.is64Bit = False - elif fileclass[0] == 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[0] == 1: # ELFDATA2LSB - f.isLSB = True - elif byteordering[0] == 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()) - - # Does any other architecture use N64? - e_machine = f.read16() - if e_machine[0] == 0x0008 and f.is64Bit: # EM_MIPS && 64 bit - f.isN64 = True - - print "('e_machine', %s)" % common_dump.HexDump(e_machine) - print "('e_version', %s)" % common_dump.HexDump(f.read32()) - print "('e_entry', %s)" % common_dump.HexDump(f.readWord()) - e_phoff = f.readWord() - print "('e_phoff', %s)" % common_dump.HexDump(e_phoff) - 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()) - e_phentsize = f.read16() - print "('e_phentsize', %s)" % common_dump.HexDump(e_phentsize) - e_phnum = f.read16() - print "('e_phnum', %s)" % common_dump.HexDump(e_phnum) - 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[0]): - f.seek(e_shoff[0] + index * e_shentsize[0]) - s = Section(f) - sections.append(s) - - # Read .shstrtab so we can resolve section names - f.seek(sections[e_shstrndx[0]].sh_offset[0]) - shstrtab = StringTable(f.read(sections[e_shstrndx[0]].sh_size[0])) - - # Get the symbol string table - strtab = None - for section in sections: - if shstrtab[section.sh_name[0]] == ".strtab": - f.seek(section.sh_offset[0]) - strtab = StringTable(f.read(section.sh_size[0])) - break - - print "('_sections', [" - for index in range(e_shnum[0]): - print " # Section %s" % index - sections[index].dump(shstrtab, f, strtab, opts.dumpSectionData) - print "])" - - # Read all program headers - headers = [] - for index in range(e_phnum[0]): - f.seek(e_phoff[0] + index * e_phentsize[0]) - h = ProgramHeader(f) - headers.append(h) - - print "('_ProgramHeaders', [" - for index in range(e_phnum[0]): - print " # Program Header %s" % index - headers[index].dump() - 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 deleted file mode 100755 index 9c708083b30..00000000000 --- a/test/Scripts/elf-dump.bat +++ /dev/null @@ -1,7 +0,0 @@ -@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/ignore b/test/Scripts/ignore deleted file mode 100755 index 865ae4df1bd..00000000000 --- a/test/Scripts/ignore +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# -# Program: ignore -# -# Synopsis: Ignore the result code of the command and always return 0 -# -# Syntax: ignore command - -"$@" || exit 0 && exit 0 -exit 0 diff --git a/test/Scripts/macho-dumpx b/test/Scripts/macho-dumpx deleted file mode 100755 index 71e06d837b9..00000000000 --- a/test/Scripts/macho-dumpx +++ /dev/null @@ -1,294 +0,0 @@ -#!/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 - - self.string_table = None - - def tell(self): - return self.file.tell() - - 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): - # Force to 32-bit, if possible; otherwise these might be long ints on a - # big-endian platform. FIXME: Why??? - Value = struct.unpack('><'[self.isLSB] + 'I', self.read(4))[0] - return int(Value) - - def read64(self): - 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: - raise ValueError,"%s: warning: multiple string tables" % sys.argv[0] - - self.string_table = strings - - def getString(self, index): - if self.string_table is None: - raise ValueError,"%s: warning: no string table registered" % sys.argv[0] - - end = self.string_table.index('\x00', index) - return self.string_table[index:end] - -def dumpmacho(path, opts): - f = Reader(path) - - magic = f.read(4) - if magic == '\xFE\xED\xFA\xCE': - f.isLSB, f.is64Bit = False, False - elif magic == '\xCE\xFA\xED\xFE': - f.isLSB, f.is64Bit = True, False - elif magic == '\xFE\xED\xFA\xCF': - f.isLSB, f.is64Bit = False, True - elif magic == '\xCF\xFA\xED\xFE': - f.isLSB, f.is64Bit = True, True - else: - raise ValueError,"Not a Mach-O object file: %r (bad magic)" % path - - print "('cputype', %r)" % f.read32() - print "('cpusubtype', %r)" % f.read32() - filetype = f.read32() - print "('filetype', %r)" % filetype - - numLoadCommands = f.read32() - print "('num_load_commands', %r)" % numLoadCommands - - loadCommandsSize = f.read32() - print "('load_commands_size', %r)" % loadCommandsSize - - print "('flag', %r)" % f.read32() - - if f.is64Bit: - print "('reserved', %r)" % f.read32() - - start = f.tell() - - print "('load_commands', [" - for i in range(numLoadCommands): - dumpLoadCommand(f, i, opts) - print "])" - - if f.tell() - start != loadCommandsSize: - raise ValueError,"%s: warning: invalid load commands size: %r" % ( - sys.argv[0], loadCommandsSize) - -def dumpLoadCommand(f, i, opts): - start = f.tell() - - print " # Load Command %r" % i - cmd = f.read32() - print " (('command', %r)" % cmd - cmdSize = f.read32() - print " ('size', %r)" % cmdSize - - if cmd == 1: - dumpSegmentLoadCommand(f, opts, False) - elif cmd == 2: - dumpSymtabCommand(f, opts) - elif cmd == 11: - dumpDysymtabCommand(f, opts) - elif cmd == 25: - dumpSegmentLoadCommand(f, opts, True) - elif cmd == 27: - import uuid - print " ('uuid', %s)" % uuid.UUID(bytes=f.read(16)) - else: - print >>sys.stderr,"%s: warning: unknown load command: %r" % ( - sys.argv[0], cmd) - f.read(cmdSize - 8) - print " )," - - if f.tell() - start != cmdSize: - raise ValueError,"%s: warning: invalid load command size: %r" % ( - sys.argv[0], cmdSize) - -def dumpSegmentLoadCommand(f, opts, is64Bit): - print " ('segment_name', %r)" % f.read(16) - if is64Bit: - print " ('vm_addr', %r)" % f.read64() - print " ('vm_size', %r)" % f.read64() - print " ('file_offset', %r)" % f.read64() - print " ('file_size', %r)" % f.read64() - else: - print " ('vm_addr', %r)" % f.read32() - print " ('vm_size', %r)" % f.read32() - print " ('file_offset', %r)" % f.read32() - print " ('file_size', %r)" % f.read32() - print " ('maxprot', %r)" % f.read32() - print " ('initprot', %r)" % f.read32() - numSections = f.read32() - print " ('num_sections', %r)" % numSections - print " ('flags', %r)" % f.read32() - - print " ('sections', [" - for i in range(numSections): - dumpSection(f, i, opts, is64Bit) - print " ])" - -def dumpSymtabCommand(f, opts): - symoff = f.read32() - print " ('symoff', %r)" % symoff - nsyms = f.read32() - print " ('nsyms', %r)" % nsyms - stroff = f.read32() - print " ('stroff', %r)" % stroff - strsize = f.read32() - print " ('strsize', %r)" % strsize - - prev_pos = f.tell() - - f.seek(stroff) - string_data = f.read(strsize) - print " ('_string_data', %r)" % string_data - - f.registerStringTable(string_data) - - f.seek(symoff) - print " ('_symbols', [" - for i in range(nsyms): - dumpNlist32(f, i, opts) - print " ])" - - f.seek(prev_pos) - -def dumpNlist32(f, i, opts): - print " # Symbol %r" % i - n_strx = f.read32() - print " (('n_strx', %r)" % n_strx - n_type = f.read8() - print " ('n_type', %#x)" % n_type - n_sect = f.read8() - print " ('n_sect', %r)" % n_sect - n_desc = f.read16() - print " ('n_desc', %r)" % n_desc - if f.is64Bit: - n_value = f.read64() - print " ('n_value', %r)" % n_value - else: - n_value = f.read32() - print " ('n_value', %r)" % n_value - print " ('_string', %r)" % f.getString(n_strx) - print " )," - -def dumpDysymtabCommand(f, opts): - print " ('ilocalsym', %r)" % f.read32() - print " ('nlocalsym', %r)" % f.read32() - print " ('iextdefsym', %r)" % f.read32() - print " ('nextdefsym', %r)" % f.read32() - print " ('iundefsym', %r)" % f.read32() - print " ('nundefsym', %r)" % f.read32() - print " ('tocoff', %r)" % f.read32() - print " ('ntoc', %r)" % f.read32() - print " ('modtaboff', %r)" % f.read32() - print " ('nmodtab', %r)" % f.read32() - print " ('extrefsymoff', %r)" % f.read32() - print " ('nextrefsyms', %r)" % f.read32() - indirectsymoff = f.read32() - print " ('indirectsymoff', %r)" % indirectsymoff - nindirectsyms = f.read32() - print " ('nindirectsyms', %r)" % nindirectsyms - print " ('extreloff', %r)" % f.read32() - print " ('nextrel', %r)" % f.read32() - print " ('locreloff', %r)" % f.read32() - print " ('nlocrel', %r)" % f.read32() - - prev_pos = f.tell() - - f.seek(indirectsymoff) - print " ('_indirect_symbols', [" - for i in range(nindirectsyms): - print " # Indirect Symbol %r" % i - print " (('symbol_index', %#x),)," % f.read32() - print " ])" - - f.seek(prev_pos) - -def dumpSection(f, i, opts, is64Bit): - print " # Section %r" % i - print " (('section_name', %r)" % f.read(16) - print " ('segment_name', %r)" % f.read(16) - if is64Bit: - print " ('address', %r)" % f.read64() - size = f.read64() - print " ('size', %r)" % size - else: - print " ('address', %r)" % f.read32() - size = f.read32() - print " ('size', %r)" % size - offset = f.read32() - print " ('offset', %r)" % offset - print " ('alignment', %r)" % f.read32() - reloc_offset = f.read32() - print " ('reloc_offset', %r)" % reloc_offset - num_reloc = f.read32() - print " ('num_reloc', %r)" % num_reloc - print " ('flags', %#x)" % f.read32() - print " ('reserved1', %r)" % f.read32() - print " ('reserved2', %r)" % f.read32() - if is64Bit: - print " ('reserved3', %r)" % f.read32() - print " )," - - prev_pos = f.tell() - - f.seek(reloc_offset) - print " ('_relocations', [" - for i in range(num_reloc): - print " # Relocation %r" % i - print " (('word-0', %#x)," % f.read32() - print " ('word-1', %#x))," % f.read32() - print " ])" - - if opts.dumpSectionData: - f.seek(offset) - print " ('_section_data', '%s')" % common_dump.dataToHex(f.read(size)) - - f.seek(prev_pos) - -def 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: - dumpmacho(arg, opts) - -if __name__ == '__main__': - main() diff --git a/test/Scripts/macho-dumpx.bat b/test/Scripts/macho-dumpx.bat deleted file mode 100644 index 81484f67d70..00000000000 --- a/test/Scripts/macho-dumpx.bat +++ /dev/null @@ -1,7 +0,0 @@ -@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\macho-dump %1 %2 %3 %4 %5 %6 %7 %8 %9 - diff --git a/test/lit.cfg b/test/lit.cfg index ac18e50d99f..ea91f45754d 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -56,17 +56,8 @@ llvm_obj_root = getattr(config, 'llvm_obj_root', None) if llvm_obj_root is not None: config.test_exec_root = os.path.join(llvm_obj_root, 'test') -# Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin -# dir (if available). +# Tweak the PATH to include the tools dir. if llvm_obj_root is not None: - llvm_src_root = getattr(config, 'llvm_src_root', None) - if not llvm_src_root: - lit.fatal('No LLVM source root set!') - path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test', - 'Scripts'), - config.environment['PATH'])) - config.environment['PATH'] = path - llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) if not llvm_tools_dir: lit.fatal('No LLVM tools dir set!') -- 2.34.1