[llvm-commits] [llvm] r120219 - in /llvm/trunk: include/llvm/Object/MachOObject.h lib/Object/MachOObject.cpp tools/macho-dump/macho-dump.cpp
Daniel Dunbar
daniel at zuster.org
Sat Nov 27 05:58:16 PST 2010
Author: ddunbar
Date: Sat Nov 27 07:58:16 2010
New Revision: 120219
URL: http://llvm.org/viewvc/llvm-project?rev=120219&view=rev
Log:
macho-dump: Add support for --dump-section-data and tweak a few format strings.
Modified:
llvm/trunk/include/llvm/Object/MachOObject.h
llvm/trunk/lib/Object/MachOObject.cpp
llvm/trunk/tools/macho-dump/macho-dump.cpp
Modified: llvm/trunk/include/llvm/Object/MachOObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOObject.h?rev=120219&r1=120218&r2=120219&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOObject.h (original)
+++ llvm/trunk/include/llvm/Object/MachOObject.h Sat Nov 27 07:58:16 2010
@@ -102,6 +102,8 @@
return Is64Bit ? macho::Header64Size : macho::Header32Size;
}
+ StringRef getData(size_t Offset, size_t Size) const;
+
/// @}
/// @name String Table Data
/// @{
Modified: llvm/trunk/lib/Object/MachOObject.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObject.cpp?rev=120219&r1=120218&r2=120219&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObject.cpp (original)
+++ llvm/trunk/lib/Object/MachOObject.cpp Sat Nov 27 07:58:16 2010
@@ -125,6 +125,10 @@
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,
Modified: llvm/trunk/tools/macho-dump/macho-dump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/macho-dump/macho-dump.cpp?rev=120219&r1=120218&r2=120219&view=diff
==============================================================================
--- llvm/trunk/tools/macho-dump/macho-dump.cpp (original)
+++ llvm/trunk/tools/macho-dump/macho-dump.cpp Sat Nov 27 07:58:16 2010
@@ -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 @@
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 @@
}
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 @@
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 @@
outs() << " # Indirect Symbol " << i << "\n";
outs() << " (('symbol_index', "
- << format("%#x", ISTE->Index) << "),),\n";
+ << format("0x%x", ISTE->Index) << "),),\n";
}
outs() << " ])\n";
More information about the llvm-commits
mailing list