[PATCH] D12078: [llvm-readobj] ELF: Factor out common code

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 03:54:59 PDT 2015


davide created this revision.
davide added reviewers: rafael, echristo.
davide added a subscriber: llvm-commits.

It seems reasonable to me, but wanted to double check (and maybe you can propose a better name for the function)

http://reviews.llvm.org/D12078

Files:
  ELFDumper.cpp

Index: ELFDumper.cpp
===================================================================
--- ELFDumper.cpp
+++ ELFDumper.cpp
@@ -95,6 +95,7 @@
     uintX_t EntSize;
   };
 
+  void printSymbolsHelper(bool IsDynamic);
   void printSymbol(const Elf_Sym *Symbol, const Elf_Shdr *SymTab,
                    StringRef StrTable, bool IsDynamic);
 
@@ -1148,27 +1149,26 @@
 }
 
 template<class ELFT>
-void ELFDumper<ELFT>::printSymbols() {
-  ListScope Group(W, "Symbols");
-
+void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic)
+{
   const Elf_Shdr *Symtab = 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>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12078.32287.patch
Type: text/x-patch
Size: 1478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150817/1278de9a/attachment.bin>


More information about the llvm-commits mailing list