diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -296,6 +296,8 @@ void printSymbolsHelper(bool IsDynamic) const; void printDynamicEntry(raw_ostream &OS, uint64_t Type, uint64_t Value) const; + void printDynamicString(uint64_t Value, raw_ostream &OS, + bool WithBracket = true) const; const Elf_Shdr *getDotSymtabSec() const { return DotSymtabSec; } const Elf_Shdr *getDotCGProfileSec() const { return DotCGProfileSec; } @@ -1952,12 +1954,7 @@ {DT_RUNPATH, "Library runpath"}, }; OS << TagNames.at(Type) << ": "; - if (DynamicStringTable.empty()) - OS << " "; - else if (Value < DynamicStringTable.size()) - OS << "[" << StringRef(DynamicStringTable.data() + Value) << "]"; - else - OS << ""; + printDynamicString(Value, OS, true); break; } case DT_FLAGS: @@ -1972,6 +1969,21 @@ } } +template +void ELFDumper::printDynamicString(uint64_t Value, raw_ostream &OS, + bool WithBracket) const { + if (DynamicStringTable.empty()) + OS << " "; + else if (Value < DynamicStringTable.size()) { + if (WithBracket) + OS << "["; + OS << StringRef(DynamicStringTable.data() + Value); + if (WithBracket) + OS << "]"; + } else + OS << ""; +} + template void ELFDumper::printUnwindInfo() { DwarfCFIEH::PrinterContext Ctx(W, ObjF); Ctx.printUnwindInformation();