Remove obsolete object file dumpers

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179362 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nico Rieck 2013-04-12 04:07:13 +00:00
parent f89da7210b
commit 7e87373e91
11 changed files with 2 additions and 1261 deletions

View File

@ -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

View File

@ -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.

View File

@ -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', '<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')),
])))),
])
#
# Definition Interpreter
#
import sys, types, struct, re
Input = None
Stack = []
Fields = {}
Indent = 0
NewLine = True
def indent():
global Indent
Indent += 1
def dedent():
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)
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
def push_pos(seek_to = None):
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]
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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -1,10 +0,0 @@
#!/bin/sh
#
# Program: ignore
#
# Synopsis: Ignore the result code of the command and always return 0
#
# Syntax: ignore command <arguments>
"$@" || exit 0 && exit 0
exit 0

View File

@ -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()

View File

@ -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

View File

@ -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!')