summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-11-27 13:58:16 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-11-27 13:58:16 +0000
commit71130f8aa1cef096083b95267a8a688a3bef6426 (patch)
tree8e59931bc6a7906b72e98e26f832a55039361bf2
parent2208b58b83392b2a3558e556c7447b13c3aea857 (diff)
macho-dump: Add support for --dump-section-data and tweak a few format strings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120219 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Object/MachOObject.h2
-rw-r--r--lib/Object/MachOObject.cpp4
-rw-r--r--tools/macho-dump/macho-dump.cpp24
3 files changed, 25 insertions, 5 deletions
diff --git a/include/llvm/Object/MachOObject.h b/include/llvm/Object/MachOObject.h
index 6c0a1d0cad0..03d9c147b41 100644
--- a/include/llvm/Object/MachOObject.h
+++ b/include/llvm/Object/MachOObject.h
@@ -102,6 +102,8 @@ public:
return Is64Bit ? macho::Header64Size : macho::Header32Size;
}
+ StringRef getData(size_t Offset, size_t Size) const;
+
/// @}
/// @name String Table Data
/// @{
diff --git a/lib/Object/MachOObject.cpp b/lib/Object/MachOObject.cpp
index 33890f6617a..1051ce27fa0 100644
--- a/lib/Object/MachOObject.cpp
+++ b/lib/Object/MachOObject.cpp
@@ -125,6 +125,10 @@ MachOObject *MachOObject::LoadFromBuffer(MemoryBuffer *Buffer,
return Object.take();
}
+StringRef MachOObject::getData(size_t Offset, size_t Size) const {
+ return Buffer->getBuffer().substr(Offset,Size);
+}
+
void MachOObject::RegisterStringTable(macho::SymtabLoadCommand &SLC) {
HasStringTable = true;
StringTable = Buffer->getBuffer().substr(SLC.StringTableOffset,
diff --git a/tools/macho-dump/macho-dump.cpp b/tools/macho-dump/macho-dump.cpp
index abe06f4f4dc..02fa36680f8 100644
--- a/tools/macho-dump/macho-dump.cpp
+++ b/tools/macho-dump/macho-dump.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Object/MachOObject.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Format.h"
@@ -101,7 +102,7 @@ static int DumpSectionData(MachOObject &Obj, unsigned Index, StringRef Name,
outs() << " ('alignment', " << Align << ")\n";
outs() << " ('reloc_offset', " << RelocationTableOffset << ")\n";
outs() << " ('num_reloc', " << NumRelocationTableEntries << ")\n";
- outs() << " ('flags', " << format("%#x", Flags) << ")\n";
+ outs() << " ('flags', " << format("0x%x", Flags) << ")\n";
outs() << " ('reserved1', " << Reserved1 << ")\n";
outs() << " ('reserved2', " << Reserved2 << ")\n";
if (Reserved3 != ~0ULL)
@@ -120,11 +121,24 @@ static int DumpSectionData(MachOObject &Obj, unsigned Index, StringRef Name,
}
outs() << " # Relocation " << i << "\n";
- outs() << " (('word-0', " << format("%#x", RE->Word0) << "),\n";
- outs() << " ('word-1', " << format("%#x", RE->Word1) << ")),\n";
+ outs() << " (('word-0', " << format("0x%x", RE->Word0) << "),\n";
+ outs() << " ('word-1', " << format("0x%x", RE->Word1) << ")),\n";
}
outs() << " ])\n";
+ // Dump the section data, if requested.
+ if (ShowSectionData) {
+ outs() << " ('_section_data', '";
+ StringRef Data = Obj.getData(Offset, Size);
+ for (unsigned i = 0; i != Data.size(); ++i) {
+ if (i && (i % 4) == 0)
+ outs() << ' ';
+ outs() << hexdigit((Data[i] >> 4) & 0xF, /*LowerCase=*/true);
+ outs() << hexdigit((Data[i] >> 0) & 0xF, /*LowerCase=*/true);
+ }
+ outs() << "')\n";
+ }
+
return Res;
}
@@ -207,7 +221,7 @@ static void DumpSymbolTableEntryData(MachOObject &Obj,
uint16_t Flags, uint64_t Value) {
outs() << " # Symbol " << Index << "\n";
outs() << " (('n_strx', " << StringIndex << ")\n";
- outs() << " ('n_type', " << format("%#x", Type) << ")\n";
+ outs() << " ('n_type', " << format("0x%x", Type) << ")\n";
outs() << " ('n_sect', " << uint32_t(SectionIndex) << ")\n";
outs() << " ('n_desc', " << Flags << ")\n";
outs() << " ('n_value', " << Value << ")\n";
@@ -307,7 +321,7 @@ static int DumpDysymtabCommand(MachOObject &Obj,
outs() << " # Indirect Symbol " << i << "\n";
outs() << " (('symbol_index', "
- << format("%#x", ISTE->Index) << "),),\n";
+ << format("0x%x", ISTE->Index) << "),),\n";
}
outs() << " ])\n";