From 2208b58b83392b2a3558e556c7447b13c3aea857 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sat, 27 Nov 2010 13:52:53 +0000 Subject: 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 --- tools/macho-dump/macho-dump.cpp | 44 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'tools/macho-dump') 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 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 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 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, -- cgit v1.2.3