aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-08-20 13:19:16 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-08-20 13:19:16 +0000
commitb232d5649d31b9bbb191c4a0e2ce10803a6d295c (patch)
tree07e75cbe07c7c22e4ea286ebc420a02a5c0c3ace /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent028fe5af60fcfb84a7d842ab9cbadad27635090f (diff)
downloadllvm-b232d5649d31b9bbb191c4a0e2ce10803a6d295c.zip
llvm-b232d5649d31b9bbb191c4a0e2ce10803a6d295c.tar.gz
llvm-b232d5649d31b9bbb191c4a0e2ce10803a6d295c.tar.bz2
[llvm-objdump] - Remove one of `report_error` functions and improve the error reporting.
One of the report_error functions was taking object::Archive::Child as an argument. It feels excessive, this patch removes it and introduce a helper function instead. Also I fixed a "TODO" in this patch what improved the message printed. Differential revision: https://reviews.llvm.org/D66468 llvm-svn: 369382
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index beb1bd6..c32cd98 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -364,6 +364,17 @@ SectionFilter ToolSectionFilter(object::ObjectFile const &O) {
return SectionFilter([](object::SectionRef S) { return shouldKeep(S); }, O);
}
+std::string getFileNameForError(const object::Archive::Child &C,
+ unsigned Index) {
+ Expected<StringRef> NameOrErr = C.getName();
+ if (NameOrErr)
+ return NameOrErr.get();
+ // If we have an error getting the name then we print the index of the archive
+ // member. Since we are already in an error state, we just ignore this error.
+ consumeError(NameOrErr.takeError());
+ return "<file index: " + std::to_string(Index) + ">";
+}
+
void error(std::error_code EC) {
if (!EC)
return;
@@ -429,20 +440,6 @@ LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef ArchiveName,
exit(1);
}
-LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef ArchiveName,
- const object::Archive::Child &C,
- StringRef ArchitectureName) {
- Expected<StringRef> NameOrErr = C.getName();
- // TODO: if we have a error getting the name then it would be nice to print
- // the index of which archive member this is and or its offset in the
- // archive instead of "???" as the name.
- if (!NameOrErr) {
- consumeError(NameOrErr.takeError());
- report_error(std::move(E), ArchiveName, "???", ArchitectureName);
- } else
- report_error(std::move(E), ArchiveName, NameOrErr.get(), ArchitectureName);
-}
-
static void warnOnNoMatchForSections() {
SetVector<StringRef> MissingSections;
for (StringRef S : FilterSections) {
@@ -2160,11 +2157,13 @@ static void dumpObject(const COFFImportFile *I, const Archive *A,
/// Dump each object file in \a a;
static void dumpArchive(const Archive *A) {
Error Err = Error::success();
+ unsigned I = -1;
for (auto &C : A->children(Err)) {
+ ++I;
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
- report_error(std::move(E), A->getFileName(), C);
+ report_error(std::move(E), A->getFileName(), getFileNameForError(C, I));
continue;
}
if (ObjectFile *O = dyn_cast<ObjectFile>(&*ChildOrErr.get()))