Index: include/llvm/DebugInfo/DWARF/DWARFContext.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFContext.h +++ include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -292,6 +292,7 @@ virtual void anchor(); StringRef FileName; + bool HasError; bool IsLittleEndian; uint8_t AddressSize; DWARFSection InfoSection; @@ -342,14 +343,20 @@ Error maybeDecompress(const object::SectionRef &Sec, StringRef Name, StringRef &Data); + /// Reports a error, updates HasError flag. + void reportError(const Twine& Msg); + public: DWARFContextInMemory(const object::ObjectFile &Obj, - const LoadedObjectInfo *L = nullptr); + const LoadedObjectInfo *L = nullptr, + bool AllowErrors = true); DWARFContextInMemory(const StringMap> &Sections, uint8_t AddrSize, bool isLittleEndian = sys::IsLittleEndianHost); + bool HasErrors() const { return HasError; } + StringRef getFileName() const override { return FileName; } bool isLittleEndian() const override { return IsLittleEndian; } uint8_t getAddressSize() const override { return AddressSize; } Index: lib/DebugInfo/DWARF/DWARFContext.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFContext.cpp +++ lib/DebugInfo/DWARF/DWARFContext.cpp @@ -938,11 +938,20 @@ return Error::success(); } +void DWARFContextInMemory::reportError(const Twine &Msg) { + HasError = true; + errs() << Msg << '\n'; +} + DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, - const LoadedObjectInfo *L) + const LoadedObjectInfo *L, + bool AllowErrors) : FileName(Obj.getFileName()), IsLittleEndian(Obj.isLittleEndian()), AddressSize(Obj.getBytesInAddress()) { for (const SectionRef &Section : Obj.sections()) { + if (HasError && !AllowErrors) + return; + StringRef name; Section.getName(name); // Skip BSS and Virtual sections, they aren't interesting. @@ -962,9 +971,8 @@ Section.getContents(data); if (auto Err = maybeDecompress(Section, name, data)) { - errs() << "error: failed to decompress '" + name + "', " + - toString(std::move(Err)) - << '\n'; + reportError("error: failed to decompress '" + name + "', " + + toString(std::move(Err))); continue; } @@ -1049,6 +1057,9 @@ // Symbol to [address, section index] cache mapping. std::map AddrCache; for (const RelocationRef &Reloc : Section.relocations()) { + if (HasError && !AllowErrors) + return; + // FIXME: it's not clear how to correctly handle scattered // relocations. if (isRelocScattered(Obj, Reloc)) @@ -1056,7 +1067,7 @@ Expected SymInfoOrErr = getSymbolInfo(Obj, Reloc, L, AddrCache); if (!SymInfoOrErr) { - errs() << toString(SymInfoOrErr.takeError()) << '\n'; + reportError(toString(SymInfoOrErr.takeError())); continue; } @@ -1065,7 +1076,7 @@ if (V.error()) { SmallString<32> Name; Reloc.getTypeName(Name); - errs() << "error: failed to compute relocation: " << Name << "\n"; + reportError("error: failed to compute relocation: " + Name); continue; } llvm::RelocAddrEntry Rel = {SymInfoOrErr->SectionIndex, Val};