summaryrefslogtreecommitdiff
path: root/tools/llvm-nm
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2016-07-29 17:44:13 +0000
committerKevin Enderby <enderby@apple.com>2016-07-29 17:44:13 +0000
commit2a7151766d6552e877b1432edc71ffd7907ff963 (patch)
tree93398694d56b9126f64c5da5f951b5949fce9f32 /tools/llvm-nm
parent0c332fd27262703bb8a98af4d7a828cb47f5e864 (diff)
The next step along the way to getting good error messages for bad archives.
As mentioned in commit log for r276686 this next step is adding a new method in the ArchiveMemberHeader class to get the full name that does proper error checking, and can be use for error messages. To do this the name of ArchiveMemberHeader::getName() is changed to ArchiveMemberHeader::getRawName() to be consistent with Archive::Child::getRawName(). Then the “new” method is the addition of a new implementation of ArchiveMemberHeader::getName() which gets the full name and provides proper error checking. Which is mostly a rewrite of what was Archive::Child::getName() and cleaning up incorrect uses of llvm_unreachable() in the code which were actually just cases of errors in the input Archives. Then Archive::Child::getName() is changed to return Expected<> and use the new implementation of ArchiveMemberHeader::getName() . Also needed to change Archive::getMemoryBufferRef() with these changes to return Expected<> as well to propagate Errors up. As well as changing Archive::isThinMember() to return Expected<> . git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277177 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-nm')
-rw-r--r--tools/llvm-nm/llvm-nm.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp
index 9b2f5220bad..424303b1695 100644
--- a/tools/llvm-nm/llvm-nm.cpp
+++ b/tools/llvm-nm/llvm-nm.cpp
@@ -198,13 +198,14 @@ static void error(llvm::Error E, StringRef FileName, const Archive::Child &C,
HadError = true;
errs() << ToolName << ": " << FileName;
- ErrorOr<StringRef> NameOrErr = C.getName();
+ 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.getError())
+ if (!NameOrErr) {
+ consumeError(NameOrErr.takeError());
errs() << "(" << "???" << ")";
- else
+ } else
errs() << "(" << NameOrErr.get() << ")";
if (!ArchitectureName.empty())
@@ -1099,9 +1100,11 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
ErrorOr<Archive::Child> C = I->getMember();
if (error(C.getError()))
return;
- ErrorOr<StringRef> FileNameOrErr = C->getName();
- if (error(FileNameOrErr.getError()))
+ Expected<StringRef> FileNameOrErr = C->getName();
+ if (!FileNameOrErr) {
+ error(FileNameOrErr.takeError(), Filename);
return;
+ }
StringRef SymName = I->getName();
outs() << SymName << " in " << FileNameOrErr.get() << "\n";
}