Make llvm-dwarfdump exit with non-zero exit code if error was occured.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240729 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov 2015-06-25 23:40:15 +00:00
parent 1688551243
commit 1cf2b03af4
3 changed files with 18 additions and 13 deletions

View File

@ -26,5 +26,5 @@ OPTIONS
EXIT STATUS
-----------
:program:`llvm-dwarfdump` returns 0. Other exit codes imply internal
program error.
:program:`llvm-dwarfdump` returns 0 if the input files were parsed and dumped
successfully. Otherwise, it returns 1.

View File

@ -1,6 +1,6 @@
; Verify that llvm-dwarfdump doesn't crash on broken input files.
RUN: llvm-dwarfdump %p/Inputs/invalid.elf 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
RUN: llvm-dwarfdump %p/Inputs/invalid.elf.2 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
RUN: llvm-dwarfdump %p/Inputs/invalid.elf.3 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
RUN: not llvm-dwarfdump %p/Inputs/invalid.elf 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
RUN: not llvm-dwarfdump %p/Inputs/invalid.elf.2 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
RUN: not llvm-dwarfdump %p/Inputs/invalid.elf.3 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
INVALID-ELF: Invalid data was encountered while parsing the file

View File

@ -69,22 +69,27 @@ DumpType("debug-dump", cl::init(DIDT_All),
clEnumValN(DIDT_StrOffsetsDwo, "str_offsets.dwo", ".debug_str_offsets.dwo"),
clEnumValEnd));
static int ReturnValue = EXIT_SUCCESS;
static bool error(StringRef Filename, std::error_code EC) {
if (!EC)
return false;
errs() << Filename << ": " << EC.message() << "\n";
ReturnValue = EXIT_FAILURE;
return true;
}
static void DumpInput(StringRef Filename) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BuffOrErr =
MemoryBuffer::getFileOrSTDIN(Filename);
if (std::error_code EC = BuffOrErr.getError()) {
errs() << Filename << ": " << EC.message() << "\n";
if (error(Filename, BuffOrErr.getError()))
return;
}
std::unique_ptr<MemoryBuffer> Buff = std::move(BuffOrErr.get());
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
ObjectFile::createObjectFile(Buff->getMemBufferRef());
if (std::error_code EC = ObjOrErr.getError()) {
errs() << Filename << ": " << EC.message() << '\n';
if (error(Filename, ObjOrErr.getError()))
return;
}
ObjectFile &Obj = *ObjOrErr.get();
std::unique_ptr<DIContext> DICtx(new DWARFContextInMemory(Obj));
@ -109,5 +114,5 @@ int main(int argc, char **argv) {
std::for_each(InputFilenames.begin(), InputFilenames.end(), DumpInput);
return 0;
return ReturnValue;
}