llvm.org GIT mirror llvm / 5daf897
[Object] Revert r275316, Archive::child_iterator changes, while I update lld. Should fix the bots broken by r275316. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275353 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
15 changed file(s) with 202 addition(s) and 241 deletion(s). Raw diff Collapse all Expand all
105105 };
106106
107107 class child_iterator {
108 Child C;
109 Error *E;
110
111 public:
112 child_iterator() : C(Child(nullptr, nullptr, nullptr)), E(nullptr) {}
113 child_iterator(const Child &C, Error *E) : C(C), E(E) {}
114 const Child *operator->() const { return &C; }
115 const Child &operator*() const { return C; }
108 ErrorOr child;
109
110 public:
111 child_iterator() : child(Child(nullptr, nullptr, nullptr)) {}
112 child_iterator(const Child &c) : child(c) {}
113 child_iterator(std::error_code EC) : child(EC) {}
114 const ErrorOr *operator->() const { return &child; }
115 const ErrorOr &operator*() const { return child; }
116116
117117 bool operator==(const child_iterator &other) const {
118 // Ignore errors here: If an error occurred during increment then getNext
119 // will have been set to child_end(), and the following comparison should
120 // do the right thing.
121 return C == other.C;
118 // We ignore error states so that comparisions with end() work, which
119 // allows range loops.
120 if (child.getError() || other.child.getError())
121 return false;
122 return *child == *other.child;
122123 }
123124
124125 bool operator!=(const child_iterator &other) const {
128129 // Code in loops with child_iterators must check for errors on each loop
129130 // iteration. And if there is an error break out of the loop.
130131 child_iterator &operator++() { // Preincrement
131 assert(E && "Can't increment iterator with no Error attached");
132 if (auto ChildOrErr = C.getNext())
133 C = *ChildOrErr;
134 else {
135 ErrorAsOutParameter ErrAsOutParam(*E);
136 C = C.getParent()->child_end().C;
137 *E = errorCodeToError(ChildOrErr.getError());
138 E = nullptr;
139 }
132 assert(child && "Can't increment iterator with error");
133 child = child->getNext();
140134 return *this;
141135 }
142136 };
195189 Kind kind() const { return (Kind)Format; }
196190 bool isThin() const { return IsThin; }
197191
198 child_iterator child_begin(Error &Err, bool SkipInternal = true) const;
192 child_iterator child_begin(bool SkipInternal = true) const;
199193 child_iterator child_end() const;
200 iterator_range children(Error &Err,
201 bool SkipInternal = true) const {
202 return make_range(child_begin(Err, SkipInternal), child_end());
194 iterator_range children(bool SkipInternal = true) const {
195 return make_range(child_begin(SkipInternal), child_end());
203196 }
204197
205198 symbol_iterator symbol_begin() const;
214207 }
215208
216209 // check if a symbol is in the archive
217 child_iterator findSym(Error &Err, StringRef name) const;
210 child_iterator findSym(StringRef name) const;
218211
219212 bool hasSymbolTable() const;
220213 StringRef getSymbolTable() const { return SymbolTable; }
939939 std::function GetExitCode;
940940 };
941941
942 /// Report a serious error, calling any installed error handler. See
943 /// ErrorHandling.h.
944 LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err,
945 bool gen_crash_diag = true);
946
947942 } // namespace llvm
948943
949944 #endif // LLVM_SUPPORT_ERROR_H
326326 for (object::OwningBinary &OB : Archives) {
327327 object::Archive *A = OB.getBinary();
328328 // Look for our symbols in each Archive
329 Error Err;
330 object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
331 if (Err)
332 report_fatal_error(std::move(Err));
329 object::Archive::child_iterator ChildIt = A->findSym(Name);
330 if (std::error_code EC = ChildIt->getError())
331 report_fatal_error(EC.message());
333332 if (ChildIt != A->child_end()) {
334333 // FIXME: Support nested archives?
335334 Expected> ChildBinOrErr =
336 ChildIt->getAsBinary();
335 (*ChildIt)->getAsBinary();
337336 if (!ChildBinOrErr) {
338337 // TODO: Actually report errors helpfully.
339338 consumeError(ChildBinOrErr.takeError());
257257 for (object::OwningBinary &OB : Archives) {
258258 object::Archive *A = OB.getBinary();
259259 // Look for our symbols in each Archive
260 Error Err;
261 object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
262 if (Err)
263 report_fatal_error(std::move(Err));
260 object::Archive::child_iterator ChildIt = A->findSym(Name);
261 if (std::error_code EC = ChildIt->getError())
262 report_fatal_error(EC.message());
264263 if (ChildIt != A->child_end()) {
265264 // FIXME: Support nested archives?
266265 Expected> ChildBinOrErr =
267 ChildIt->getAsBinary();
266 (*ChildIt)->getAsBinary();
268267 if (!ChildBinOrErr) {
269268 // TODO: Actually report errors helpfully.
270269 consumeError(ChildBinOrErr.takeError());
297297 }
298298
299299 // Get the special members.
300 child_iterator I = child_begin(Err, false);
301 if (Err)
302 return;
300 child_iterator I = child_begin(false);
301 std::error_code ec;
302 if ((ec = I->getError())) {
303 Err = errorCodeToError(ec);
304 return;
305 }
303306 child_iterator E = child_end();
304307
305308 // This is at least a valid empty archive. Since an empty archive is the
311314 Err = Error::success();
312315 return;
313316 }
314 const Child *C = &*I;
317 const Child *C = &**I;
315318
316319 auto Increment = [&]() {
317320 ++I;
318 if (Err)
321 if ((Err = errorCodeToError(I->getError())))
319322 return true;
320 C = &*I;
323 C = &**I;
321324 return false;
322325 };
323326
362365 Format = K_BSD;
363366 // We know this is BSD, so getName will work since there is no string table.
364367 ErrorOr NameOrErr = C->getName();
365 if (auto ec = NameOrErr.getError()) {
368 ec = NameOrErr.getError();
369 if (ec) {
366370 Err = errorCodeToError(ec);
367371 return;
368372 }
460464 Err = Error::success();
461465 }
462466
463 Archive::child_iterator Archive::child_begin(Error &Err,
464 bool SkipInternal) const {
467 Archive::child_iterator Archive::child_begin(bool SkipInternal) const {
465468 if (Data.getBufferSize() == 8) // empty archive.
466469 return child_end();
467470
468471 if (SkipInternal)
469 return child_iterator(Child(this, FirstRegularData,
470 FirstRegularStartOfFile),
471 &Err);
472 return Child(this, FirstRegularData, FirstRegularStartOfFile);
472473
473474 const char *Loc = Data.getBufferStart() + strlen(Magic);
474475 std::error_code EC;
475 Child C(this, Loc, &EC);
476 if (EC) {
477 ErrorAsOutParameter ErrAsOutParam(Err);
478 Err = errorCodeToError(EC);
479 return child_end();
480 }
481 return child_iterator(C, &Err);
476 Child c(this, Loc, &EC);
477 if (EC)
478 return child_iterator(EC);
479 return child_iterator(c);
482480 }
483481
484482 Archive::child_iterator Archive::child_end() const {
485 return child_iterator(Child(this, nullptr, nullptr), nullptr);
483 return Child(this, nullptr, nullptr);
486484 }
487485
488486 StringRef Archive::Symbol::getName() const {
666664 return read32le(buf);
667665 }
668666
669 Archive::child_iterator Archive::findSym(Error &Err, StringRef name) const {
667 Archive::child_iterator Archive::findSym(StringRef name) const {
670668 Archive::symbol_iterator bs = symbol_begin();
671669 Archive::symbol_iterator es = symbol_end();
672670
673671 for (; bs != es; ++bs) {
674672 StringRef SymName = bs->getName();
675673 if (SymName == name) {
676 if (auto MemberOrErr = bs->getMember()) {
677 return child_iterator(*MemberOrErr, &Err);
678 } else {
679 ErrorAsOutParameter ErrAsOutParam(Err);
680 Err = errorCodeToError(MemberOrErr.getError());
674 ErrorOr ResultOrErr = bs->getMember();
675 // FIXME: Should we really eat the error?
676 if (ResultOrErr.getError())
681677 return child_end();
682 }
678 return ResultOrErr.get();
683679 }
684680 }
685681 return child_end();
6363 });
6464 }
6565
66
6766 std::error_code ErrorList::convertToErrorCode() const {
6867 return std::error_code(static_cast(ErrorErrorCode::MultipleErrors),
6968 *ErrorErrorCat);
9998 return EC;
10099 }
101100
102 void report_fatal_error(Error Err, bool GenCrashDiag) {
103 assert(Err && "report_fatal_error called with success value");
104 std::string ErrMsg;
105 {
106 raw_string_ostream ErrStream(ErrMsg);
107 logAllUnhandledErrors(std::move(Err), ErrStream, "");
108 }
109 report_fatal_error(ErrMsg);
110101 }
111
112 }
101101 Buffers.reserve(CurrentArchives.size());
102102
103103 for (const auto &CurrentArchive : CurrentArchives) {
104 Error Err;
105 for (auto Child : CurrentArchive->children(Err)) {
104 for (auto ChildOrErr : CurrentArchive->children()) {
105 if (std::error_code Err = ChildOrErr.getError())
106 return Err;
107 const auto &Child = *ChildOrErr;
106108 if (auto NameOrErr = Child.getName()) {
107109 if (*NameOrErr == Filename) {
108110 if (Timestamp != sys::TimeValue::PosixZeroTime() &&
120122 }
121123 }
122124 }
123 if (Err)
124 return errorToErrorCode(std::move(Err));
125125 }
126126
127127 if (Buffers.empty())
404404 fail("extracting from a thin archive is not supported");
405405
406406 bool Filter = !Members.empty();
407 {
408 Error Err;
409 for (auto &C : OldArchive->children(Err)) {
410 ErrorOr NameOrErr = C.getName();
411 failIfError(NameOrErr.getError());
412 StringRef Name = NameOrErr.get();
413
414 if (Filter) {
415 auto I = std::find(Members.begin(), Members.end(), Name);
416 if (I == Members.end())
417 continue;
418 Members.erase(I);
419 }
420
421 switch (Operation) {
422 default:
423 llvm_unreachable("Not a read operation");
424 case Print:
425 doPrint(Name, C);
426 break;
427 case DisplayTable:
428 doDisplayTable(Name, C);
429 break;
430 case Extract:
431 doExtract(Name, C);
432 break;
433 }
407 for (auto &ChildOrErr : OldArchive->children()) {
408 failIfError(ChildOrErr.getError());
409 const object::Archive::Child &C = *ChildOrErr;
410
411 ErrorOr NameOrErr = C.getName();
412 failIfError(NameOrErr.getError());
413 StringRef Name = NameOrErr.get();
414
415 if (Filter) {
416 auto I = std::find(Members.begin(), Members.end(), Name);
417 if (I == Members.end())
418 continue;
419 Members.erase(I);
434420 }
435 failIfError(std::move(Err));
436 }
437
421
422 switch (Operation) {
423 default:
424 llvm_unreachable("Not a read operation");
425 case Print:
426 doPrint(Name, C);
427 break;
428 case DisplayTable:
429 doDisplayTable(Name, C);
430 break;
431 case Extract:
432 doExtract(Name, C);
433 break;
434 }
435 }
438436 if (Members.empty())
439437 return;
440438 for (StringRef Name : Members)
532530 int InsertPos = -1;
533531 StringRef PosName = sys::path::filename(RelPos);
534532 if (OldArchive) {
535 Error Err;
536 for (auto &Child : OldArchive->children(Err)) {
533 for (auto &ChildOrErr : OldArchive->children()) {
534 failIfError(ChildOrErr.getError());
535 auto &Child = ChildOrErr.get();
537536 int Pos = Ret.size();
538537 ErrorOr NameOrErr = Child.getName();
539538 failIfError(NameOrErr.getError());
568567 if (MemberI != Members.end())
569568 Members.erase(MemberI);
570569 }
571 failIfError(std::move(Err));
572570 }
573571
574572 if (Operation == Delete)
765763 "Could not parse library");
766764 Archives.push_back(std::move(*LibOrErr));
767765 object::Archive &Lib = *Archives.back();
768 {
769 Error Err;
770 for (auto &Member : Lib.children(Err))
771 addMember(NewMembers, Member);
772 failIfError(std::move(Err));
766 for (auto &MemberOrErr : Lib.children()) {
767 failIfError(MemberOrErr.getError());
768 addMember(NewMembers, *MemberOrErr);
773769 }
774770 break;
775771 }
4747 outs() << "\nError reading file: " << EC.message() << ".\n";
4848 outs().flush();
4949 exit(1);
50 }
51
52 static void error(Error Err) {
53 if (Err) {
54 logAllUnhandledErrors(std::move(Err), outs(), "Error reading file: ");
55 outs().flush();
56 exit(1);
57 }
5850 }
5951
6052 } // namespace llvm
489481 }
490482
491483 static void dumpArchive(const Archive *Arc) {
492 Error Err;
493 for (auto &ArcC : Arc->children(Err)) {
484 for (auto &ErrorOrChild : Arc->children()) {
485 error(ErrorOrChild.getError());
486 const Archive::Child &ArcC = *ErrorOrChild;
494487 Expected> ChildOrErr = ArcC.getAsBinary();
495488 if (!ChildOrErr) {
496489 // Ignore non-object files.
510503 else
511504 reportError(Arc->getFileName(), cxxdump_error::unrecognized_file_format);
512505 }
513 error(std::move(Err));
514506 }
515507
516508 static void dumpInput(StringRef File) {
11081108 }
11091109 }
11101110
1111 {
1112 Error Err;
1113 for (auto &C : A->children(Err)) {
1114 Expected> ChildOrErr = C.getAsBinary(&Context);
1115 if (!ChildOrErr) {
1116 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
1117 error(std::move(E), Filename, C);
1118 continue;
1111 for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
1112 I != E; ++I) {
1113 if (error(I->getError()))
1114 return;
1115 auto &C = I->get();
1116 Expected> ChildOrErr = C.getAsBinary(&Context);
1117 if (!ChildOrErr) {
1118 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
1119 error(std::move(E), Filename, C);
1120 continue;
1121 }
1122 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
1123 if (!checkMachOAndArchFlags(O, Filename))
1124 return;
1125 if (!PrintFileName) {
1126 outs() << "\n";
1127 if (isa(O)) {
1128 outs() << Filename << "(" << O->getFileName() << ")";
1129 } else
1130 outs() << O->getFileName();
1131 outs() << ":\n";
11191132 }
1120 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
1121 if (!checkMachOAndArchFlags(O, Filename))
1122 return;
1123 if (!PrintFileName) {
1124 outs() << "\n";
1125 if (isa(O)) {
1126 outs() << Filename << "(" << O->getFileName() << ")";
1127 } else
1128 outs() << O->getFileName();
1129 outs() << ":\n";
1130 }
1131 dumpSymbolNamesFromObject(*O, false, Filename);
1132 }
1133 dumpSymbolNamesFromObject(*O, false, Filename);
11331134 }
1134 if (Err)
1135 error(std::move(Err), A->getFileName());
11361135 }
11371136 return;
11381137 }
11741173 } else if (Expected> AOrErr =
11751174 I->getAsArchive()) {
11761175 std::unique_ptr &A = *AOrErr;
1177 Error Err;
1178 for (auto &C : A->children(Err)) {
1176 for (Archive::child_iterator AI = A->child_begin(),
1177 AE = A->child_end();
1178 AI != AE; ++AI) {
1179 if (error(AI->getError()))
1180 return;
1181 auto &C = AI->get();
11791182 Expected> ChildOrErr =
11801183 C.getAsBinary(&Context);
11811184 if (!ChildOrErr) {
12051208 ArchitectureName);
12061209 }
12071210 }
1208 if (Err)
1209 error(std::move(Err), A->getFileName());
12101211 } else {
12111212 consumeError(AOrErr.takeError());
12121213 error(Filename + " for architecture " +
12451246 } else if (Expected> AOrErr =
12461247 I->getAsArchive()) {
12471248 std::unique_ptr &A = *AOrErr;
1248 Error Err;
1249 for (auto &C : A->children(Err)) {
1249 for (Archive::child_iterator AI = A->child_begin(),
1250 AE = A->child_end();
1251 AI != AE; ++AI) {
1252 if (error(AI->getError()))
1253 return;
1254 auto &C = AI->get();
12501255 Expected> ChildOrErr =
12511256 C.getAsBinary(&Context);
12521257 if (!ChildOrErr) {
12661271 dumpSymbolNamesFromObject(*O, false, ArchiveName);
12671272 }
12681273 }
1269 if (Err)
1270 error(std::move(Err), A->getFileName());
12711274 } else {
12721275 consumeError(AOrErr.takeError());
12731276 error(Filename + " for architecture " +
13121315 } else if (Expected> AOrErr =
13131316 I->getAsArchive()) {
13141317 std::unique_ptr &A = *AOrErr;
1315 Error Err;
1316 for (auto &C : A->children(Err)) {
1318 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
1319 AI != AE; ++AI) {
1320 if (error(AI->getError()))
1321 return;
1322 auto &C = AI->get();
13171323 Expected> ChildOrErr =
13181324 C.getAsBinary(&Context);
13191325 if (!ChildOrErr) {
13421348 dumpSymbolNamesFromObject(*O, false, ArchiveName, ArchitectureName);
13431349 }
13441350 }
1345 if (Err)
1346 error(std::move(Err), A->getFileName());
13471351 } else {
13481352 consumeError(AOrErr.takeError());
13491353 error(Filename + " for architecture " +
15341534 }
15351535
15361536 static void printArchiveHeaders(Archive *A, bool verbose, bool print_offset) {
1537 Error Err;
1538 for (const auto &C : A->children(Err, false))
1537 for (Archive::child_iterator I = A->child_begin(false), E = A->child_end();
1538 I != E; ++I) {
1539 if (std::error_code EC = I->getError())
1540 report_fatal_error(EC.message());
1541 const Archive::Child &C = **I;
15391542 printArchiveChild(C, verbose, print_offset);
1540 if (Err)
1541 report_fatal_error(std::move(Err));
1543 }
15421544 }
15431545
15441546 // ParseInputMachO() parses the named Mach-O file in Filename and handles the
15691571 outs() << "Archive : " << Filename << "\n";
15701572 if (ArchiveHeaders)
15711573 printArchiveHeaders(A, !NonVerbose, ArchiveMemberOffsets);
1572 Error Err;
1573 for (auto &C : A->children(Err)) {
1574 for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
1575 I != E; ++I) {
1576 if (std::error_code EC = I->getError())
1577 report_error(Filename, EC);
1578 auto &C = I->get();
15741579 Expected> ChildOrErr = C.getAsBinary();
15751580 if (!ChildOrErr) {
15761581 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
15831588 ProcessMachO(Filename, O, O->getFileName());
15841589 }
15851590 }
1586 if (Err)
1587 report_error(Filename, std::move(Err));
15881591 return;
15891592 }
15901593 if (UniversalHeaders) {
16261629 outs() << "\n";
16271630 if (ArchiveHeaders)
16281631 printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
1629 Error Err;
1630 for (auto &C : A->children(Err)) {
1632 for (Archive::child_iterator AI = A->child_begin(),
1633 AE = A->child_end();
1634 AI != AE; ++AI) {
1635 if (std::error_code EC = AI->getError())
1636 report_error(Filename, EC);
1637 auto &C = AI->get();
16311638 Expected> ChildOrErr = C.getAsBinary();
16321639 if (!ChildOrErr) {
16331640 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
16381645 dyn_cast(&*ChildOrErr.get()))
16391646 ProcessMachO(Filename, O, O->getFileName(), ArchitectureName);
16401647 }
1641 if (Err)
1642 report_error(Filename, std::move(Err));
16431648 } else {
16441649 consumeError(AOrErr.takeError());
16451650 error("Mach-O universal file: " + Filename + " for " +
16811686 outs() << "Archive : " << Filename << "\n";
16821687 if (ArchiveHeaders)
16831688 printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
1684 Error Err;
1685 for (auto &C : A->children(Err)) {
1689 for (Archive::child_iterator AI = A->child_begin(),
1690 AE = A->child_end();
1691 AI != AE; ++AI) {
1692 if (std::error_code EC = AI->getError())
1693 report_error(Filename, EC);
1694 auto &C = AI->get();
16861695 Expected> ChildOrErr = C.getAsBinary();
16871696 if (!ChildOrErr) {
16881697 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
16931702 dyn_cast(&*ChildOrErr.get()))
16941703 ProcessMachO(Filename, O, O->getFileName());
16951704 }
1696 if (Err)
1697 report_error(Filename, std::move(Err));
16981705 } else {
16991706 consumeError(AOrErr.takeError());
17001707 error("Mach-O universal file: " + Filename + " for architecture " +
17321739 outs() << "\n";
17331740 if (ArchiveHeaders)
17341741 printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
1735 Error Err;
1736 for (auto &C : A->children(Err)) {
1742 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
1743 AI != AE; ++AI) {
1744 if (std::error_code EC = AI->getError())
1745 report_error(Filename, EC);
1746 auto &C = AI->get();
17371747 Expected> ChildOrErr = C.getAsBinary();
17381748 if (!ChildOrErr) {
17391749 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
17471757 ArchitectureName);
17481758 }
17491759 }
1750 if (Err)
1751 report_error(Filename, std::move(Err));
17521760 } else {
17531761 consumeError(AOrErr.takeError());
17541762 error("Mach-O universal file: " + Filename + " for architecture " +
17011701
17021702 /// @brief Dump each object file in \a a;
17031703 static void DumpArchive(const Archive *a) {
1704 Error Err;
1705 for (auto &C : a->children(Err)) {
1704 for (auto &ErrorOrChild : a->children()) {
1705 if (std::error_code EC = ErrorOrChild.getError())
1706 report_error(a->getFileName(), EC);
1707 const Archive::Child &C = *ErrorOrChild;
17061708 Expected> ChildOrErr = C.getAsBinary();
17071709 if (!ChildOrErr) {
17081710 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
17141716 else
17151717 report_error(a->getFileName(), object_error::invalid_file_type);
17161718 }
1717 if (Err)
1718 report_error(a->getFileName(), std::move(Err));
17191719 }
17201720
17211721 /// @brief Open file and figure out how to dump it.
292292 Input = "";
293293
294294 reportError(Twine(Input) + ": " + Message);
295 }
296
297 static void reportError(StringRef Input, Error Err) {
298 if (Input == "-")
299 Input = "";
300 std::string ErrMsg;
301 {
302 raw_string_ostream ErrStream(ErrMsg);
303 logAllUnhandledErrors(std::move(Err), ErrStream, Input + ": ");
304 }
305 reportError(ErrMsg);
306295 }
307296
308297 static bool isMipsArch(unsigned Arch) {
434423
435424 /// @brief Dumps each object file in \a Arc;
436425 static void dumpArchive(const Archive *Arc) {
437 Error Err;
438 for (auto &Child : Arc->children(Err)) {
426 for (auto &ErrorOrChild : Arc->children()) {
427 if (std::error_code EC = ErrorOrChild.getError())
428 reportError(Arc->getFileName(), EC.message());
429 const auto &Child = *ErrorOrChild;
439430 Expected> ChildOrErr = Child.getAsBinary();
440431 if (!ChildOrErr) {
441432 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) {
452443 else
453444 reportError(Arc->getFileName(), readobj_error::unrecognized_file_format);
454445 }
455 if (Err)
456 reportError(Arc->getFileName(), std::move(Err));
457446 }
458447
459448 /// @brief Dumps each object file in \a MachO Universal Binary;
526526
527527 if (Archive *a = dyn_cast(&Bin)) {
528528 // This is an archive. Iterate over each member and display its sizes.
529 Error Err;
530 for (auto &C : a->children(Err)) {
531 Expected> ChildOrErr = C.getAsBinary();
529 for (object::Archive::child_iterator i = a->child_begin(),
530 e = a->child_end();
531 i != e; ++i) {
532 if (error(i->getError()))
533 exit(1);
534 Expected> ChildOrErr = i->get().getAsBinary();
532535 if (!ChildOrErr) {
533536 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
534 error(std::move(E), a->getFileName(), C);
537 error(std::move(E), a->getFileName(), i->get());
535538 continue;
536539 }
537540 if (ObjectFile *o = dyn_cast(&*ChildOrErr.get())) {
551554 }
552555 }
553556 }
554 if (Err)
555 error(std::move(Err), a->getFileName());
556557 } else if (MachOUniversalBinary *UB =
557558 dyn_cast(&Bin)) {
558559 // If we have a list of architecture flags specified dump only those.
595596 std::unique_ptr &UA = *AOrErr;
596597 // This is an archive. Iterate over each member and display its
597598 // sizes.
598 Error Err;
599 for (auto &C : UA->children(Err)) {
600 Expected> ChildOrErr = C.getAsBinary();
599 for (object::Archive::child_iterator i = UA->child_begin(),
600 e = UA->child_end();
601 i != e; ++i) {
602 if (error(i->getError()))
603 exit(1);
604 Expected> ChildOrErr =
605 i->get().getAsBinary();
601606 if (!ChildOrErr) {
602607 if (auto E = isNotObjectErrorInvalidFileType(
603608 ChildOrErr.takeError()))
604 error(std::move(E), UA->getFileName(), C,
609 error(std::move(E), UA->getFileName(), i->get(),
605610 ArchFlags.size() > 1 ?
606611 StringRef(I->getArchTypeName()) : StringRef());
607612 continue;
631636 }
632637 }
633638 }
634 if (Err)
635 error(std::move(Err), UA->getFileName());
636639 } else {
637640 consumeError(AOrErr.takeError());
638641 error("Mach-O universal file: " + file + " for architecture " +
684687 std::unique_ptr &UA = *AOrErr;
685688 // This is an archive. Iterate over each member and display its
686689 // sizes.
687 Error Err;
688 for (auto &C : UA->children(Err)) {
689 Expected> ChildOrErr = C.getAsBinary();
690 for (object::Archive::child_iterator i = UA->child_begin(),
691 e = UA->child_end();
692 i != e; ++i) {
693 if (error(i->getError()))
694 exit(1);
695 Expected> ChildOrErr =
696 i->get().getAsBinary();
690697 if (!ChildOrErr) {
691698 if (auto E = isNotObjectErrorInvalidFileType(
692699 ChildOrErr.takeError()))
693 error(std::move(E), UA->getFileName(), C);
700 error(std::move(E), UA->getFileName(), i->get());
694701 continue;
695702 }
696703 if (ObjectFile *o = dyn_cast(&*ChildOrErr.get())) {
713720 }
714721 }
715722 }
716 if (Err)
717 error(std::move(Err), UA->getFileName());
718723 } else {
719724 consumeError(AOrErr.takeError());
720725 error("Mach-O universal file: " + file + " for architecture " +
759764 I->getAsArchive()) {
760765 std::unique_ptr &UA = *AOrErr;
761766 // This is an archive. Iterate over each member and display its sizes.
762 Error Err;
763 for (auto &C : UA->children(Err)) {
764 Expected> ChildOrErr = C.getAsBinary();
767 for (object::Archive::child_iterator i = UA->child_begin(),
768 e = UA->child_end();
769 i != e; ++i) {
770 if (error(i->getError()))
771 exit(1);
772 Expected> ChildOrErr = i->get().getAsBinary();
765773 if (!ChildOrErr) {
766774 if (auto E = isNotObjectErrorInvalidFileType(
767775 ChildOrErr.takeError()))
768 error(std::move(E), UA->getFileName(), C, MoreThanOneArch ?
776 error(std::move(E), UA->getFileName(), i->get(), MoreThanOneArch ?
769777 StringRef(I->getArchTypeName()) : StringRef());
770778 continue;
771779 }
789797 }
790798 }
791799 }
792 if (Err)
793 error(std::move(Err), UA->getFileName());
794800 } else {
795801 consumeError(AOrErr.takeError());
796802 error("Mach-O universal file: " + file + " for architecture " +
134134 FailIfError(E.getError());
135135 }
136136
137 static void FailIfError(Error Err) {
138 if (Err) {
139 logAllUnhandledErrors(std::move(Err), errs(), "Error: ");
140 exit(1);
141 }
142 }
143
144137 template static void FailIfError(Expected &E) {
145 FailIfError(E.takeError());
138 if (E)
139 return;
140 logAllUnhandledErrors(E.takeError(), errs(), "Error: ");
146141 }
147142
148143 static void FailIfNotEmpty(const llvm::Twine &E) {
421416 static void
422417 visitObjectFiles(const object::Archive &A,
423418 function_ref Fn) {
424 Error Err;
425 for (auto &C : A.children(Err)) {
419 for (auto &ErrorOrChild : A.children()) {
420 FailIfError(ErrorOrChild);
421 const object::Archive::Child &C = *ErrorOrChild;
426422 Expected> ChildOrErr = C.getAsBinary();
427423 FailIfError(errorToErrorCode(ChildOrErr.takeError()));
428424 if (auto *O = dyn_cast(&*ChildOrErr.get()))
430426 else
431427 FailIfError(object::object_error::invalid_file_type);
432428 }
433 FailIfError(std::move(Err));
434429 }
435430
436431 static void