summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-11-27 13:46:11 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-11-27 13:46:11 +0000
commitf2e2a5ff04e13720cec0c130c1d88d81d0ae6007 (patch)
treed8a06360956446e828600dd653fd69aa5ecdddc4
parent90e3e3a429e75a7d3671afcc30ed376b6186fd58 (diff)
downloadllvm-f2e2a5ff04e13720cec0c130c1d88d81d0ae6007.tar.gz
llvm-f2e2a5ff04e13720cec0c130c1d88d81d0ae6007.tar.bz2
llvm-f2e2a5ff04e13720cec0c130c1d88d81d0ae6007.tar.xz
macho-dump: Add support for dumping string table data.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120217 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Object/MachOObject.h17
-rw-r--r--lib/Object/MachOObject.cpp8
-rw-r--r--tools/macho-dump/macho-dump.cpp8
3 files changed, 32 insertions, 1 deletions
diff --git a/include/llvm/Object/MachOObject.h b/include/llvm/Object/MachOObject.h
index 53c7abf34a..836e5491d2 100644
--- a/include/llvm/Object/MachOObject.h
+++ b/include/llvm/Object/MachOObject.h
@@ -13,6 +13,7 @@
#include <string>
#include "llvm/ADT/InMemoryStruct.h"
#include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Object/MachOFormat.h"
namespace llvm {
@@ -59,6 +60,8 @@ private:
bool Is64Bit;
/// Whether the object is swapped endianness from the host.
bool IsSwappedEndian;
+ /// Whether the string table has been registered.
+ bool HasStringTable;
/// The cached information on the load commands.
LoadCommandInfo *LoadCommands;
@@ -68,6 +71,9 @@ private:
macho::Header Header;
macho::Header64Ext Header64Ext;
+ /// Cache string table information.
+ StringRef StringTable;
+
private:
MachOObject(MemoryBuffer *Buffer, bool IsLittleEndian, bool Is64Bit);
@@ -97,6 +103,17 @@ public:
}
/// @}
+ /// @name String Table Data
+ /// @{
+
+ StringRef getStringTableData() const {
+ assert(HasStringTable && "String table has not been registered!");
+ return StringTable;
+ }
+
+ void RegisterStringTable(macho::SymtabLoadCommand &SLC);
+
+ /// @}
/// @name Object Header Access
/// @{
diff --git a/lib/Object/MachOObject.cpp b/lib/Object/MachOObject.cpp
index f5bc73ada7..45c9bff45f 100644
--- a/lib/Object/MachOObject.cpp
+++ b/lib/Object/MachOObject.cpp
@@ -57,7 +57,7 @@ MachOObject::MachOObject(MemoryBuffer *Buffer_, bool IsLittleEndian_,
bool Is64Bit_)
: Buffer(Buffer_), IsLittleEndian(IsLittleEndian_), Is64Bit(Is64Bit_),
IsSwappedEndian(IsLittleEndian != sys::isLittleEndianHost()),
- LoadCommands(0), NumLoadedCommands(0) {
+ HasStringTable(false), LoadCommands(0), NumLoadedCommands(0) {
// Load the common header.
memcpy(&Header, Buffer->getBuffer().data(), sizeof(Header));
if (IsSwappedEndian) {
@@ -125,6 +125,12 @@ MachOObject *MachOObject::LoadFromBuffer(MemoryBuffer *Buffer,
return Object.take();
}
+void MachOObject::RegisterStringTable(macho::SymtabLoadCommand &SLC) {
+ HasStringTable = true;
+ StringTable = Buffer->getBuffer().substr(SLC.StringTableOffset,
+ SLC.StringTableSize);
+}
+
const MachOObject::LoadCommandInfo &
MachOObject::getLoadCommandInfo(unsigned Index) const {
assert(Index < getHeader().NumLoadCommands && "Invalid index!");
diff --git a/tools/macho-dump/macho-dump.cpp b/tools/macho-dump/macho-dump.cpp
index 274c41bd25..e2a8ef136e 100644
--- a/tools/macho-dump/macho-dump.cpp
+++ b/tools/macho-dump/macho-dump.cpp
@@ -213,6 +213,14 @@ static int DumpSymtabCommand(MachOObject &Obj,
outs() << " ('stroff', " << SLC->StringTableOffset << ")\n";
outs() << " ('strsize', " << SLC->StringTableSize << ")\n";
+ // Cache the string table data.
+ Obj.RegisterStringTable(*SLC);
+
+ // Dump the string data.
+ outs() << " ('_string_data', '";
+ outs().write_escaped(Obj.getStringTableData(),
+ /*UseHexEscapes=*/true) << "')\n";
+
return 0;
}