31 changes: 27 additions & 4 deletions lldb/tools/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ static OptionDefinition g_options[] =
{ LLDB_3_TO_5, false, "one-line-before-file" , 'O', required_argument, 0, eArgTypeNone,
"Tells the debugger to execute this one-line lldb command before any file provided on the command line has been loaded." },
{ LLDB_3_TO_5, false, "source-quietly" , 'Q', no_argument , 0, eArgTypeNone,
"Tells the debugger suppress output from commands provided in the -s, -S, -O and -o commands." },
"Tells the debugger to execute this one-line lldb command before any file provided on the command line has been loaded." },
{ LLDB_3_TO_5, false, "batch" , 'b', no_argument , 0, eArgTypeNone,
"Tells the debugger to running the commands from -s, -S, -o & -O, and then quit. However if any run command stopped due to a signal or crash, "
"the debugger will return to the interactive prompt at the place of the crash." },
{ LLDB_3_TO_5, false, "editor" , 'e', no_argument , 0, eArgTypeNone,
"Tells the debugger to open source files using the host's \"external editor\" mechanism." },
{ LLDB_3_TO_5, false, "no-lldbinit" , 'x', no_argument , 0, eArgTypeNone,
Expand Down Expand Up @@ -406,6 +409,7 @@ Driver::OptionData::OptionData () :
m_process_name(),
m_process_pid(LLDB_INVALID_PROCESS_ID),
m_use_external_editor(false),
m_batch(false),
m_seen_options()
{
}
Expand All @@ -429,6 +433,7 @@ Driver::OptionData::Clear ()
m_use_external_editor = false;
m_wait_for = false;
m_process_name.erase();
m_batch = false;
m_process_pid = LLDB_INVALID_PROCESS_ID;
}

Expand Down Expand Up @@ -641,6 +646,10 @@ Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &exiting)
m_option_data.m_print_python_path = true;
break;

case 'b':
m_option_data.m_batch = true;
break;

case 'c':
{
SBFileSpec file(optarg);
Expand Down Expand Up @@ -924,6 +933,7 @@ Driver::MainLoop ()

// The command file might have requested that we quit, this variable will track that.
bool quit_requested = false;
bool stopped_for_crash = false;
if (commands_data && commands_size)
{
enum PIPES { READ, WRITE }; // Constants 0 and 1 for READ and WRITE
Expand Down Expand Up @@ -973,8 +983,15 @@ Driver::MainLoop ()

SBCommandInterpreterRunOptions options;
options.SetStopOnError (true);

m_debugger.RunCommandInterpreter(handle_events, spawn_thread, options, num_errors, quit_requested);
if (m_option_data.m_batch)
options.SetStopOnCrash (true);

m_debugger.RunCommandInterpreter(handle_events,
spawn_thread,
options,
num_errors,
quit_requested,
stopped_for_crash);
m_debugger.SetAsync(old_async);
}
else
Expand Down Expand Up @@ -1030,7 +1047,13 @@ Driver::MainLoop ()
// interpreter again in interactive mode and let the debugger
// take ownership of stdin

if (!quit_requested)
bool go_interactive = true;
if (quit_requested)
go_interactive = false;
else if (m_option_data.m_batch && !stopped_for_crash)
go_interactive = false;

if (go_interactive)
{
m_debugger.SetInputFileHandle (stdin, true);
m_debugger.RunCommandInterpreter(handle_events, spawn_thread);
Expand Down
1 change: 1 addition & 0 deletions lldb/tools/driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Driver : public lldb::SBBroadcaster
std::string m_process_name;
lldb::pid_t m_process_pid;
bool m_use_external_editor; // FIXME: When we have set/show variables we can remove this from here.
bool m_batch;
typedef std::set<char> OptionSet;
OptionSet m_seen_options;
};
Expand Down