## that goes past the end of file.
# RUN: yaml2obj --docnum=2 %s > %t2.so
-# RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck %s --check-prefix=ERR1
-# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck %s --check-prefix=ERR1
+# RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
+# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
-# ERR1: error: SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0)
+# ERR1: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0)
--- !ELF
FileHeader:
## that goes past the end of file.
# RUN: yaml2obj --docnum=3 %s > %t3.so
-# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck %s --check-prefix=ERR2
-# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck %s --check-prefix=ERR2
+# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
+# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
-# ERR2: error: SHT_NOTE section [index 1] has invalid offset (0x180) or size (0xffff0000)
+# ERR2: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0x180) or size (0xffff0000)
--- !ELF
FileHeader:
## goes past the end of file.
# RUN: yaml2obj --docnum=4 %s > %t4.so
-# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck %s --check-prefix=ERR3
-# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck %s --check-prefix=ERR3
+# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
+# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
-# ERR3: error: PT_NOTE header has invalid offset (0xffff0000) or size (0x0)
+# ERR3: error: '[[FILE]]': PT_NOTE header has invalid offset (0xffff0000) or size (0x0)
--- !ELF
FileHeader:
## goes past the end of file.
# RUN: yaml2obj --docnum=5 %s > %t5.so
-# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck %s --check-prefix=ERR4
-# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck %s --check-prefix=ERR4
+# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4
+# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4
-# ERR4: error: PT_NOTE header has invalid offset (0x1b8) or size (0xffff0000)
+# ERR4: error: '[[FILE]]': PT_NOTE header has invalid offset (0x1b8) or size (0xffff0000)
--- !ELF
FileHeader:
return readobj_error::unknown_symbol;
auto StrTableOrErr = ELF->getStringTableForSymtab(*Symtab);
if (!StrTableOrErr)
- error(StrTableOrErr.takeError());
+ reportError(StrTableOrErr.takeError(), FileName);
StringRef StrTable = *StrTableOrErr;
for (const Elf_Sym &Sym : unwrapOrError(FileName, ELF->symbols(Symtab)))
auto SymTabOrErr = ELF->getSection(Sec.sh_link);
if (!SymTabOrErr)
- error(SymTabOrErr.takeError());
+ reportError(SymTabOrErr.takeError(), FileName);
const Elf_Shdr *SymTab = *SymTabOrErr;
for (const Elf_Rel &R : unwrapOrError(FileName, ELF->rels(&Sec))) {
// The section consists of a number of subsection in the following format:
// |SubSectionType|SubSectionSize|Contents...|
uint32_t SubType, SubSectionSize;
- error(Reader.readInteger(SubType));
- error(Reader.readInteger(SubSectionSize));
+
+ if (Error E = Reader.readInteger(SubType))
+ reportError(std::move(E), Obj->getFileName());
+ if (Error E = Reader.readInteger(SubSectionSize))
+ reportError(std::move(E), Obj->getFileName());
StringRef Contents;
- error(Reader.readFixedString(Contents, SubSectionSize));
+ if (Error E = Reader.readFixedString(Contents, SubSectionSize))
+ reportError(std::move(E), Obj->getFileName());
BinaryStreamRef ST(Contents, support::little);
switch (DebugSubsectionKind(SubType)) {
case DebugSubsectionKind::FileChecksums:
- error(CVFileChecksumTable.initialize(ST));
+ if (Error E = CVFileChecksumTable.initialize(ST))
+ reportError(std::move(E), Obj->getFileName());
break;
case DebugSubsectionKind::StringTable:
- error(CVStringTable.initialize(ST));
+ if (Error E = CVStringTable.initialize(ST))
+ reportError(std::move(E), Obj->getFileName());
break;
default:
break;
}
uint32_t PaddedSize = alignTo(SubSectionSize, 4);
- error(Reader.skip(PaddedSize - SubSectionSize));
+ if (Error E = Reader.skip(PaddedSize - SubSectionSize))
+ reportError(std::move(E), Obj->getFileName());
}
}
W.printNumber("Section", SectionName, Obj->getSectionID(Section));
uint32_t Magic;
- error(consume(Data, Magic));
+ if (Error E = consume(Data, Magic))
+ reportError(std::move(E), Obj->getFileName());
+
W.printHex("Magic", Magic);
if (Magic != COFF::DEBUG_SECTION_MAGIC)
return error(object_error::parse_failed);
// The section consists of a number of subsection in the following format:
// |SubSectionType|SubSectionSize|Contents...|
uint32_t SubType, SubSectionSize;
- error(consume(Data, SubType));
- error(consume(Data, SubSectionSize));
+ if (Error E = consume(Data, SubType))
+ reportError(std::move(E), Obj->getFileName());
+ if (Error E = consume(Data, SubSectionSize))
+ reportError(std::move(E), Obj->getFileName());
ListScope S(W, "Subsection");
// Dump the subsection as normal even if the ignore bit is set.
BinaryStreamReader SR(Contents, llvm::support::little);
DebugFrameDataSubsectionRef FrameData;
- error(FrameData.initialize(SR));
+ if (Error E = FrameData.initialize(SR))
+ reportError(std::move(E), Obj->getFileName());
StringRef LinkageName;
error(resolveSymbolName(Obj->getCOFFSection(Section), SectionContents,
BinaryStreamReader Reader(FunctionLineTables[Name], support::little);
DebugLinesSubsectionRef LineInfo;
- error(LineInfo.initialize(Reader));
+ if (Error E = LineInfo.initialize(Reader))
+ reportError(std::move(E), Obj->getFileName());
W.printHex("Flags", LineInfo.header()->Flags);
W.printHex("CodeSize", LineInfo.header()->CodeSize);
error(object_error::parse_failed);
}
- if (auto EC = CVSD.dump(Symbols)) {
+ if (Error E = CVSD.dump(Symbols)) {
W.flush();
- error(std::move(EC));
+ reportError(std::move(E), Obj->getFileName());
}
CompilationCPUType = CVSD.getCompilationCPUType();
W.flush();
void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) {
BinaryStreamRef Stream(Subsection, llvm::support::little);
DebugChecksumsSubsectionRef Checksums;
- error(Checksums.initialize(Stream));
+ if (Error E = Checksums.initialize(Stream))
+ reportError(std::move(E), Obj->getFileName());
for (auto &FC : Checksums) {
DictScope S(W, "FileChecksum");
void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) {
BinaryStreamReader SR(Subsection, llvm::support::little);
DebugInlineeLinesSubsectionRef Lines;
- error(Lines.initialize(SR));
+ if (Error E = Lines.initialize(SR))
+ reportError(std::move(E), Obj->getFileName());
for (auto &Line : Lines) {
DictScope S(W, "InlineeSourceLine");
if (SectionName == ".debug$T") {
StringRef Data = unwrapOrError(Obj->getFileName(), S.getContents());
uint32_t Magic;
- error(consume(Data, Magic));
+ if (Error E = consume(Data, Magic))
+ reportError(std::move(E), Obj->getFileName());
+
if (Magic != 4)
error(object_error::parse_failed);
if (GHash) {
std::vector<GloballyHashedType> Hashes =
GloballyHashedType::hashTypes(Types);
- if (auto EC =
+ if (Error E =
mergeTypeAndIdRecords(GlobalCVIDs, GlobalCVTypes, SourceToDest,
Types, Hashes, PCHSignature))
- return error(std::move(EC));
+ return reportError(std::move(E), Obj->getFileName());
} else {
- if (auto EC = mergeTypeAndIdRecords(CVIDs, CVTypes, SourceToDest, Types,
+ if (Error E = mergeTypeAndIdRecords(CVIDs, CVTypes, SourceToDest, Types,
PCHSignature))
- return error(std::move(EC));
+ return reportError(std::move(E), Obj->getFileName());
}
}
}
W.printBinaryBlock("Data", Data);
uint32_t Magic;
- error(consume(Data, Magic));
+ if (Error E = consume(Data, Magic))
+ reportError(std::move(E), Obj->getFileName());
+
W.printHex("Magic", Magic);
if (Magic != COFF::DEBUG_SECTION_MAGIC)
return error(object_error::parse_failed);
Types.reset(Data, 100);
TypeDumpVisitor TDV(Types, &W, opts::CodeViewSubsectionBytes);
- error(codeview::visitTypeStream(Types, TDV));
+ if (Error E = codeview::visitTypeStream(Types, TDV))
+ reportError(std::move(E), Obj->getFileName());
+
W.flush();
}
error(EC);
Expected<StringRef> Res = getSectionName(Obj, AuxNumber, Assoc);
if (!Res)
- error(Res.takeError());
+ reportError(Res.takeError(), Obj->getFileName());
AssocName = *Res;
W.printNumber("AssocSection", AssocName, AuxNumber);
{
ListScope S(Writer, "MergedTypeStream");
TypeDumpVisitor TDV(TpiTypes, &Writer, opts::CodeViewSubsectionBytes);
- error(codeview::visitTypeStream(TpiTypes, TDV));
+ if (Error Err = codeview::visitTypeStream(TpiTypes, TDV))
+ reportError(std::move(Err), "<?>");
Writer.flush();
}
ListScope S(Writer, "MergedIDStream");
TypeDumpVisitor TDV(TpiTypes, &Writer, opts::CodeViewSubsectionBytes);
TDV.setIpiTypes(IpiTypes);
- error(codeview::visitTypeStream(IpiTypes, TDV));
+ if (Error Err = codeview::visitTypeStream(IpiTypes, TDV))
+ reportError(std::move(Err), "<?>");
Writer.flush();
}
}
for (const auto &Note : Obj->notes(P, Err))
ProcessNote(Note);
if (Err)
- error(std::move(Err));
+ reportError(std::move(Err), this->FileName);
}
} else {
for (const auto &S :
for (const auto &Note : Obj->notes(S, Err))
ProcessNote(Note);
if (Err)
- error(std::move(Err));
+ reportError(std::move(Err), this->FileName);
}
}
}
// integer.
if (*Offset == PrevOffset)
reportError(
- FileStr,
createStringError(object_error::parse_failed,
"could not extract a valid stack size in section %s",
- SectionName.data()));
+ SectionName.data()),
+ FileStr);
printStackSizeEntry(StackSize, FuncName);
}
uint64_t Offset = Reloc.getOffset();
if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(Elf_Addr) + 1))
- reportError(FileStr, createStringError(
- object_error::parse_failed,
- "found invalid relocation offset into section %s "
- "while trying to extract a stack size entry",
- StackSizeSectionName.data()));
+ reportError(
+ createStringError(object_error::parse_failed,
+ "found invalid relocation offset into section %s "
+ "while trying to extract a stack size entry",
+ StackSizeSectionName.data()),
+ FileStr);
uint64_t Addend = Data.getAddress(&Offset);
uint64_t SymValue = Resolver(Reloc, RelocSymValue, Addend);
// size. Check for an extra byte before we try to process the entry.
if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(Elf_Addr) + 1)) {
reportError(
- FileStr,
createStringError(
object_error::parse_failed,
"section %s ended while trying to extract a stack size entry",
- SectionName.data()));
+ SectionName.data()),
+ FileStr);
}
uint64_t SymValue = Data.getAddress(&Offset);
printFunctionStackSize(Obj, SymValue,
RelocSec.getName(RelocSectionName);
StringRef RelocName = EF->getRelocationTypeName(Reloc.getType());
reportError(
- FileStr,
createStringError(object_error::parse_failed,
"unsupported relocation type in section %s: %s",
- RelocSectionName.data(), RelocName.data()));
+ RelocSectionName.data(), RelocName.data()),
+ FileStr);
}
this->printStackSize(Obj, Reloc, FunctionSec, StackSizeSectionName,
Resolver, Data);
for (const auto &Note : Obj->notes(P, Err))
ProcessNote(Note);
if (Err)
- error(std::move(Err));
+ reportError(std::move(Err), this->FileName);
}
} else {
for (const auto &S : unwrapOrError(this->FileName, Obj->sections())) {
for (const auto &Note : Obj->notes(S, Err))
ProcessNote(Note);
if (Err)
- error(std::move(Err));
+ reportError(std::move(Err), this->FileName);
}
}
}
resolveRelocation(Ctx, Section, SectionOffset + 8, XData, Offset);
ArrayRef<uint8_t> Contents;
- error(Ctx.COFF.getSectionContents(XData, Contents));
+ if (Error E = Ctx.COFF.getSectionContents(XData, Contents))
+ reportError(std::move(E), Ctx.COFF.getFileName());
+
if (Contents.empty())
return;
const coff_section *PData = Ctx.COFF.getCOFFSection(Section);
ArrayRef<uint8_t> Contents;
- error(Ctx.COFF.getSectionContents(PData, Contents));
+
+ if (Error E = Ctx.COFF.getSectionContents(PData, Contents))
+ reportError(std::move(E), Ctx.COFF.getFileName());
if (Contents.empty())
continue;
exit(1);
}
-void reportError(StringRef Input, Error Err) {
+void reportError(Error Err, StringRef Input) {
+ assert(Err);
if (Input == "-")
Input = "<stdin>";
- error(createFileError(Input, std::move(Err)));
+ handleAllErrors(createFileError(Input, std::move(Err)),
+ [&](const ErrorInfoBase &EI) { reportError(EI.message()); });
}
void reportWarning(Twine Msg) {
});
}
-void error(Error EC) {
- if (!EC)
- return;
- handleAllErrors(std::move(EC),
- [&](const ErrorInfoBase &EI) { reportError(EI.message()); });
-}
-
void error(std::error_code EC) {
if (!EC)
return;
} // namespace llvm
-static void reportError(StringRef Input, std::error_code EC) {
- reportError(Input, errorCodeToError(EC));
+static void reportError(std::error_code EC, StringRef Input) {
+ assert(EC != readobj_error::success);
+ reportError(errorCodeToError(EC), Input);
}
static bool isMipsArch(unsigned Arch) {
std::unique_ptr<ObjDumper> Dumper;
if (std::error_code EC = createDumper(Obj, Writer, Dumper))
- reportError(FileStr, EC);
+ reportError(EC, FileStr);
if (opts::Output == opts::LLVM || opts::InputFilenames.size() > 1 || A) {
Writer.startLine() << "\n";
for (auto &Child : Arc->children(Err)) {
Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary();
if (!ChildOrErr) {
- if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) {
- reportError(Arc->getFileName(), std::move(E));
- }
+ if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
+ reportError(std::move(E), Arc->getFileName());
continue;
}
if (ObjectFile *Obj = dyn_cast<ObjectFile>(&*ChildOrErr.get()))
else if (COFFImportFile *Imp = dyn_cast<COFFImportFile>(&*ChildOrErr.get()))
dumpCOFFImportFile(Imp, Writer);
else
- reportError(Arc->getFileName(), readobj_error::unrecognized_file_format);
+ reportError(readobj_error::unrecognized_file_format, Arc->getFileName());
}
if (Err)
- reportError(Arc->getFileName(), std::move(Err));
+ reportError(std::move(Err), Arc->getFileName());
}
/// Dumps each object file in \a MachO Universal Binary;
Expected<std::unique_ptr<MachOObjectFile>> ObjOrErr = Obj.getAsObjectFile();
if (ObjOrErr)
dumpObject(&*ObjOrErr.get(), Writer);
- else if (auto E = isNotObjectErrorInvalidFileType(ObjOrErr.takeError())) {
- reportError(UBinary->getFileName(), ObjOrErr.takeError());
- }
+ else if (auto E = isNotObjectErrorInvalidFileType(ObjOrErr.takeError()))
+ reportError(ObjOrErr.takeError(), UBinary->getFileName());
else if (Expected<std::unique_ptr<Archive>> AOrErr = Obj.getAsArchive())
dumpArchive(&*AOrErr.get(), Writer);
}
ScopedPrinter &Printer) {
WindowsRes::Dumper Dumper(WinRes, Printer);
if (auto Err = Dumper.printData())
- reportError(WinRes->getFileName(), std::move(Err));
+ reportError(std::move(Err), WinRes->getFileName());
}
// Attempt to open the binary.
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File);
if (!BinaryOrErr)
- reportError(File, BinaryOrErr.takeError());
+ reportError(BinaryOrErr.takeError(), File);
Binary &Binary = *BinaryOrErr.get().getBinary();
if (Archive *Arc = dyn_cast<Archive>(&Binary))
else if (WindowsResource *WinRes = dyn_cast<WindowsResource>(&Binary))
dumpWindowsResourceFile(WinRes, Writer);
else
- reportError(File, readobj_error::unrecognized_file_format);
+ reportError(readobj_error::unrecognized_file_format, File);
CVTypes.Binaries.push_back(std::move(*BinaryOrErr));
}
// Various helper functions.
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
- void reportError(StringRef Input, Error Err);
+ void reportError(Error Err, StringRef Input);
void reportWarning(Twine Msg);
void reportWarning(StringRef Input, Error Err);
void warn(llvm::Error Err);
void error(std::error_code EC);
- void error(llvm::Error EC);
template <class T> T unwrapOrError(StringRef Input, Expected<T> EO) {
if (EO)
return *EO;
- reportError(Input, EO.takeError());
+ reportError(EO.takeError(), Input);
llvm_unreachable("reportError shouldn't return in this case");
}
} // namespace llvm