Author: Jonas Devlieghere Date: 2020-05-05T11:01:44-07:00 New Revision: 61d5b0e66394d61947d61861685b4223214f023e
URL: https://github.com/llvm/llvm-project/commit/61d5b0e66394d61947d61861685b4223214f023e DIFF: https://github.com/llvm/llvm-project/commit/61d5b0e66394d61947d61861685b4223214f023e.diff LOG: [lldb/Driver] Exit with a non-zero exit code in case of error in batch mode. We have the option to stop running commands in batch mode when an error occurs. When that happens we should exit the driver with a non-zero exit code. Differential revision: https://reviews.llvm.org/D78825 Added: Modified: lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/Shell/Commands/command-source.test lldb/test/Shell/Driver/TestProcessAttach.test lldb/test/Shell/Host/TestCustomShell.test lldb/test/Shell/Quit/TestQuitExitCodeNonInt.test lldb/test/Shell/Quit/TestQuitExitCodeTooManyArgs.test lldb/test/Shell/Reproducer/TestDiscard.test lldb/test/Shell/Reproducer/TestDump.test lldb/test/Shell/Settings/TestSettingsSet.test lldb/test/Shell/Settings/TestStopCommandSourceOnError.test lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test lldb/tools/driver/Driver.cpp Removed: ################################################################################ diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 3f727e83f12b..2cc3d47406b7 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -2816,8 +2816,10 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler, case eReturnStatusFailed: m_result.IncrementNumberOfErrors(); - if (io_handler.GetFlags().Test(eHandleCommandFlagStopOnError)) + if (io_handler.GetFlags().Test(eHandleCommandFlagStopOnError)) { + m_result.SetResult(lldb::eCommandInterpreterResultCommandError); io_handler.SetIsDone(true); + } break; case eReturnStatusQuit: diff --git a/lldb/test/Shell/Commands/command-source.test b/lldb/test/Shell/Commands/command-source.test index d8218850c32c..fa389f2a1288 100644 --- a/lldb/test/Shell/Commands/command-source.test +++ b/lldb/test/Shell/Commands/command-source.test @@ -1,8 +1,8 @@ # Check that stop command source on error. -# RUN: %lldb -x -b -o "command source -e 1 %s" 2>&1 | FileCheck %s --check-prefix STOP +# RUN: not %lldb -x -b -o "command source -e 1 %s" 2>&1 | FileCheck %s --check-prefix STOP # RUN: %lldb -x -b -o "command source -e 0 %s" 2>&1 | FileCheck %s --check-prefix CONTINUE -# RUN: %lldb -x -b -o 'settings set interpreter.stop-command-source-on-error true' -o "command source %s" 2>&1 | FileCheck %s --check-prefix STOP +# RUN: not %lldb -x -b -o 'settings set interpreter.stop-command-source-on-error true' -o "command source %s" 2>&1 | FileCheck %s --check-prefix STOP # RUN: %lldb -x -b -o 'settings set interpreter.stop-command-source-on-error false' -o "command source %s" 2>&1 | FileCheck %s --check-prefix CONTINUE bogus diff --git a/lldb/test/Shell/Driver/TestProcessAttach.test b/lldb/test/Shell/Driver/TestProcessAttach.test index 4e24ebb161b6..ab75814e21ce 100644 --- a/lldb/test/Shell/Driver/TestProcessAttach.test +++ b/lldb/test/Shell/Driver/TestProcessAttach.test @@ -1,2 +1,2 @@ -# RUN: %lldb -x -b -S %S/Inputs/process_attach_pid.in 2>&1 | FileCheck %s +# RUN: not %lldb -x -b -S %S/Inputs/process_attach_pid.in 2>&1 | FileCheck %s # CHECK: last option requires an argument diff --git a/lldb/test/Shell/Host/TestCustomShell.test b/lldb/test/Shell/Host/TestCustomShell.test index fd97b4c2b06e..75114c554493 100644 --- a/lldb/test/Shell/Host/TestCustomShell.test +++ b/lldb/test/Shell/Host/TestCustomShell.test @@ -8,7 +8,7 @@ # XFAIL: system-openbsd # RUN: %clang_host %S/Inputs/simple.c -g -o %t.out -# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s --check-prefix ERROR +# RUN: SHELL=bogus not %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s --check-prefix ERROR # RUN: env -i %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s # ERROR: error: shell expansion failed diff --git a/lldb/test/Shell/Quit/TestQuitExitCodeNonInt.test b/lldb/test/Shell/Quit/TestQuitExitCodeNonInt.test index 87c0bd41bb05..1747ddd669b6 100644 --- a/lldb/test/Shell/Quit/TestQuitExitCodeNonInt.test +++ b/lldb/test/Shell/Quit/TestQuitExitCodeNonInt.test @@ -1,4 +1,4 @@ # UNSUPPORTED: system-windows -# RUN: %lldb -b -s %s 2>&1 | FileCheck %s +# RUN: not %lldb -b -s %s 2>&1 | FileCheck %s q str // CHECK: Couldn't parse 'str' diff --git a/lldb/test/Shell/Quit/TestQuitExitCodeTooManyArgs.test b/lldb/test/Shell/Quit/TestQuitExitCodeTooManyArgs.test index a67669451e99..315adf02af4d 100644 --- a/lldb/test/Shell/Quit/TestQuitExitCodeTooManyArgs.test +++ b/lldb/test/Shell/Quit/TestQuitExitCodeTooManyArgs.test @@ -1,4 +1,4 @@ # UNSUPPORTED: system-windows -# RUN: %lldb -b -s %s 2>&1 | FileCheck %s +# RUN: not %lldb -b -s %s 2>&1 | FileCheck %s q 1 2 // CHECK: Too many arguments for 'quit' diff --git a/lldb/test/Shell/Reproducer/TestDiscard.test b/lldb/test/Shell/Reproducer/TestDiscard.test index 829aabbe2b03..aee56f77c06f 100644 --- a/lldb/test/Shell/Reproducer/TestDiscard.test +++ b/lldb/test/Shell/Reproducer/TestDiscard.test @@ -6,7 +6,7 @@ # RUN: %clang_host %S/Inputs/simple.c -g -o %t/reproducer.out # Capture but don't generate the reproducer. -# RUN: %lldb -x -b -s %S/Inputs/Discard.in --capture --capture-path %t.repro %t/reproducer.out +# RUN: not %lldb -x -b -s %S/Inputs/Discard.in --capture --capture-path %t.repro %t/reproducer.out # Make sure the directory doesn't exist. # RUN: mkdir %t.repro diff --git a/lldb/test/Shell/Reproducer/TestDump.test b/lldb/test/Shell/Reproducer/TestDump.test index 8300a97004bb..cf2c89c938b7 100644 --- a/lldb/test/Shell/Reproducer/TestDump.test +++ b/lldb/test/Shell/Reproducer/TestDump.test @@ -25,9 +25,9 @@ # RUN: %lldb --replay %t.repro | FileCheck %s --check-prefix FILES # RUN: rm %t.repro/gdb-remote.yaml -# RUN: %lldb -b -o 'reproducer dump -p gdb -f %t.repro' 2>&1 | FileCheck %s --check-prefix GDB-ERROR +# RUN: not %lldb -b -o 'reproducer dump -p gdb -f %t.repro' 2>&1 | FileCheck %s --check-prefix GDB-ERROR # GDB-ERROR: error: Unable to create GDB loader. # RUN: rm %t.repro/command-interpreter.yaml -# RUN: %lldb -b -o 'reproducer dump -p commands -f %t.repro' 2>&1 | FileCheck %s --check-prefix COMMANDS-ERROR +# RUN: not %lldb -b -o 'reproducer dump -p commands -f %t.repro' 2>&1 | FileCheck %s --check-prefix COMMANDS-ERROR # COMMANDS-ERROR: error: Unable to create command loader. diff --git a/lldb/test/Shell/Settings/TestSettingsSet.test b/lldb/test/Shell/Settings/TestSettingsSet.test index 0def3faaadbb..3006a694a16b 100644 --- a/lldb/test/Shell/Settings/TestSettingsSet.test +++ b/lldb/test/Shell/Settings/TestSettingsSet.test @@ -1,7 +1,7 @@ # This tests setting setting values. # Check that setting an empty value with -f(orce) clears the value. -# RUN: %lldb -b -s %s 2>&1 | FileCheck %s +# RUN: not %lldb -b -s %s 2>&1 | FileCheck %s settings set tab-size 16 settings show tab-size diff --git a/lldb/test/Shell/Settings/TestStopCommandSourceOnError.test b/lldb/test/Shell/Settings/TestStopCommandSourceOnError.test index a53dc2cd6868..d734a0940a2d 100644 --- a/lldb/test/Shell/Settings/TestStopCommandSourceOnError.test +++ b/lldb/test/Shell/Settings/TestStopCommandSourceOnError.test @@ -12,13 +12,13 @@ # RUN: %lldb -b -o 'settings set interpreter.stop-command-source-on-error false' -s %S/Inputs/StopCommandSource.in | FileCheck %s --check-prefix CONTINUE # FIXME: Should continue -# RUN: %lldb -b -s %S/Inputs/DontStopCommandSource.in -o 'bogus' -o 'print 111100000 + 11111' | FileCheck %s --check-prefix STOP +# RUN: not %lldb -b -s %S/Inputs/DontStopCommandSource.in -o 'bogus' -o 'print 111100000 + 11111' | FileCheck %s --check-prefix STOP # FIXME: Should continue -# RUN: %lldb -b -o 'settings set interpreter.stop-command-source-on-error false' -o 'bogus' -o 'print 123400000 + 56789' | FileCheck %s --check-prefix STOP +# RUN: not %lldb -b -o 'settings set interpreter.stop-command-source-on-error false' -o 'bogus' -o 'print 123400000 + 56789' | FileCheck %s --check-prefix STOP # FIXME: Should continue -# RUN: %lldb -b -s %S/Inputs/DontStopCommandSource.in | FileCheck %s --check-prefix STOP +# RUN: not %lldb -b -s %S/Inputs/DontStopCommandSource.in | FileCheck %s --check-prefix STOP # FIXME: Should continue -# RUN: %lldb -b -o 'settings set interpreter.stop-command-source-on-error true' -s %S/Inputs/DontStopCommandSource.in | FileCheck %s --check-prefix STOP +# RUN: not %lldb -b -o 'settings set interpreter.stop-command-source-on-error true' -s %S/Inputs/DontStopCommandSource.in | FileCheck %s --check-prefix STOP diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test b/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test index f9c02061fc86..8f2ef7135afc 100644 --- a/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test +++ b/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test @@ -14,10 +14,10 @@ LOOKUPE: no type was found matching 'E' RUN: %lldb %t -b -o "type lookup EC" | FileCheck --check-prefix=LOOKUPEC %s LOOKUPEC: no type was found matching 'EC' -RUN: %lldb %t -b -o "print (E) 1" 2>&1 | FileCheck --check-prefix=PRINTE %s +RUN: not %lldb %t -b -o "print (E) 1" 2>&1 | FileCheck --check-prefix=PRINTE %s PRINTE: use of undeclared identifier 'E' -RUN: %lldb %t -b -o "print (EC) 1" 2>&1 | FileCheck --check-prefix=PRINTEC %s +RUN: not %lldb %t -b -o "print (EC) 1" 2>&1 | FileCheck --check-prefix=PRINTEC %s PRINTEC: use of undeclared identifier 'EC' RUN: %lldb %t -b -o "target variable a e ec" | FileCheck --check-prefix=VARS %s diff --git a/lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test b/lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test index e748b4e5c73c..682b0e5332b1 100644 --- a/lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test +++ b/lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test @@ -5,7 +5,7 @@ # UNSUPPORTED: system-windows # RUN: %clang_host %p/Inputs/call-asm.c -x assembler-with-cpp %p/Inputs/thread-step-out-ret-addr-check.s -o %t -# RUN: %lldb %t -s %s -b 2>&1 | FileCheck %s +# RUN: not %lldb %t -s %s -b 2>&1 | FileCheck %s breakpoint set -n nonstandard_stub # CHECK: Breakpoint 1: where = {{.*}}`nonstandard_stub diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp index ff7ed2ca0544..b38423b28559 100644 --- a/lldb/tools/driver/Driver.cpp +++ b/lldb/tools/driver/Driver.cpp @@ -619,6 +619,12 @@ int Driver::MainLoop() { results.GetResult() != lldb::eCommandInterpreterResultInferiorCrash) go_interactive = false; + // When running in batch mode and stopped because of an error, exit with a + // non-zero exit status. + if (m_option_data.m_batch && + results.GetResult() == lldb::eCommandInterpreterResultCommandError) + exit(1); + if (m_option_data.m_batch && results.GetResult() == lldb::eCommandInterpreterResultInferiorCrash && !m_option_data.m_after_crash_commands.empty()) { @@ -636,6 +642,13 @@ int Driver::MainLoop() { if (local_results.GetResult() == lldb::eCommandInterpreterResultQuitRequested) go_interactive = false; + + // When running in batch mode and an error occurred while sourcing + // the crash commands, exit with a non-zero exit status. + if (m_option_data.m_batch && + local_results.GetResult() == + lldb::eCommandInterpreterResultCommandError) + exit(1); } } m_debugger.SetAsync(old_async); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits