aboutsummaryrefslogtreecommitdiff
path: root/tools/macho-dump
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-11-27 13:52:53 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-11-27 13:52:53 +0000
commit2208b58b83392b2a3558e556c7447b13c3aea857 (patch)
tree163b3d8177447a47d2f2193a44fb90a51e6c1b13 /tools/macho-dump
parentf2e2a5ff04e13720cec0c130c1d88d81d0ae6007 (diff)
macho-dump: Add support for dumping symbol table entries.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120218 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/macho-dump')
-rw-r--r--tools/macho-dump/macho-dump.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/tools/macho-dump/macho-dump.cpp b/tools/macho-dump/macho-dump.cpp
index e2a8ef136e..abe06f4f4d 100644
--- a/tools/macho-dump/macho-dump.cpp
+++ b/tools/macho-dump/macho-dump.cpp
@@ -201,6 +201,20 @@ static int DumpSegment64Command(MachOObject &Obj,
return 0;
}
+static void DumpSymbolTableEntryData(MachOObject &Obj,
+ unsigned Index, uint32_t StringIndex,
+ uint8_t Type, uint8_t SectionIndex,
+ uint16_t Flags, uint64_t Value) {
+ outs() << " # Symbol " << Index << "\n";
+ outs() << " (('n_strx', " << StringIndex << ")\n";
+ outs() << " ('n_type', " << format("%#x", Type) << ")\n";
+ outs() << " ('n_sect', " << uint32_t(SectionIndex) << ")\n";
+ outs() << " ('n_desc', " << Flags << ")\n";
+ outs() << " ('n_value', " << Value << ")\n";
+ outs() << " ('_string', '" << Obj.getStringAtIndex(StringIndex) << "')\n";
+ outs() << " ),\n";
+}
+
static int DumpSymtabCommand(MachOObject &Obj,
const MachOObject::LoadCommandInfo &LCI) {
InMemoryStruct<macho::SymtabLoadCommand> SLC;
@@ -221,7 +235,35 @@ static int DumpSymtabCommand(MachOObject &Obj,
outs().write_escaped(Obj.getStringTableData(),
/*UseHexEscapes=*/true) << "')\n";
- return 0;
+ // Dump the symbol table.
+ int Res = 0;
+ outs() << " ('_symbols', [\n";
+ for (unsigned i = 0; i != SLC->NumSymbolTableEntries; ++i) {
+ if (Obj.is64Bit()) {
+ InMemoryStruct<macho::Symbol64TableEntry> STE;
+ Obj.ReadSymbol64TableEntry(SLC->SymbolTableOffset, i, STE);
+ if (!STE) {
+ Res = Error("unable to read symbol: '" + Twine(i) + "'");
+ break;
+ }
+
+ DumpSymbolTableEntryData(Obj, i, STE->StringIndex, STE->Type,
+ STE->SectionIndex, STE->Flags, STE->Value);
+ } else {
+ InMemoryStruct<macho::SymbolTableEntry> STE;
+ Obj.ReadSymbolTableEntry(SLC->SymbolTableOffset, i, STE);
+ if (!SLC) {
+ Res = Error("unable to read symbol: '" + Twine(i) + "'");
+ break;
+ }
+
+ DumpSymbolTableEntryData(Obj, i, STE->StringIndex, STE->Type,
+ STE->SectionIndex, STE->Flags, STE->Value);
+ }
+ }
+ outs() << " ])\n";
+
+ return Res;
}
static int DumpDysymtabCommand(MachOObject &Obj,