[PATCH] D83208: [llvm-readobj] - Refactor ELFDumper<ELFT>::getStaticSymbolName.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 7 03:41:08 PDT 2020
This revision was automatically updated to reflect the committed changes.
grimar marked an inline comment as done.
Closed by commit rG2953ac0975bc: [llvm-readobj] - Refactor ELFDumper<ELFT>::getStaticSymbolName. (authored by grimar).
Changed prior to commit:
https://reviews.llvm.org/D83208?vs=275644&id=275982#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83208/new/
https://reviews.llvm.org/D83208
Files:
llvm/test/tools/llvm-readobj/ELF/addrsig.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -343,7 +343,7 @@
const Elf_Sym *FirstSym) const;
Expected<StringRef> getSymbolSectionName(const Elf_Sym *Symbol,
unsigned SectionIndex) const;
- Expected<std::string> getStaticSymbolName(uint32_t Index) const;
+ std::string getStaticSymbolName(uint32_t Index) const;
StringRef getDynamicString(uint64_t Value) const;
Expected<StringRef> getSymbolVersionByIndex(uint32_t VersionSymbolIndex,
bool &IsDefault) const;
@@ -1131,21 +1131,27 @@
}
template <typename ELFT>
-Expected<std::string>
-ELFDumper<ELFT>::getStaticSymbolName(uint32_t Index) const {
+std::string ELFDumper<ELFT>::getStaticSymbolName(uint32_t Index) const {
+ auto Warn = [&](Error E) -> std::string {
+ this->reportUniqueWarning(
+ createError("unable to read the name of symbol with index " +
+ Twine(Index) + ": " + toString(std::move(E))));
+ return "<?>";
+ };
+
const ELFFile<ELFT> *Obj = ObjF->getELFFile();
Expected<const typename ELFT::Sym *> SymOrErr =
Obj->getSymbol(DotSymtabSec, Index);
if (!SymOrErr)
- return SymOrErr.takeError();
+ return Warn(SymOrErr.takeError());
Expected<StringRef> StrTabOrErr = Obj->getStringTableForSymtab(*DotSymtabSec);
if (!StrTabOrErr)
- return StrTabOrErr.takeError();
+ return Warn(StrTabOrErr.takeError());
Expected<StringRef> NameOrErr = (*SymOrErr)->getName(*StrTabOrErr);
if (!NameOrErr)
- return NameOrErr.takeError();
+ return Warn(NameOrErr.takeError());
return maybeDemangle(*NameOrErr);
}
@@ -6575,21 +6581,12 @@
return;
}
- auto GetSymName = [&](uint32_t Index) -> std::string {
- if (Expected<std::string> NameOrErr =
- this->dumper()->getStaticSymbolName(Index))
- return *NameOrErr;
- else
- this->reportUniqueWarning(
- createError("unable to read the name of symbol with index " +
- Twine(Index) + ": " + toString(NameOrErr.takeError())));
- return "<?>";
- };
-
for (const Elf_CGProfile &CGPE : *CGProfileOrErr) {
DictScope D(W, "CGProfileEntry");
- W.printNumber("From", GetSymName(CGPE.cgp_from), CGPE.cgp_from);
- W.printNumber("To", GetSymName(CGPE.cgp_to), CGPE.cgp_to);
+ W.printNumber("From", this->dumper()->getStaticSymbolName(CGPE.cgp_from),
+ CGPE.cgp_from);
+ W.printNumber("To", this->dumper()->getStaticSymbolName(CGPE.cgp_to),
+ CGPE.cgp_to);
W.printNumber("Weight", CGPE.cgp_weight);
}
}
Index: llvm/test/tools/llvm-readobj/ELF/addrsig.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/addrsig.test
+++ llvm/test/tools/llvm-readobj/ELF/addrsig.test
@@ -58,7 +58,7 @@
# INVALID-INDEX: Addrsig [
# INVALID-INDEX-NEXT: Sym: foo (1)
-# INVALID-INDEX-NEXT: warning: '[[FILE]]': unable to get symbol from section [index 2]: invalid symbol index (255)
+# INVALID-INDEX-NEXT: warning: '[[FILE]]': unable to read the name of symbol with index 255: unable to get symbol from section [index 2]: invalid symbol index (255)
# INVALID-INDEX-NEXT: Sym: <?> (255)
# INVALID-INDEX-NEXT: Sym: bar (2)
# INVALID-INDEX-NEXT: ]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83208.275982.patch
Type: text/x-patch
Size: 3508 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200707/5306ae57/attachment-0001.bin>
More information about the llvm-commits
mailing list