Skip to content

Commit 61d5b0e

Browse files
committed
[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
1 parent 8fc7a90 commit 61d5b0e

13 files changed

+33
-18
lines changed

lldb/source/Interpreter/CommandInterpreter.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2816,8 +2816,10 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler,
28162816

28172817
case eReturnStatusFailed:
28182818
m_result.IncrementNumberOfErrors();
2819-
if (io_handler.GetFlags().Test(eHandleCommandFlagStopOnError))
2819+
if (io_handler.GetFlags().Test(eHandleCommandFlagStopOnError)) {
2820+
m_result.SetResult(lldb::eCommandInterpreterResultCommandError);
28202821
io_handler.SetIsDone(true);
2822+
}
28212823
break;
28222824

28232825
case eReturnStatusQuit:

lldb/test/Shell/Commands/command-source.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Check that stop command source on error.
22

3-
# RUN: %lldb -x -b -o "command source -e 1 %s" 2>&1 | FileCheck %s --check-prefix STOP
3+
# RUN: not %lldb -x -b -o "command source -e 1 %s" 2>&1 | FileCheck %s --check-prefix STOP
44
# RUN: %lldb -x -b -o "command source -e 0 %s" 2>&1 | FileCheck %s --check-prefix CONTINUE
5-
# 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
5+
# 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
66
# 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
77

88
bogus
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# RUN: %lldb -x -b -S %S/Inputs/process_attach_pid.in 2>&1 | FileCheck %s
1+
# RUN: not %lldb -x -b -S %S/Inputs/process_attach_pid.in 2>&1 | FileCheck %s
22
# CHECK: last option requires an argument

lldb/test/Shell/Host/TestCustomShell.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# XFAIL: system-openbsd
99

1010
# RUN: %clang_host %S/Inputs/simple.c -g -o %t.out
11-
# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s --check-prefix ERROR
11+
# RUN: SHELL=bogus not %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s --check-prefix ERROR
1212
# RUN: env -i %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
1313

1414
# ERROR: error: shell expansion failed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# UNSUPPORTED: system-windows
2-
# RUN: %lldb -b -s %s 2>&1 | FileCheck %s
2+
# RUN: not %lldb -b -s %s 2>&1 | FileCheck %s
33
q str
44
// CHECK: Couldn't parse 'str'
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# UNSUPPORTED: system-windows
2-
# RUN: %lldb -b -s %s 2>&1 | FileCheck %s
2+
# RUN: not %lldb -b -s %s 2>&1 | FileCheck %s
33
q 1 2
44
// CHECK: Too many arguments for 'quit'

lldb/test/Shell/Reproducer/TestDiscard.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# RUN: %clang_host %S/Inputs/simple.c -g -o %t/reproducer.out
77

88
# Capture but don't generate the reproducer.
9-
# RUN: %lldb -x -b -s %S/Inputs/Discard.in --capture --capture-path %t.repro %t/reproducer.out
9+
# RUN: not %lldb -x -b -s %S/Inputs/Discard.in --capture --capture-path %t.repro %t/reproducer.out
1010

1111
# Make sure the directory doesn't exist.
1212
# RUN: mkdir %t.repro

lldb/test/Shell/Reproducer/TestDump.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
# RUN: %lldb --replay %t.repro | FileCheck %s --check-prefix FILES
2626

2727
# RUN: rm %t.repro/gdb-remote.yaml
28-
# RUN: %lldb -b -o 'reproducer dump -p gdb -f %t.repro' 2>&1 | FileCheck %s --check-prefix GDB-ERROR
28+
# RUN: not %lldb -b -o 'reproducer dump -p gdb -f %t.repro' 2>&1 | FileCheck %s --check-prefix GDB-ERROR
2929
# GDB-ERROR: error: Unable to create GDB loader.
3030

3131
# RUN: rm %t.repro/command-interpreter.yaml
32-
# RUN: %lldb -b -o 'reproducer dump -p commands -f %t.repro' 2>&1 | FileCheck %s --check-prefix COMMANDS-ERROR
32+
# RUN: not %lldb -b -o 'reproducer dump -p commands -f %t.repro' 2>&1 | FileCheck %s --check-prefix COMMANDS-ERROR
3333
# COMMANDS-ERROR: error: Unable to create command loader.

lldb/test/Shell/Settings/TestSettingsSet.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This tests setting setting values.
22

33
# Check that setting an empty value with -f(orce) clears the value.
4-
# RUN: %lldb -b -s %s 2>&1 | FileCheck %s
4+
# RUN: not %lldb -b -s %s 2>&1 | FileCheck %s
55

66
settings set tab-size 16
77
settings show tab-size

lldb/test/Shell/Settings/TestStopCommandSourceOnError.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
# RUN: %lldb -b -o 'settings set interpreter.stop-command-source-on-error false' -s %S/Inputs/StopCommandSource.in | FileCheck %s --check-prefix CONTINUE
1313

1414
# FIXME: Should continue
15-
# RUN: %lldb -b -s %S/Inputs/DontStopCommandSource.in -o 'bogus' -o 'print 111100000 + 11111' | FileCheck %s --check-prefix STOP
15+
# RUN: not %lldb -b -s %S/Inputs/DontStopCommandSource.in -o 'bogus' -o 'print 111100000 + 11111' | FileCheck %s --check-prefix STOP
1616

1717
# FIXME: Should continue
18-
# RUN: %lldb -b -o 'settings set interpreter.stop-command-source-on-error false' -o 'bogus' -o 'print 123400000 + 56789' | FileCheck %s --check-prefix STOP
18+
# 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
1919

2020
# FIXME: Should continue
21-
# RUN: %lldb -b -s %S/Inputs/DontStopCommandSource.in | FileCheck %s --check-prefix STOP
21+
# RUN: not %lldb -b -s %S/Inputs/DontStopCommandSource.in | FileCheck %s --check-prefix STOP
2222

2323
# FIXME: Should continue
24-
# RUN: %lldb -b -o 'settings set interpreter.stop-command-source-on-error true' -s %S/Inputs/DontStopCommandSource.in | FileCheck %s --check-prefix STOP
24+
# RUN: not %lldb -b -o 'settings set interpreter.stop-command-source-on-error true' -s %S/Inputs/DontStopCommandSource.in | FileCheck %s --check-prefix STOP

lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ LOOKUPE: no type was found matching 'E'
1414
RUN: %lldb %t -b -o "type lookup EC" | FileCheck --check-prefix=LOOKUPEC %s
1515
LOOKUPEC: no type was found matching 'EC'
1616

17-
RUN: %lldb %t -b -o "print (E) 1" 2>&1 | FileCheck --check-prefix=PRINTE %s
17+
RUN: not %lldb %t -b -o "print (E) 1" 2>&1 | FileCheck --check-prefix=PRINTE %s
1818
PRINTE: use of undeclared identifier 'E'
1919

20-
RUN: %lldb %t -b -o "print (EC) 1" 2>&1 | FileCheck --check-prefix=PRINTEC %s
20+
RUN: not %lldb %t -b -o "print (EC) 1" 2>&1 | FileCheck --check-prefix=PRINTEC %s
2121
PRINTEC: use of undeclared identifier 'EC'
2222

2323
RUN: %lldb %t -b -o "target variable a e ec" | FileCheck --check-prefix=VARS %s

lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# UNSUPPORTED: system-windows
66

77
# RUN: %clang_host %p/Inputs/call-asm.c -x assembler-with-cpp %p/Inputs/thread-step-out-ret-addr-check.s -o %t
8-
# RUN: %lldb %t -s %s -b 2>&1 | FileCheck %s
8+
# RUN: not %lldb %t -s %s -b 2>&1 | FileCheck %s
99

1010
breakpoint set -n nonstandard_stub
1111
# CHECK: Breakpoint 1: where = {{.*}}`nonstandard_stub

lldb/tools/driver/Driver.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ int Driver::MainLoop() {
619619
results.GetResult() != lldb::eCommandInterpreterResultInferiorCrash)
620620
go_interactive = false;
621621

622+
// When running in batch mode and stopped because of an error, exit with a
623+
// non-zero exit status.
624+
if (m_option_data.m_batch &&
625+
results.GetResult() == lldb::eCommandInterpreterResultCommandError)
626+
exit(1);
627+
622628
if (m_option_data.m_batch &&
623629
results.GetResult() == lldb::eCommandInterpreterResultInferiorCrash &&
624630
!m_option_data.m_after_crash_commands.empty()) {
@@ -636,6 +642,13 @@ int Driver::MainLoop() {
636642
if (local_results.GetResult() ==
637643
lldb::eCommandInterpreterResultQuitRequested)
638644
go_interactive = false;
645+
646+
// When running in batch mode and an error occurred while sourcing
647+
// the crash commands, exit with a non-zero exit status.
648+
if (m_option_data.m_batch &&
649+
local_results.GetResult() ==
650+
lldb::eCommandInterpreterResultCommandError)
651+
exit(1);
639652
}
640653
}
641654
m_debugger.SetAsync(old_async);

0 commit comments

Comments
 (0)