Author: Jonas Devlieghere Date: 2020-01-15T14:58:16-08:00 New Revision: 7ce2de2ce4e7d4dd8e1e5a7a5b35c0f98e46681d
URL: https://github.com/llvm/llvm-project/commit/7ce2de2ce4e7d4dd8e1e5a7a5b35c0f98e46681d DIFF: https://github.com/llvm/llvm-project/commit/7ce2de2ce4e7d4dd8e1e5a7a5b35c0f98e46681d.diff LOG: [lldb/Debugger] Rename IO handler methods to be more meaningful (NFC) Make it clear form the method names whether they are synchronous or asynchronous. Added: Modified: lldb/include/lldb/Core/Debugger.h lldb/source/Commands/CommandObjectCommands.cpp lldb/source/Commands/CommandObjectExpression.cpp lldb/source/Commands/CommandObjectGUI.cpp lldb/source/Core/Debugger.cpp lldb/source/Expression/REPL.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/source/Target/Process.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index a8048427c8f1..6ee39f62be98 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -190,13 +190,15 @@ class Debugger : public std::enable_shared_from_this<Debugger>, lldb::StreamFileSP &out, lldb::StreamFileSP &err); - void PushIOHandler(const lldb::IOHandlerSP &reader_sp, - bool cancel_top_handler = true); + /// Run the given IO handler and return immediately. + void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp, + bool cancel_top_handler = true); - bool PopIOHandler(const lldb::IOHandlerSP &reader_sp); + /// Run the given IO handler and block until it's complete. + void RunIOHandlerSync(const lldb::IOHandlerSP &reader_sp); - // Synchronously run an input reader until it is done - void RunIOHandler(const lldb::IOHandlerSP &reader_sp); + /// Remove the given IO handler if it's currently active. + bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp); bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp); @@ -339,6 +341,11 @@ class Debugger : public std::enable_shared_from_this<Debugger>, static lldb::thread_result_t EventHandlerThread(lldb::thread_arg_t arg); + void PushIOHandler(const lldb::IOHandlerSP &reader_sp, + bool cancel_top_handler = true); + + bool PopIOHandler(const lldb::IOHandlerSP &reader_sp); + bool HasIOHandlerThread(); bool StartIOHandlerThread(); @@ -402,7 +409,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>, std::array<lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown> m_script_interpreters; - IOHandlerStack m_input_reader_stack; + IOHandlerStack m_io_handler_stack; llvm::StringMap<std::weak_ptr<llvm::raw_ostream>> m_log_streams; std::shared_ptr<llvm::raw_ostream> m_log_callback_stream_sp; ConstString m_instance_name; diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 388db6fad631..ffa261dae33c 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -1007,7 +1007,7 @@ a number follows 'f':" *this, nullptr)); if (io_handler_sp) { - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); result.SetStatus(eReturnStatusSuccessFinishNoResult); } } else { diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index db90dde98eff..375343ae8be3 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -535,7 +535,7 @@ void CommandObjectExpression::GetMultilineExpression() { "Enter expressions, then terminate with an empty line to evaluate:\n"); output_sp->Flush(); } - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); } static EvaluateExpressionOptions @@ -622,10 +622,8 @@ bool CommandObjectExpression::DoExecute(llvm::StringRef command, } IOHandlerSP io_handler_sp(repl_sp->GetIOHandler()); - io_handler_sp->SetIsDone(false); - - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); } else { repl_error.SetErrorStringWithFormat( "Couldn't create a REPL for %s", diff --git a/lldb/source/Commands/CommandObjectGUI.cpp b/lldb/source/Commands/CommandObjectGUI.cpp index 67ddc68a169e..762163b2670a 100644 --- a/lldb/source/Commands/CommandObjectGUI.cpp +++ b/lldb/source/Commands/CommandObjectGUI.cpp @@ -35,7 +35,7 @@ bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) { input.GetIsInteractive()) { IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger)); if (io_handler_sp) - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); result.SetStatus(eReturnStatusSuccessFinishResult); } else { result.AppendError("the gui command requires an interactive terminal."); diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 33f72a0896cb..eafb64173f6a 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -708,7 +708,7 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) m_source_manager_up(), m_source_file_cache(), m_command_interpreter_up( std::make_unique<CommandInterpreter>(*this, false)), - m_input_reader_stack(), m_instance_name(), m_loaded_plugins(), + m_io_handler_stack(), m_instance_name(), m_loaded_plugins(), m_event_handler_thread(), m_io_handler_thread(), m_sync_broadcaster(nullptr, "lldb.debugger.sync"), m_forward_listener_sp(), m_clear_once() { @@ -870,15 +870,15 @@ ExecutionContext Debugger::GetSelectedExecutionContext() { } void Debugger::DispatchInputInterrupt() { - std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); - IOHandlerSP reader_sp(m_input_reader_stack.Top()); + std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex()); + IOHandlerSP reader_sp(m_io_handler_stack.Top()); if (reader_sp) reader_sp->Interrupt(); } void Debugger::DispatchInputEndOfFile() { - std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); - IOHandlerSP reader_sp(m_input_reader_stack.Top()); + std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex()); + IOHandlerSP reader_sp(m_io_handler_stack.Top()); if (reader_sp) reader_sp->GotEOF(); } @@ -886,9 +886,9 @@ void Debugger::DispatchInputEndOfFile() { void Debugger::ClearIOHandlers() { // The bottom input reader should be the main debugger input reader. We do // not want to close that one here. - std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); - while (m_input_reader_stack.GetSize() > 1) { - IOHandlerSP reader_sp(m_input_reader_stack.Top()); + std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex()); + while (m_io_handler_stack.GetSize() > 1) { + IOHandlerSP reader_sp(m_io_handler_stack.Top()); if (reader_sp) PopIOHandler(reader_sp); } @@ -896,7 +896,7 @@ void Debugger::ClearIOHandlers() { void Debugger::ExecuteIOHandlers() { while (true) { - IOHandlerSP reader_sp(m_input_reader_stack.Top()); + IOHandlerSP reader_sp(m_io_handler_stack.Top()); if (!reader_sp) break; @@ -904,7 +904,7 @@ void Debugger::ExecuteIOHandlers() { // Remove all input readers that are done from the top of the stack while (true) { - IOHandlerSP top_reader_sp = m_input_reader_stack.Top(); + IOHandlerSP top_reader_sp = m_io_handler_stack.Top(); if (top_reader_sp && top_reader_sp->GetIsDone()) PopIOHandler(top_reader_sp); else @@ -915,33 +915,42 @@ void Debugger::ExecuteIOHandlers() { } bool Debugger::IsTopIOHandler(const lldb::IOHandlerSP &reader_sp) { - return m_input_reader_stack.IsTop(reader_sp); + return m_io_handler_stack.IsTop(reader_sp); } bool Debugger::CheckTopIOHandlerTypes(IOHandler::Type top_type, IOHandler::Type second_top_type) { - return m_input_reader_stack.CheckTopIOHandlerTypes(top_type, second_top_type); + return m_io_handler_stack.CheckTopIOHandlerTypes(top_type, second_top_type); } void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) { lldb_private::StreamFile &stream = is_stdout ? GetOutputStream() : GetErrorStream(); - m_input_reader_stack.PrintAsync(&stream, s, len); + m_io_handler_stack.PrintAsync(&stream, s, len); } ConstString Debugger::GetTopIOHandlerControlSequence(char ch) { - return m_input_reader_stack.GetTopIOHandlerControlSequence(ch); + return m_io_handler_stack.GetTopIOHandlerControlSequence(ch); } const char *Debugger::GetIOHandlerCommandPrefix() { - return m_input_reader_stack.GetTopIOHandlerCommandPrefix(); + return m_io_handler_stack.GetTopIOHandlerCommandPrefix(); } const char *Debugger::GetIOHandlerHelpPrologue() { - return m_input_reader_stack.GetTopIOHandlerHelpPrologue(); + return m_io_handler_stack.GetTopIOHandlerHelpPrologue(); } -void Debugger::RunIOHandler(const IOHandlerSP &reader_sp) { +bool Debugger::RemoveIOHandler(const IOHandlerSP &reader_sp) { + return PopIOHandler(reader_sp); +} + +void Debugger::RunIOHandlerAsync(const IOHandlerSP &reader_sp, + bool cancel_top_handler) { + PushIOHandler(reader_sp, cancel_top_handler); +} + +void Debugger::RunIOHandlerSync(const IOHandlerSP &reader_sp) { PushIOHandler(reader_sp); IOHandlerSP top_reader_sp = reader_sp; @@ -954,7 +963,7 @@ void Debugger::RunIOHandler(const IOHandlerSP &reader_sp) { } while (true) { - top_reader_sp = m_input_reader_stack.Top(); + top_reader_sp = m_io_handler_stack.Top(); if (top_reader_sp && top_reader_sp->GetIsDone()) PopIOHandler(top_reader_sp); else @@ -970,8 +979,8 @@ void Debugger::AdoptTopIOHandlerFilesIfInvalid(FileSP &in, StreamFileSP &out, // input reader's in/out/err streams, or fall back to the debugger file // handles, or we fall back onto stdin/stdout/stderr as a last resort. - std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); - IOHandlerSP top_reader_sp(m_input_reader_stack.Top()); + std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex()); + IOHandlerSP top_reader_sp(m_io_handler_stack.Top()); // If no STDIN has been set, then set it appropriately if (!in || !in->IsValid()) { if (top_reader_sp) @@ -1009,17 +1018,17 @@ void Debugger::PushIOHandler(const IOHandlerSP &reader_sp, if (!reader_sp) return; - std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); + std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex()); // Get the current top input reader... - IOHandlerSP top_reader_sp(m_input_reader_stack.Top()); + IOHandlerSP top_reader_sp(m_io_handler_stack.Top()); // Don't push the same IO handler twice... if (reader_sp == top_reader_sp) return; // Push our new input reader - m_input_reader_stack.Push(reader_sp); + m_io_handler_stack.Push(reader_sp); reader_sp->Activate(); // Interrupt the top input reader to it will exit its Run() function and let @@ -1035,23 +1044,23 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) { if (!pop_reader_sp) return false; - std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); + std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex()); // The reader on the stop of the stack is done, so let the next read on the // stack refresh its prompt and if there is one... - if (m_input_reader_stack.IsEmpty()) + if (m_io_handler_stack.IsEmpty()) return false; - IOHandlerSP reader_sp(m_input_reader_stack.Top()); + IOHandlerSP reader_sp(m_io_handler_stack.Top()); if (pop_reader_sp != reader_sp) return false; reader_sp->Deactivate(); reader_sp->Cancel(); - m_input_reader_stack.Pop(); + m_io_handler_stack.Pop(); - reader_sp = m_input_reader_stack.Top(); + reader_sp = m_io_handler_stack.Top(); if (reader_sp) reader_sp->Activate(); diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp index fcd083684738..57bd949bc302 100644 --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -252,7 +252,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { lldb::IOHandlerSP io_handler_sp(ci.GetIOHandler()); if (io_handler_sp) { io_handler_sp->SetIsDone(false); - debugger.PushIOHandler(ci.GetIOHandler()); + debugger.RunIOHandlerAsync(ci.GetIOHandler()); } } } @@ -370,7 +370,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { lldb::IOHandlerSP io_handler_sp(ci.GetIOHandler()); if (io_handler_sp) { io_handler_sp->SetIsDone(false); - debugger.PushIOHandler(ci.GetIOHandler()); + debugger.RunIOHandlerAsync(ci.GetIOHandler()); } } break; @@ -530,7 +530,7 @@ Status REPL::RunLoop() { save_default_line); } - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); // Check if we are in dedicated REPL mode where LLDB was start with the "-- // repl" option from the command line. Currently we know this by checking if diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 1ee80503f569..3701ee1d0d27 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1854,7 +1854,7 @@ bool CommandInterpreter::Confirm(llvm::StringRef message, bool default_answer) { IOHandlerConfirm *confirm = new IOHandlerConfirm(m_debugger, message, default_answer); IOHandlerSP io_handler_sp(confirm); - m_debugger.RunIOHandler(io_handler_sp); + m_debugger.RunIOHandlerSync(io_handler_sp); return confirm->GetResponse(); } @@ -2477,7 +2477,7 @@ void CommandInterpreter::HandleCommandsFromFile( m_command_source_depth++; - debugger.RunIOHandler(io_handler_sp); + debugger.RunIOHandlerSync(io_handler_sp); if (!m_command_source_flags.empty()) m_command_source_flags.pop_back(); m_command_source_depth--; @@ -2854,7 +2854,7 @@ void CommandInterpreter::GetLLDBCommandsFromIOHandler( if (io_handler_sp) { io_handler_sp->SetUserData(baton); - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); } } @@ -2874,7 +2874,7 @@ void CommandInterpreter::GetPythonCommandsFromIOHandler( if (io_handler_sp) { io_handler_sp->SetUserData(baton); - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); } } @@ -2934,7 +2934,7 @@ void CommandInterpreter::RunCommandInterpreter( // Always re-create the command interpreter when we run it in case any file // handles have changed. bool force_create = true; - m_debugger.PushIOHandler(GetIOHandler(force_create, &options)); + m_debugger.RunIOHandlerAsync(GetIOHandler(force_create, &options)); m_stopped_for_crash = false; if (auto_handle_events) diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp index 701d68d1ec08..a5a4ade013b9 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp @@ -80,7 +80,7 @@ void ScriptInterpreterLua::ExecuteInterpreterLoop() { return; IOHandlerSP io_handler_sp(new IOHandlerLuaInterpreter(debugger, *this)); - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); } bool ScriptInterpreterLua::LoadScriptingModule( diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 06e0d5bfa63f..733d796c5104 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -1064,7 +1064,7 @@ void ScriptInterpreterPythonImpl::ExecuteInterpreterLoop() { IOHandlerSP io_handler_sp(new IOHandlerPythonInterpreter(debugger, this)); if (io_handler_sp) { - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); } } diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 6711dc37eca6..aa9cd31fec50 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -4460,7 +4460,8 @@ bool Process::PushProcessIOHandler() { // existing IOHandler that potentially provides the user interface (e.g. // the IOHandler for Editline). bool cancel_top_handler = !m_mod_id.IsRunningUtilityFunction(); - GetTarget().GetDebugger().PushIOHandler(io_handler_sp, cancel_top_handler); + GetTarget().GetDebugger().RunIOHandlerAsync(io_handler_sp, + cancel_top_handler); return true; } return false; @@ -4469,7 +4470,7 @@ bool Process::PushProcessIOHandler() { bool Process::PopProcessIOHandler() { IOHandlerSP io_handler_sp(m_process_input_reader); if (io_handler_sp) - return GetTarget().GetDebugger().PopIOHandler(io_handler_sp); + return GetTarget().GetDebugger().RemoveIOHandler(io_handler_sp); return false; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits