summaryrefslogtreecommitdiffstats
path: root/test/Scripts
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2011-10-20 21:10:27 +0000
committerdim <dim@FreeBSD.org>2011-10-20 21:10:27 +0000
commit7b3392326c40c3c20697816acae597ba7b3144eb (patch)
tree2cbcf22585e99f8a87d12d5ff94f392c0d266819 /test/Scripts
parent1176aa52646fe641a4243a246aa7f960c708a274 (diff)
downloadFreeBSD-src-7b3392326c40c3c20697816acae597ba7b3144eb.zip
FreeBSD-src-7b3392326c40c3c20697816acae597ba7b3144eb.tar.gz
Vendor import of llvm release_30 branch r142614:
http://llvm.org/svn/llvm-project/llvm/branches/release_30@142614
Diffstat (limited to 'test/Scripts')
-rw-r--r--test/Scripts/common_dump.py6
-rwxr-xr-xtest/Scripts/elf-dump98
2 files changed, 49 insertions, 55 deletions
diff --git a/test/Scripts/common_dump.py b/test/Scripts/common_dump.py
index 3d69c3f..fd58993 100644
--- a/test/Scripts/common_dump.py
+++ b/test/Scripts/common_dump.py
@@ -31,7 +31,7 @@ def dataToHexUnified(d):
return ''.join(bytes).strip()
-def HexDump(val, numBits=32):
+def HexDump(valPair):
"""
1. do not print 'L'
2. Handle negatives and large numbers by mod (2^numBits)
@@ -40,7 +40,9 @@ def HexDump(val, numBits=32):
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
index 76cdbf9..58ca177 100755
--- a/test/Scripts/elf-dump
+++ b/test/Scripts/elf-dump
@@ -26,22 +26,16 @@ class Reader:
return data
def read8(self):
- return ord(self.read(1))
+ return (ord(self.read(1)), 8)
def read16(self):
- return struct.unpack('><'[self.isLSB] + 'H', self.read(2))[0]
+ return (struct.unpack('><'[self.isLSB] + 'H', self.read(2))[0], 16)
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]
+ return (struct.unpack('><'[self.isLSB] + 'I', self.read(4))[0], 32)
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]
+ return (struct.unpack('><'[self.isLSB] + 'Q', self.read(8))[0], 64)
def readWord(self):
if self.is64Bit:
@@ -49,12 +43,6 @@ class Reader:
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
@@ -77,7 +65,7 @@ class Section:
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_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)
@@ -87,60 +75,64 @@ class Section:
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
+ if self.sh_type[0] == 2: # SHT_SYMTAB
print " ('_symbols', ["
dumpSymtab(f, self, strtab)
print " ])"
- elif self.sh_type == 4 or self.sh_type == 9: # SHT_RELA / SHT_REL
+ elif self.sh_type[0] == 4 or self.sh_type[0] == 9: # SHT_RELA / SHT_REL
print " ('_relocations', ["
- dumpRel(f, self, self.sh_type == 4)
+ dumpRel(f, self, self.sh_type[0] == 4)
print " ])"
elif dumpdata:
- f.seek(self.sh_offset)
+ f.seek(self.sh_offset[0])
if self.sh_type != 8: # != SHT_NOBITS
- data = f.read(self.sh_size)
+ 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 // section.sh_entsize
+ entries = section.sh_size[0] // section.sh_entsize[0]
for index in range(entries):
- f.seek(section.sh_offset + index * section.sh_entsize)
- print " # Symbol %s" % common_dump.HexDump(index)
+ 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]
+ 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()
- print " ('st_bind', %s)" % common_dump.HexDump((st_info >> 4))
- print " ('st_type', %s)" % common_dump.HexDump((st_info & 0xf))
+ 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(), 64)
- print " ('st_size', %s)" % common_dump.HexDump(f.read64(), 64)
+ 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 // section.sh_entsize
+ entries = section.sh_size[0] // section.sh_entsize[0]
for index in range(entries):
- f.seek(section.sh_offset + index * section.sh_entsize)
- print " # Relocation %s" % common_dump.HexDump(index)
+ f.seek(section.sh_offset[0] + index * section.sh_entsize[0])
+ print " # Relocation %s" % index
print " (('r_offset', %s)" % common_dump.HexDump(f.readWord())
- r_info = f.readWord()
+ r_info = f.readWord()[0]
if f.is64Bit:
- print " ('r_sym', %s)" % common_dump.HexDump((r_info >> 32))
- print " ('r_type', %s)" % common_dump.HexDump((r_info & 0xffffffff))
+ r_sym = (r_info >> 32, 32)
+ r_type = (r_info & 0xffffffff, 32)
else:
- print " ('r_sym', %s)" % common_dump.HexDump((r_info >> 8))
- print " ('r_type', %s)" % common_dump.HexDump((r_info & 0xff))
+ 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.readWordS())
+ print " ('r_addend', %s)" % common_dump.HexDump(f.readWord())
print " ),"
def dumpELF(path, opts):
@@ -150,18 +142,18 @@ def dumpELF(path, opts):
assert magic == '\x7FELF'
fileclass = f.read8()
- if fileclass == 1: # ELFCLASS32
+ if fileclass[0] == 1: # ELFCLASS32
f.is64Bit = False
- elif fileclass == 2: # ELFCLASS64
+ 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 == 1: # ELFDATA2LSB
+ if byteordering[0] == 1: # ELFDATA2LSB
f.isLSB = True
- elif byteordering == 2: # ELFDATA2MSB
+ elif byteordering[0] == 2: # ELFDATA2MSB
f.isLSB = False
else:
raise ValueError, "Unknown byte ordering %s" % common_dump.HexDump(byteordering)
@@ -193,26 +185,26 @@ def dumpELF(path, opts):
# Read all section headers
sections = []
- for index in range(e_shnum):
- f.seek(e_shoff + index * e_shentsize)
+ 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].sh_offset)
- shstrtab = StringTable(f.read(sections[e_shstrndx].sh_size))
+ 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] == ".strtab":
- f.seek(section.sh_offset)
- strtab = StringTable(f.read(section.sh_size))
+ 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):
- print " # Section %s" % common_dump.HexDump(index)
+ for index in range(e_shnum[0]):
+ print " # Section %s" % index
sections[index].dump(shstrtab, f, strtab, opts.dumpSectionData)
print "])"
OpenPOWER on IntegriCloud