From 6c2e2d1c6b29534e99630fedbaa5e39652258449 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 26 Aug 2009 13:57:44 +0000 Subject: [PATCH] llvm-mc/Mach-O: Dump relocations and section data (optionally) in my Mach-O dumper. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80087 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Scripts/macho-dump | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/test/Scripts/macho-dump b/test/Scripts/macho-dump index 800015ec825..12ec26d4589 100755 --- a/test/Scripts/macho-dump +++ b/test/Scripts/macho-dump @@ -208,20 +208,42 @@ def dumpSection32(f, i, opts): print " (('section_name', %r)" % f.read(16) print " ('segment_name', %r)" % f.read(16) print " ('address', %r)" % f.read32() - print " ('size', %r)" % f.read32() - print " ('offset', %r)" % f.read32() - print " ('alignment', %r)" % f.read32() - print " ('reloc_offset', %r)" % f.read32() - print " ('num_reloc', %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() 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', %r)" % 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: