From 663cebc4ad5ac5ad77ac051cbb925a126bba2c23 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 31 Dec 2012 15:27:42 +0000 Subject: Style fixes in llvm-readobj.cpp. Extracted from a patch by Sami Liedes! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171299 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/llvm-readobj.cpp | 46 +++++++++++++++---------------------- 1 file changed, 18 insertions(+), 28 deletions(-) (limited to 'tools/llvm-readobj/llvm-readobj.cpp') diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index 40e3b8c933..a30b0a8a57 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -33,17 +33,7 @@ using namespace llvm::object; static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("")); -void DumpSymbolHeader() { - outs() << format(" %-32s", (const char*)"Name") - << format(" %-4s", (const char*)"Type") - << format(" %-16s", (const char*)"Address") - << format(" %-16s", (const char*)"Size") - << format(" %-16s", (const char*)"FileOffset") - << format(" %-26s", (const char*)"Flags") - << "\n"; -} - -const char *GetTypeStr(SymbolRef::Type Type) { +static const char *getTypeStr(SymbolRef::Type Type) { switch (Type) { case SymbolRef::ST_Unknown: return "?"; case SymbolRef::ST_Data: return "DATA"; @@ -55,7 +45,7 @@ const char *GetTypeStr(SymbolRef::Type Type) { return "INV"; } -std::string GetFlagStr(uint32_t Flags) { +static std::string getSymbolFlagStr(uint32_t Flags) { std::string result; if (Flags & SymbolRef::SF_Undefined) result += "undef,"; @@ -79,7 +69,8 @@ std::string GetFlagStr(uint32_t Flags) { return result; } -void DumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) { +static void +dumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) { StringRef Name; SymbolRef::Type Type; uint32_t Flags; @@ -108,24 +99,23 @@ void DumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) { // format() can't handle StringRefs outs() << format(" %-32s", FullName.c_str()) - << format(" %-4s", GetTypeStr(Type)) + << format(" %-4s", getTypeStr(Type)) << format(" %16" PRIx64, Address) << format(" %16" PRIx64, Size) << format(" %16" PRIx64, FileOffset) - << " " << GetFlagStr(Flags) + << " " << getSymbolFlagStr(Flags) << "\n"; } - // Iterate through the normal symbols in the ObjectFile -void DumpSymbols(const ObjectFile *obj) { +static void dumpSymbols(const ObjectFile *obj) { error_code ec; uint32_t count = 0; outs() << "Symbols:\n"; symbol_iterator it = obj->begin_symbols(); symbol_iterator ie = obj->end_symbols(); while (it != ie) { - DumpSymbol(*it, obj, false); + dumpSymbol(*it, obj, false); it.increment(ec); if (ec) report_fatal_error("Symbol iteration failed"); @@ -135,14 +125,14 @@ void DumpSymbols(const ObjectFile *obj) { } // Iterate through the dynamic symbols in the ObjectFile. -void DumpDynamicSymbols(const ObjectFile *obj) { +static void dumpDynamicSymbols(const ObjectFile *obj) { error_code ec; uint32_t count = 0; outs() << "Dynamic Symbols:\n"; symbol_iterator it = obj->begin_dynamic_symbols(); symbol_iterator ie = obj->end_dynamic_symbols(); while (it != ie) { - DumpSymbol(*it, obj, true); + dumpSymbol(*it, obj, true); it.increment(ec); if (ec) report_fatal_error("Symbol iteration failed"); @@ -151,21 +141,21 @@ void DumpDynamicSymbols(const ObjectFile *obj) { outs() << " Total: " << count << "\n\n"; } -void DumpLibrary(const LibraryRef &lib) { +static void dumpLibrary(const LibraryRef &lib) { StringRef path; lib.getPath(path); outs() << " " << path << "\n"; } // Iterate through needed libraries -void DumpLibrariesNeeded(const ObjectFile *obj) { +static void dumpLibrariesNeeded(const ObjectFile *obj) { error_code ec; uint32_t count = 0; library_iterator it = obj->begin_libraries_needed(); library_iterator ie = obj->end_libraries_needed(); outs() << "Libraries needed:\n"; while (it != ie) { - DumpLibrary(*it); + dumpLibrary(*it); it.increment(ec); if (ec) report_fatal_error("Needed libraries iteration failed"); @@ -174,7 +164,7 @@ void DumpLibrariesNeeded(const ObjectFile *obj) { outs() << " Total: " << count << "\n\n"; } -void DumpHeaders(const ObjectFile *obj) { +static void dumpHeaders(const ObjectFile *obj) { outs() << "File Format : " << obj->getFileFormatName() << "\n"; outs() << "Arch : " << Triple::getArchTypeName((llvm::Triple::ArchType)obj->getArch()) @@ -209,10 +199,10 @@ int main(int argc, char** argv) { errs() << InputFilename << ": Object type not recognized\n"; } - DumpHeaders(obj); - DumpSymbols(obj); - DumpDynamicSymbols(obj); - DumpLibrariesNeeded(obj); + dumpHeaders(obj); + dumpSymbols(obj); + dumpDynamicSymbols(obj); + dumpLibrariesNeeded(obj); return 0; } -- cgit v1.2.3-70-g09d2 From 1318e14f3e9d786ea108d99ecaee7b5baa9b8fd0 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 31 Dec 2012 15:30:58 +0000 Subject: Fix indentation. Extracted from a patch by Sami Liedes! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171300 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/llvm-readobj.cpp | 64 ++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'tools/llvm-readobj/llvm-readobj.cpp') diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index a30b0a8a57..252a37798c 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -71,40 +71,40 @@ static std::string getSymbolFlagStr(uint32_t Flags) { static void dumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) { - StringRef Name; - SymbolRef::Type Type; - uint32_t Flags; - uint64_t Address; - uint64_t Size; - uint64_t FileOffset; - Sym.getName(Name); - Sym.getAddress(Address); - Sym.getSize(Size); - Sym.getFileOffset(FileOffset); - Sym.getType(Type); - Sym.getFlags(Flags); - std::string FullName = Name; - - // If this is a dynamic symbol from an ELF object, append - // the symbol's version to the name. - if (IsDynamic && obj->isELF()) { - StringRef Version; - bool IsDefault; - GetELFSymbolVersion(obj, Sym, Version, IsDefault); - if (!Version.empty()) { - FullName += (IsDefault ? "@@" : "@"); - FullName += Version; - } + StringRef Name; + SymbolRef::Type Type; + uint32_t Flags; + uint64_t Address; + uint64_t Size; + uint64_t FileOffset; + Sym.getName(Name); + Sym.getAddress(Address); + Sym.getSize(Size); + Sym.getFileOffset(FileOffset); + Sym.getType(Type); + Sym.getFlags(Flags); + std::string FullName = Name; + + // If this is a dynamic symbol from an ELF object, append + // the symbol's version to the name. + if (IsDynamic && obj->isELF()) { + StringRef Version; + bool IsDefault; + GetELFSymbolVersion(obj, Sym, Version, IsDefault); + if (!Version.empty()) { + FullName += (IsDefault ? "@@" : "@"); + FullName += Version; } + } - // format() can't handle StringRefs - outs() << format(" %-32s", FullName.c_str()) - << format(" %-4s", getTypeStr(Type)) - << format(" %16" PRIx64, Address) - << format(" %16" PRIx64, Size) - << format(" %16" PRIx64, FileOffset) - << " " << getSymbolFlagStr(Flags) - << "\n"; + // format() can't handle StringRefs + outs() << format(" %-32s", FullName.c_str()) + << format(" %-4s", getTypeStr(Type)) + << format(" %16" PRIx64, Address) + << format(" %16" PRIx64, Size) + << format(" %16" PRIx64, FileOffset) + << " " << getSymbolFlagStr(Flags) + << "\n"; } // Iterate through the normal symbols in the ObjectFile -- cgit v1.2.3-70-g09d2 From ad784790ad28023ef5041beac6c23a8250778f3f Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 31 Dec 2012 15:45:31 +0000 Subject: Check for errors. Extracted from a patch by Sami Liedes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171301 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/llvm-readobj.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'tools/llvm-readobj/llvm-readobj.cpp') diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index 252a37798c..8f8804a7c4 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -69,6 +69,11 @@ static std::string getSymbolFlagStr(uint32_t Flags) { return result; } +static void checkError(error_code ec, const char *msg) { + if (ec) + report_fatal_error(std::string(msg) + ": " + ec.message()); +} + static void dumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) { StringRef Name; @@ -77,12 +82,13 @@ dumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) { uint64_t Address; uint64_t Size; uint64_t FileOffset; - Sym.getName(Name); - Sym.getAddress(Address); - Sym.getSize(Size); - Sym.getFileOffset(FileOffset); - Sym.getType(Type); - Sym.getFlags(Flags); + checkError(Sym.getName(Name), "SymbolRef.getName() failed"); + checkError(Sym.getAddress(Address), "SymbolRef.getAddress() failed"); + checkError(Sym.getSize(Size), "SymbolRef.getSize() failed"); + checkError(Sym.getFileOffset(FileOffset), + "SymbolRef.getFileOffset() failed"); + checkError(Sym.getType(Type), "SymbolRef.getType() failed"); + checkError(Sym.getFlags(Flags), "SymbolRef.getFlags() failed"); std::string FullName = Name; // If this is a dynamic symbol from an ELF object, append -- cgit v1.2.3-70-g09d2 From 148ee4f224be6448834bf039807c70bb1a7c78f5 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 31 Dec 2012 16:05:21 +0000 Subject: Print a header above the symbols. Extracted from a patch by Sami Liedes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171302 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Object/readobj-shared-object.test | 2 ++ tools/llvm-readobj/llvm-readobj.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) (limited to 'tools/llvm-readobj/llvm-readobj.cpp') diff --git a/test/Object/readobj-shared-object.test b/test/Object/readobj-shared-object.test index 3b5457ce07..8d9b179002 100644 --- a/test/Object/readobj-shared-object.test +++ b/test/Object/readobj-shared-object.test @@ -19,6 +19,7 @@ ELF32:Address Size: 32 bits ELF32:Load Name : libfoo.so ELF:Symbols: +ELF: Name Type Address Size FileOffset Flags ELF: .dynsym DBG {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} formatspecific ELF: .dynstr DBG {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} formatspecific ELF: .text DBG {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} formatspecific @@ -42,6 +43,7 @@ ELF: _edata ? {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0- ELF: Total: 21 ELF:Dynamic Symbols: +ELF: Name Type Address Size FileOffset Flags ELF: common_sym DATA {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} global ELF: tls_sym DATA {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} global,threadlocal ELF: defined_sym DATA {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} global diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index 8f8804a7c4..81d2bfb730 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -33,6 +33,16 @@ using namespace llvm::object; static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("")); +static void dumpSymbolHeader() { + outs() << format(" %-32s", (const char*)"Name") + << format(" %-4s", (const char*)"Type") + << format(" %-16s", (const char*)"Address") + << format(" %-16s", (const char*)"Size") + << format(" %-16s", (const char*)"FileOffset") + << format(" %-26s", (const char*)"Flags") + << "\n"; +} + static const char *getTypeStr(SymbolRef::Type Type) { switch (Type) { case SymbolRef::ST_Unknown: return "?"; @@ -118,6 +128,7 @@ static void dumpSymbols(const ObjectFile *obj) { error_code ec; uint32_t count = 0; outs() << "Symbols:\n"; + dumpSymbolHeader(); symbol_iterator it = obj->begin_symbols(); symbol_iterator ie = obj->end_symbols(); while (it != ie) { @@ -135,6 +146,7 @@ static void dumpDynamicSymbols(const ObjectFile *obj) { error_code ec; uint32_t count = 0; outs() << "Dynamic Symbols:\n"; + dumpSymbolHeader(); symbol_iterator it = obj->begin_dynamic_symbols(); symbol_iterator ie = obj->end_dynamic_symbols(); while (it != ie) { -- cgit v1.2.3-70-g09d2 From fc73847d8fa79d310b26b7a80275dc48755ec2e3 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 31 Dec 2012 16:29:44 +0000 Subject: Dump sections. Extracted from a patch by Sami Liedes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171304 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Object/readobj-shared-object.test | 18 ++++++++ tools/llvm-readobj/llvm-readobj.cpp | 76 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) (limited to 'tools/llvm-readobj/llvm-readobj.cpp') diff --git a/test/Object/readobj-shared-object.test b/test/Object/readobj-shared-object.test index 8d9b179002..c1dd15b1f9 100644 --- a/test/Object/readobj-shared-object.test +++ b/test/Object/readobj-shared-object.test @@ -53,6 +53,24 @@ ELF: global_func FUNC {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0- ELF: _edata ? {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} global,absolute ELF: Total: {{[0-9a-f]+}} +ELF:Sections: +ELF: Name Address Size Align Flags +ELF: {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata +ELF: .hash {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required,rodata +ELF: .dynsym {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required,rodata +ELF: .dynstr {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required,rodata +ELF: .text {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} text,{{(data,)?}}required +ELF: .eh_frame {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required,rodata +ELF: .tdata {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required +ELF: .dynamic {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required +ELF: .got.plt {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required +ELF: .data {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required +ELF: .bss {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} {{[a-z,]*}} +ELF: .shstrtab {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata +ELF: .symtab {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata +ELF: .strtab {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata +ELF: Total: 14 + ELF:Libraries needed: ELF: libc.so.6 ELF: libm.so.6 diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index 81d2bfb730..27b5c53d2e 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -43,6 +43,15 @@ static void dumpSymbolHeader() { << "\n"; } +static void dumpSectionHeader() { + outs() << format(" %-24s", (const char*)"Name") + << format(" %-16s", (const char*)"Address") + << format(" %-16s", (const char*)"Size") + << format(" %-8s", (const char*)"Align") + << format(" %-26s", (const char*)"Flags") + << "\n"; +} + static const char *getTypeStr(SymbolRef::Type Type) { switch (Type) { case SymbolRef::ST_Unknown: return "?"; @@ -84,6 +93,36 @@ static void checkError(error_code ec, const char *msg) { report_fatal_error(std::string(msg) + ": " + ec.message()); } +static std::string getSectionFlagStr(const SectionRef &Section) { + const struct { + error_code (SectionRef::*MemF)(bool &) const; + const char *FlagStr, *ErrorStr; + } Work[] = + {{ &SectionRef::isText, "text,", "Section.isText() failed" }, + { &SectionRef::isData, "data,", "Section.isData() failed" }, + { &SectionRef::isBSS, "bss,", "Section.isBSS() failed" }, + { &SectionRef::isRequiredForExecution, "required,", + "Section.isRequiredForExecution() failed" }, + { &SectionRef::isVirtual, "virtual,", "Section.isVirtual() failed" }, + { &SectionRef::isZeroInit, "zeroinit,", "Section.isZeroInit() failed" }, + { &SectionRef::isReadOnlyData, "rodata,", + "Section.isReadOnlyData() failed" }}; + + std::string result; + for (uint32_t I = 0; I < sizeof(Work)/sizeof(*Work); ++I) { + bool B; + checkError((Section.*Work[I].MemF)(B), Work[I].ErrorStr); + if (B) + result += Work[I].FlagStr; + } + + // Remove trailing comma + if (result.size() > 0) { + result.erase(result.size() - 1); + } + return result; +} + static void dumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) { StringRef Name; @@ -159,12 +198,43 @@ static void dumpDynamicSymbols(const ObjectFile *obj) { outs() << " Total: " << count << "\n\n"; } +static void dumpSection(const SectionRef &Section, const ObjectFile *obj) { + StringRef Name; + checkError(Section.getName(Name), "SectionRef::getName() failed"); + uint64_t Addr, Size, Align; + checkError(Section.getAddress(Addr), "SectionRef::getAddress() failed"); + checkError(Section.getSize(Size), "SectionRef::getSize() failed"); + checkError(Section.getAlignment(Align), "SectionRef::getAlignment() failed"); + outs() << format(" %-24s", std::string(Name).c_str()) + << format(" %16" PRIx64, Addr) + << format(" %16" PRIx64, Size) + << format(" %8" PRIx64, Align) + << " " << getSectionFlagStr(Section) + << "\n"; +} + static void dumpLibrary(const LibraryRef &lib) { StringRef path; lib.getPath(path); outs() << " " << path << "\n"; } +template +static void dump(const ObjectFile *obj, Func f, Iterator begin, Iterator end, + const char *errStr) { + error_code ec; + uint32_t count = 0; + Iterator it = begin, ie = end; + while (it != ie) { + f(*it, obj); + it.increment(ec); + if (ec) + report_fatal_error(errStr); + ++count; + } + outs() << " Total: " << count << "\n\n"; +} + // Iterate through needed libraries static void dumpLibrariesNeeded(const ObjectFile *obj) { error_code ec; @@ -220,6 +290,12 @@ int main(int argc, char** argv) { dumpHeaders(obj); dumpSymbols(obj); dumpDynamicSymbols(obj); + + outs() << "Sections:\n"; + dumpSectionHeader(); + dump(obj, &dumpSection, obj->begin_sections(), obj->end_sections(), + "Section iteration failed"); + dumpLibrariesNeeded(obj); return 0; } -- cgit v1.2.3-70-g09d2 From 87b47ccc5afcdffb1fa7f04b27fca926ec7fb344 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 31 Dec 2012 16:53:01 +0000 Subject: Use the generic dump template. Extracted from a patch by Sami Liedes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171305 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/llvm-readobj.cpp | 72 ++++++++++--------------------------- 1 file changed, 19 insertions(+), 53 deletions(-) (limited to 'tools/llvm-readobj/llvm-readobj.cpp') diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index 27b5c53d2e..d22ecd1b04 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -162,40 +162,12 @@ dumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) { << "\n"; } -// Iterate through the normal symbols in the ObjectFile -static void dumpSymbols(const ObjectFile *obj) { - error_code ec; - uint32_t count = 0; - outs() << "Symbols:\n"; - dumpSymbolHeader(); - symbol_iterator it = obj->begin_symbols(); - symbol_iterator ie = obj->end_symbols(); - while (it != ie) { - dumpSymbol(*it, obj, false); - it.increment(ec); - if (ec) - report_fatal_error("Symbol iteration failed"); - ++count; - } - outs() << " Total: " << count << "\n\n"; +static void dumpStaticSymbol(const SymbolRef &Sym, const ObjectFile *obj) { + return dumpSymbol(Sym, obj, false); } -// Iterate through the dynamic symbols in the ObjectFile. -static void dumpDynamicSymbols(const ObjectFile *obj) { - error_code ec; - uint32_t count = 0; - outs() << "Dynamic Symbols:\n"; - dumpSymbolHeader(); - symbol_iterator it = obj->begin_dynamic_symbols(); - symbol_iterator ie = obj->end_dynamic_symbols(); - while (it != ie) { - dumpSymbol(*it, obj, true); - it.increment(ec); - if (ec) - report_fatal_error("Symbol iteration failed"); - ++count; - } - outs() << " Total: " << count << "\n\n"; +static void dumpDynamicSymbol(const SymbolRef &Sym, const ObjectFile *obj) { + return dumpSymbol(Sym, obj, true); } static void dumpSection(const SectionRef &Section, const ObjectFile *obj) { @@ -213,7 +185,7 @@ static void dumpSection(const SectionRef &Section, const ObjectFile *obj) { << "\n"; } -static void dumpLibrary(const LibraryRef &lib) { +static void dumpLibrary(const LibraryRef &lib, const ObjectFile *obj) { StringRef path; lib.getPath(path); outs() << " " << path << "\n"; @@ -235,23 +207,6 @@ static void dump(const ObjectFile *obj, Func f, Iterator begin, Iterator end, outs() << " Total: " << count << "\n\n"; } -// Iterate through needed libraries -static void dumpLibrariesNeeded(const ObjectFile *obj) { - error_code ec; - uint32_t count = 0; - library_iterator it = obj->begin_libraries_needed(); - library_iterator ie = obj->end_libraries_needed(); - outs() << "Libraries needed:\n"; - while (it != ie) { - dumpLibrary(*it); - it.increment(ec); - if (ec) - report_fatal_error("Needed libraries iteration failed"); - ++count; - } - outs() << " Total: " << count << "\n\n"; -} - static void dumpHeaders(const ObjectFile *obj) { outs() << "File Format : " << obj->getFileFormatName() << "\n"; outs() << "Arch : " @@ -288,15 +243,26 @@ int main(int argc, char** argv) { } dumpHeaders(obj); - dumpSymbols(obj); - dumpDynamicSymbols(obj); + + outs() << "Symbols:\n"; + dumpSymbolHeader(); + dump(obj, dumpStaticSymbol, obj->begin_symbols(), obj->end_symbols(), + "Symbol iteration failed"); + + outs() << "Dynamic Symbols:\n"; + dumpSymbolHeader(); + dump(obj, dumpDynamicSymbol, obj->begin_dynamic_symbols(), + obj->end_dynamic_symbols(), "Symbol iteration failed"); outs() << "Sections:\n"; dumpSectionHeader(); dump(obj, &dumpSection, obj->begin_sections(), obj->end_sections(), "Section iteration failed"); - dumpLibrariesNeeded(obj); + outs() << "Libraries needed:\n"; + dump(obj, &dumpLibrary, obj->begin_libraries_needed(), + obj->end_libraries_needed(), "Needed libraries iteration failed"); + return 0; } -- cgit v1.2.3-70-g09d2