[llvm] r245813 - [llvm-readobj/ELF] Factor out common code.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 23 07:06:41 PDT 2015


Author: davide
Date: Sun Aug 23 09:06:40 2015
New Revision: 245813

URL: http://llvm.org/viewvc/llvm-project?rev=245813&view=rev
Log:
[llvm-readobj/ELF] Factor out common code.

Modified:
    llvm/trunk/tools/llvm-readobj/ELFDumper.cpp

Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=245813&r1=245812&r2=245813&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Sun Aug 23 09:06:40 2015
@@ -95,6 +95,7 @@ private:
     uintX_t EntSize;
   };
 
+  void printSymbolsHelper(bool IsDynamic);
   void printSymbol(const Elf_Sym *Symbol, const Elf_Shdr *SymTab,
                    StringRef StrTable, bool IsDynamic);
 
@@ -1148,27 +1149,25 @@ void ELFDumper<ELFT>::printRelocation(co
 }
 
 template<class ELFT>
-void ELFDumper<ELFT>::printSymbols() {
-  ListScope Group(W, "Symbols");
-
-  const Elf_Shdr *Symtab = DotSymtabSec;
+void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) {
+  const Elf_Shdr *Symtab = (IsDynamic) ? DotDynSymSec : DotSymtabSec;
   ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
   error(StrTableOrErr.getError());
   StringRef StrTable = *StrTableOrErr;
   for (const Elf_Sym &Sym : Obj->symbols(Symtab))
-    printSymbol(&Sym, Symtab, StrTable, false);
+    printSymbol(&Sym, Symtab, StrTable, IsDynamic);
+}
+
+template<class ELFT>
+void ELFDumper<ELFT>::printSymbols() {
+  ListScope Group(W, "Symbols");
+  printSymbolsHelper(false);
 }
 
 template<class ELFT>
 void ELFDumper<ELFT>::printDynamicSymbols() {
   ListScope Group(W, "DynamicSymbols");
-
-  const Elf_Shdr *Symtab = DotDynSymSec;
-  ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
-  error(StrTableOrErr.getError());
-  StringRef StrTable = *StrTableOrErr;
-  for (const Elf_Sym &Sym : Obj->symbols(Symtab))
-    printSymbol(&Sym, Symtab, StrTable, true);
+  printSymbolsHelper(true);
 }
 
 template <class ELFT>




More information about the llvm-commits mailing list