JDevlieghere updated this revision to Diff 261382. JDevlieghere marked 2 inline comments as done.
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79120/new/ https://reviews.llvm.org/D79120 Files: lldb/include/lldb/API/SBCommandInterpreterRunOptions.h lldb/include/lldb/API/SBDebugger.h lldb/include/lldb/API/SBDefines.h lldb/source/API/SBCommandInterpreterRunOptions.cpp lldb/source/API/SBDebugger.cpp lldb/tools/driver/Driver.cpp
Index: lldb/tools/driver/Driver.cpp =================================================================== --- lldb/tools/driver/Driver.cpp +++ lldb/tools/driver/Driver.cpp @@ -588,10 +588,7 @@ const char *commands_data = commands_stream.GetData(); const size_t commands_size = commands_stream.GetSize(); - // The command file might have requested that we quit, this variable will - // track that. - bool quit_requested = false; - bool stopped_for_crash = false; + bool go_interactive = true; if ((commands_data != nullptr) && (commands_size != 0u)) { FILE *commands_file = PrepareCommandsForSourcing(commands_data, commands_size); @@ -603,23 +600,27 @@ m_debugger.SetInputFileHandle(commands_file, true); - // Set the debugger into Sync mode when running the command file. - // Otherwise command files - // that run the target won't run in a sensible way. + // Set the debugger into Sync mode when running the command file. Otherwise + // command files that run the target won't run in a sensible way. bool old_async = m_debugger.GetAsync(); m_debugger.SetAsync(false); - int num_errors = 0; SBCommandInterpreterRunOptions options; + options.SetAutoHandleEvents(true); + options.SetSpawnThread(false); options.SetStopOnError(true); - if (m_option_data.m_batch) - options.SetStopOnCrash(true); - - m_debugger.RunCommandInterpreter(handle_events, spawn_thread, options, - num_errors, quit_requested, - stopped_for_crash); - - if (m_option_data.m_batch && stopped_for_crash && + options.SetStopOnCrash(m_option_data.m_batch); + + SBCommandInterpreterRunResult results = + m_debugger.RunCommandInterpreter(options); + if (results.GetResult() == lldb::eCommandInterpreterResultQuitRequested) + go_interactive = false; + if (m_option_data.m_batch && + results.GetResult() != lldb::eCommandInterpreterResultInferiorCrash) + go_interactive = false; + + if (m_option_data.m_batch && + results.GetResult() == lldb::eCommandInterpreterResultInferiorCrash && !m_option_data.m_after_crash_commands.empty()) { SBStream crash_commands_stream; WriteCommandsForSourcing(eCommandPlacementAfterCrash, @@ -629,30 +630,20 @@ commands_file = PrepareCommandsForSourcing(crash_commands_data, crash_commands_size); if (commands_file != nullptr) { - bool local_quit_requested; - bool local_stopped_for_crash; m_debugger.SetInputFileHandle(commands_file, true); - - m_debugger.RunCommandInterpreter(handle_events, spawn_thread, options, - num_errors, local_quit_requested, - local_stopped_for_crash); - if (local_quit_requested) - quit_requested = true; + SBCommandInterpreterRunResult local_results = + m_debugger.RunCommandInterpreter(options); + if (local_results.GetResult() == + lldb::eCommandInterpreterResultQuitRequested) + go_interactive = false; } } m_debugger.SetAsync(old_async); } - // Now set the input file handle to STDIN and run the command - // interpreter again in interactive mode or repl mode and let the debugger - // take ownership of stdin - - bool go_interactive = true; - if (quit_requested) - go_interactive = false; - else if (m_option_data.m_batch && !stopped_for_crash) - go_interactive = false; - + // Now set the input file handle to STDIN and run the command interpreter + // again in interactive mode or repl mode and let the debugger take ownership + // of stdin. if (go_interactive) { m_debugger.SetInputFileHandle(stdin, true); Index: lldb/source/API/SBDebugger.cpp =================================================================== --- lldb/source/API/SBDebugger.cpp +++ lldb/source/API/SBDebugger.cpp @@ -1200,6 +1200,18 @@ } } +SBCommandInterpreterRunResult SBDebugger::RunCommandInterpreter( + const SBCommandInterpreterRunOptions &options) { + if (!m_opaque_sp) + return {}; + + CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter(); + CommandInterpreterRunResult result = + interp.RunCommandInterpreter(options.ref()); + + return SBCommandInterpreterRunResult(result); +} + SBError SBDebugger::RunREPL(lldb::LanguageType language, const char *repl_options) { LLDB_RECORD_METHOD(lldb::SBError, SBDebugger, RunREPL, Index: lldb/source/API/SBCommandInterpreterRunOptions.cpp =================================================================== --- lldb/source/API/SBCommandInterpreterRunOptions.cpp +++ lldb/source/API/SBCommandInterpreterRunOptions.cpp @@ -163,6 +163,37 @@ return *m_opaque_up; } +SBCommandInterpreterRunResult::SBCommandInterpreterRunResult() { + m_opaque_up.reset(new CommandInterpreterRunResult()); +} + +SBCommandInterpreterRunResult::SBCommandInterpreterRunResult( + const SBCommandInterpreterRunResult &rhs) { + *m_opaque_up = *rhs.m_opaque_up; +} + +SBCommandInterpreterRunResult::SBCommandInterpreterRunResult( + const CommandInterpreterRunResult &rhs) { + m_opaque_up.reset(new CommandInterpreterRunResult(rhs)); +} + +SBCommandInterpreterRunResult::~SBCommandInterpreterRunResult() = default; + +SBCommandInterpreterRunResult &SBCommandInterpreterRunResult::operator=( + const SBCommandInterpreterRunResult &rhs) { + *m_opaque_up = *rhs.m_opaque_up; + return *this; +} + +int SBCommandInterpreterRunResult::GetNumberOfErrors() const { + return m_opaque_up->GetNumErrors(); +} + +lldb::CommandInterpreterResult +SBCommandInterpreterRunResult::GetResult() const { + return m_opaque_up->GetResult(); +} + namespace lldb_private { namespace repro { @@ -204,6 +235,7 @@ GetSpawnThread, ()); LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetSpawnThread, (bool)); + LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreterRunResult, ()); } } // namespace repro Index: lldb/include/lldb/API/SBDefines.h =================================================================== --- lldb/include/lldb/API/SBDefines.h +++ lldb/include/lldb/API/SBDefines.h @@ -28,6 +28,7 @@ class LLDB_API SBCommand; class LLDB_API SBCommandInterpreter; class LLDB_API SBCommandInterpreterRunOptions; +class LLDB_API SBCommandInterpreterRunResult; class LLDB_API SBCommandPluginInterface; class LLDB_API SBCommandReturnObject; class LLDB_API SBCommunication; Index: lldb/include/lldb/API/SBDebugger.h =================================================================== --- lldb/include/lldb/API/SBDebugger.h +++ lldb/include/lldb/API/SBDebugger.h @@ -331,6 +331,9 @@ int &num_errors, bool &quit_requested, bool &stopped_for_crash); + SBCommandInterpreterRunResult + RunCommandInterpreter(const SBCommandInterpreterRunOptions &options); + SBError RunREPL(lldb::LanguageType language, const char *repl_options); private: Index: lldb/include/lldb/API/SBCommandInterpreterRunOptions.h =================================================================== --- lldb/include/lldb/API/SBCommandInterpreterRunOptions.h +++ lldb/include/lldb/API/SBCommandInterpreterRunOptions.h @@ -13,6 +13,11 @@ #include "lldb/API/SBDefines.h" +namespace lldb_private { +class CommandInterpreterRunOptions; +class CommandInterpreterRunResult; +} // namespace lldb_private + namespace lldb { class LLDB_API SBCommandInterpreterRunOptions { @@ -69,6 +74,29 @@ m_opaque_up; }; +class LLDB_API SBCommandInterpreterRunResult { + friend class SBDebugger; + friend class SBCommandInterpreter; + +public: + SBCommandInterpreterRunResult(); + SBCommandInterpreterRunResult(const SBCommandInterpreterRunResult &rhs); + ~SBCommandInterpreterRunResult(); + + SBCommandInterpreterRunResult & + operator=(const SBCommandInterpreterRunResult &rhs); + + int GetNumberOfErrors() const; + lldb::CommandInterpreterResult GetResult() const; + +private: + SBCommandInterpreterRunResult( + const lldb_private::CommandInterpreterRunResult &rhs); + + // This is set in the constructor and will always be valid. + std::unique_ptr<lldb_private::CommandInterpreterRunResult> m_opaque_up; +}; + } // namespace lldb #endif // LLDB_API_SBCOMMANDINTERPRETERRUNOPTIONS_H
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits