Index: llvm-cxxdump.cpp =================================================================== --- llvm-cxxdump.cpp +++ llvm-cxxdump.cpp @@ -40,15 +40,12 @@ cl::ZeroOrMore); } // namespace opts -static int ReturnValue = EXIT_SUCCESS; - namespace llvm { static bool error(std::error_code EC) { if (!EC) return false; - ReturnValue = EXIT_FAILURE; outs() << "\nError reading file: " << EC.message() << ".\n"; outs().flush(); return true; @@ -62,7 +59,6 @@ errs() << Input << ": " << Message << "\n"; errs().flush(); - ReturnValue = EXIT_FAILURE; } static void reportError(StringRef Input, std::error_code EC) { @@ -132,7 +128,7 @@ return false; } -static void dumpCXXData(const ObjectFile *Obj) { +static bool dumpCXXData(const ObjectFile *Obj) { struct CompleteObjectLocator { StringRef Symbols[2]; ArrayRef Data; @@ -192,11 +188,11 @@ uint64_t SymSize = P.second; ErrorOr SymNameOrErr = Sym.getName(); if (error(SymNameOrErr.getError())) - return; + return true; StringRef SymName = *SymNameOrErr; object::section_iterator SecI(Obj->section_begin()); if (error(Sym.getSection(SecI))) - return; + return true; // Skip external symbols. if (SecI == Obj->section_end()) continue; @@ -206,10 +202,10 @@ continue; StringRef SecContents; if (error(Sec.getContents(SecContents))) - return; + return true; ErrorOr SymAddressOrErr = Sym.getAddress(); if (error(SymAddressOrErr.getError())) - return; + return true; uint64_t SymAddress = *SymAddressOrErr; uint64_t SecAddress = Sec.getAddress(); uint64_t SecSize = Sec.getSize(); @@ -241,7 +237,7 @@ StringRef *I = std::begin(COL.Symbols), *E = std::end(COL.Symbols); if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E)) - return; + return true; COLs[SymName] = COL; } // Class hierarchy descriptors in the MS-ABI start with '??_R3' @@ -252,7 +248,7 @@ StringRef *I = std::begin(CHD.Symbols), *E = std::end(CHD.Symbols); if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E)) - return; + return true; CHDs[SymName] = CHD; } // Class hierarchy descriptors in the MS-ABI start with '??_R2' @@ -270,7 +266,7 @@ StringRef *I = std::begin(BCD.Symbols), *E = std::end(BCD.Symbols); if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E)) - return; + return true; BCDs[SymName] = BCD; } // Type descriptors in the MS-ABI start with '??_R0' @@ -285,7 +281,7 @@ StringRef *I = std::begin(TD.Symbols), *E = std::end(TD.Symbols); if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E)) - return; + return true; TDs[SymName] = TD; } // Throw descriptors in the MS-ABI start with '_TI' @@ -318,7 +314,7 @@ StringRef *I = std::begin(CT.Symbols), *E = std::end(CT.Symbols); if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E)) - return; + return true; CTs[SymName] = CT; } // Construction vtables in the Itanium ABI start with '_ZTT' or '__ZTT'. @@ -507,52 +503,63 @@ continue; } } + return false; } -static void dumpArchive(const Archive *Arc) { +static bool dumpArchive(const Archive *Arc) { + bool Fail = false; for (const Archive::Child &ArcC : Arc->children()) { ErrorOr> ChildOrErr = ArcC.getAsBinary(); if (std::error_code EC = ChildOrErr.getError()) { // Ignore non-object files. - if (EC != object_error::invalid_file_type) + if (EC != object_error::invalid_file_type) { reportError(Arc->getFileName(), EC.message()); + Fail = true; + } continue; } if (ObjectFile *Obj = dyn_cast(&*ChildOrErr.get())) dumpCXXData(Obj); - else + else { reportError(Arc->getFileName(), cxxdump_error::unrecognized_file_format); + Fail = true; + } } + return Fail; } -static void dumpInput(StringRef File) { +static bool dumpInput(StringRef File) { // If file isn't stdin, check that it exists. if (File != "-" && !sys::fs::exists(File)) { reportError(File, cxxdump_error::file_not_found); - return; + return true; } // Attempt to open the binary. ErrorOr> BinaryOrErr = createBinary(File); if (std::error_code EC = BinaryOrErr.getError()) { reportError(File, EC); - return; + return true; } Binary &Binary = *BinaryOrErr.get().getBinary(); - + bool Fail; if (Archive *Arc = dyn_cast(&Binary)) - dumpArchive(Arc); + Fail = dumpArchive(Arc); else if (ObjectFile *Obj = dyn_cast(&Binary)) - dumpCXXData(Obj); - else + Fail = dumpCXXData(Obj); + else { reportError(File, cxxdump_error::unrecognized_file_format); + return true; + } + return Fail; } int main(int argc, const char *argv[]) { sys::PrintStackTraceOnErrorSignal(); PrettyStackTraceProgram X(argc, argv); llvm_shutdown_obj Y; + bool Fail; // Initialize targets. llvm::InitializeAllTargetInfos(); @@ -566,8 +573,8 @@ if (opts::InputFilenames.size() == 0) opts::InputFilenames.push_back("-"); - std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(), - dumpInput); - - return ReturnValue; + for (StringRef F: opts::InputFilenames) + if (dumpInput(F)) + Fail = true; + return Fail; }