[llvm] r240729 - Make llvm-dwarfdump exit with non-zero exit code if error was occured.
Rafael EspĂndola
rafael.espindola at gmail.com
Thu Jun 25 17:18:17 PDT 2015
Thanks!
On 25 June 2015 at 19:40, Alexey Samsonov <vonosmas at gmail.com> wrote:
> Author: samsonov
> Date: Thu Jun 25 18:40:15 2015
> New Revision: 240729
>
> URL: http://llvm.org/viewvc/llvm-project?rev=240729&view=rev
> Log:
> Make llvm-dwarfdump exit with non-zero exit code if error was occured.
>
> Modified:
> llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst
> llvm/trunk/test/DebugInfo/dwarfdump-invalid.test
> llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
>
> Modified: llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst?rev=240729&r1=240728&r2=240729&view=diff
> ==============================================================================
> --- llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst (original)
> +++ llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst Thu Jun 25 18:40:15 2015
> @@ -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.
>
> Modified: llvm/trunk/test/DebugInfo/dwarfdump-invalid.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-invalid.test?rev=240729&r1=240728&r2=240729&view=diff
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/dwarfdump-invalid.test (original)
> +++ llvm/trunk/test/DebugInfo/dwarfdump-invalid.test Thu Jun 25 18:40:15 2015
> @@ -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
>
> Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=240729&r1=240728&r2=240729&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
> +++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Thu Jun 25 18:40:15 2015
> @@ -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;
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list