Skip to content

Commit 7ce2de2

Browse files
committed
[lldb/Debugger] Rename IO handler methods to be more meaningful (NFC)
Make it clear form the method names whether they are synchronous or asynchronous.
1 parent 6b29aa2 commit 7ce2de2

File tree

10 files changed

+67
-52
lines changed

10 files changed

+67
-52
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
190190
lldb::StreamFileSP &out,
191191
lldb::StreamFileSP &err);
192192

193-
void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
194-
bool cancel_top_handler = true);
193+
/// Run the given IO handler and return immediately.
194+
void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp,
195+
bool cancel_top_handler = true);
195196

196-
bool PopIOHandler(const lldb::IOHandlerSP &reader_sp);
197+
/// Run the given IO handler and block until it's complete.
198+
void RunIOHandlerSync(const lldb::IOHandlerSP &reader_sp);
197199

198-
// Synchronously run an input reader until it is done
199-
void RunIOHandler(const lldb::IOHandlerSP &reader_sp);
200+
/// Remove the given IO handler if it's currently active.
201+
bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp);
200202

201203
bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp);
202204

@@ -339,6 +341,11 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
339341

340342
static lldb::thread_result_t EventHandlerThread(lldb::thread_arg_t arg);
341343

344+
void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
345+
bool cancel_top_handler = true);
346+
347+
bool PopIOHandler(const lldb::IOHandlerSP &reader_sp);
348+
342349
bool HasIOHandlerThread();
343350

344351
bool StartIOHandlerThread();
@@ -402,7 +409,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
402409
std::array<lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown>
403410
m_script_interpreters;
404411

405-
IOHandlerStack m_input_reader_stack;
412+
IOHandlerStack m_io_handler_stack;
406413
llvm::StringMap<std::weak_ptr<llvm::raw_ostream>> m_log_streams;
407414
std::shared_ptr<llvm::raw_ostream> m_log_callback_stream_sp;
408415
ConstString m_instance_name;

lldb/source/Commands/CommandObjectCommands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ a number follows 'f':"
10071007
*this, nullptr));
10081008

10091009
if (io_handler_sp) {
1010-
debugger.PushIOHandler(io_handler_sp);
1010+
debugger.RunIOHandlerAsync(io_handler_sp);
10111011
result.SetStatus(eReturnStatusSuccessFinishNoResult);
10121012
}
10131013
} else {

lldb/source/Commands/CommandObjectExpression.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ void CommandObjectExpression::GetMultilineExpression() {
535535
"Enter expressions, then terminate with an empty line to evaluate:\n");
536536
output_sp->Flush();
537537
}
538-
debugger.PushIOHandler(io_handler_sp);
538+
debugger.RunIOHandlerAsync(io_handler_sp);
539539
}
540540

541541
static EvaluateExpressionOptions
@@ -622,10 +622,8 @@ bool CommandObjectExpression::DoExecute(llvm::StringRef command,
622622
}
623623

624624
IOHandlerSP io_handler_sp(repl_sp->GetIOHandler());
625-
626625
io_handler_sp->SetIsDone(false);
627-
628-
debugger.PushIOHandler(io_handler_sp);
626+
debugger.RunIOHandlerAsync(io_handler_sp);
629627
} else {
630628
repl_error.SetErrorStringWithFormat(
631629
"Couldn't create a REPL for %s",

lldb/source/Commands/CommandObjectGUI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) {
3535
input.GetIsInteractive()) {
3636
IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
3737
if (io_handler_sp)
38-
debugger.PushIOHandler(io_handler_sp);
38+
debugger.RunIOHandlerAsync(io_handler_sp);
3939
result.SetStatus(eReturnStatusSuccessFinishResult);
4040
} else {
4141
result.AppendError("the gui command requires an interactive terminal.");

lldb/source/Core/Debugger.cpp

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
708708
m_source_manager_up(), m_source_file_cache(),
709709
m_command_interpreter_up(
710710
std::make_unique<CommandInterpreter>(*this, false)),
711-
m_input_reader_stack(), m_instance_name(), m_loaded_plugins(),
711+
m_io_handler_stack(), m_instance_name(), m_loaded_plugins(),
712712
m_event_handler_thread(), m_io_handler_thread(),
713713
m_sync_broadcaster(nullptr, "lldb.debugger.sync"),
714714
m_forward_listener_sp(), m_clear_once() {
@@ -870,41 +870,41 @@ ExecutionContext Debugger::GetSelectedExecutionContext() {
870870
}
871871

872872
void Debugger::DispatchInputInterrupt() {
873-
std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
874-
IOHandlerSP reader_sp(m_input_reader_stack.Top());
873+
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
874+
IOHandlerSP reader_sp(m_io_handler_stack.Top());
875875
if (reader_sp)
876876
reader_sp->Interrupt();
877877
}
878878

879879
void Debugger::DispatchInputEndOfFile() {
880-
std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
881-
IOHandlerSP reader_sp(m_input_reader_stack.Top());
880+
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
881+
IOHandlerSP reader_sp(m_io_handler_stack.Top());
882882
if (reader_sp)
883883
reader_sp->GotEOF();
884884
}
885885

886886
void Debugger::ClearIOHandlers() {
887887
// The bottom input reader should be the main debugger input reader. We do
888888
// not want to close that one here.
889-
std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
890-
while (m_input_reader_stack.GetSize() > 1) {
891-
IOHandlerSP reader_sp(m_input_reader_stack.Top());
889+
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
890+
while (m_io_handler_stack.GetSize() > 1) {
891+
IOHandlerSP reader_sp(m_io_handler_stack.Top());
892892
if (reader_sp)
893893
PopIOHandler(reader_sp);
894894
}
895895
}
896896

897897
void Debugger::ExecuteIOHandlers() {
898898
while (true) {
899-
IOHandlerSP reader_sp(m_input_reader_stack.Top());
899+
IOHandlerSP reader_sp(m_io_handler_stack.Top());
900900
if (!reader_sp)
901901
break;
902902

903903
reader_sp->Run();
904904

905905
// Remove all input readers that are done from the top of the stack
906906
while (true) {
907-
IOHandlerSP top_reader_sp = m_input_reader_stack.Top();
907+
IOHandlerSP top_reader_sp = m_io_handler_stack.Top();
908908
if (top_reader_sp && top_reader_sp->GetIsDone())
909909
PopIOHandler(top_reader_sp);
910910
else
@@ -915,33 +915,42 @@ void Debugger::ExecuteIOHandlers() {
915915
}
916916

917917
bool Debugger::IsTopIOHandler(const lldb::IOHandlerSP &reader_sp) {
918-
return m_input_reader_stack.IsTop(reader_sp);
918+
return m_io_handler_stack.IsTop(reader_sp);
919919
}
920920

921921
bool Debugger::CheckTopIOHandlerTypes(IOHandler::Type top_type,
922922
IOHandler::Type second_top_type) {
923-
return m_input_reader_stack.CheckTopIOHandlerTypes(top_type, second_top_type);
923+
return m_io_handler_stack.CheckTopIOHandlerTypes(top_type, second_top_type);
924924
}
925925

926926
void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) {
927927
lldb_private::StreamFile &stream =
928928
is_stdout ? GetOutputStream() : GetErrorStream();
929-
m_input_reader_stack.PrintAsync(&stream, s, len);
929+
m_io_handler_stack.PrintAsync(&stream, s, len);
930930
}
931931

932932
ConstString Debugger::GetTopIOHandlerControlSequence(char ch) {
933-
return m_input_reader_stack.GetTopIOHandlerControlSequence(ch);
933+
return m_io_handler_stack.GetTopIOHandlerControlSequence(ch);
934934
}
935935

936936
const char *Debugger::GetIOHandlerCommandPrefix() {
937-
return m_input_reader_stack.GetTopIOHandlerCommandPrefix();
937+
return m_io_handler_stack.GetTopIOHandlerCommandPrefix();
938938
}
939939

940940
const char *Debugger::GetIOHandlerHelpPrologue() {
941-
return m_input_reader_stack.GetTopIOHandlerHelpPrologue();
941+
return m_io_handler_stack.GetTopIOHandlerHelpPrologue();
942942
}
943943

944-
void Debugger::RunIOHandler(const IOHandlerSP &reader_sp) {
944+
bool Debugger::RemoveIOHandler(const IOHandlerSP &reader_sp) {
945+
return PopIOHandler(reader_sp);
946+
}
947+
948+
void Debugger::RunIOHandlerAsync(const IOHandlerSP &reader_sp,
949+
bool cancel_top_handler) {
950+
PushIOHandler(reader_sp, cancel_top_handler);
951+
}
952+
953+
void Debugger::RunIOHandlerSync(const IOHandlerSP &reader_sp) {
945954
PushIOHandler(reader_sp);
946955

947956
IOHandlerSP top_reader_sp = reader_sp;
@@ -954,7 +963,7 @@ void Debugger::RunIOHandler(const IOHandlerSP &reader_sp) {
954963
}
955964

956965
while (true) {
957-
top_reader_sp = m_input_reader_stack.Top();
966+
top_reader_sp = m_io_handler_stack.Top();
958967
if (top_reader_sp && top_reader_sp->GetIsDone())
959968
PopIOHandler(top_reader_sp);
960969
else
@@ -970,8 +979,8 @@ void Debugger::AdoptTopIOHandlerFilesIfInvalid(FileSP &in, StreamFileSP &out,
970979
// input reader's in/out/err streams, or fall back to the debugger file
971980
// handles, or we fall back onto stdin/stdout/stderr as a last resort.
972981

973-
std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
974-
IOHandlerSP top_reader_sp(m_input_reader_stack.Top());
982+
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
983+
IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
975984
// If no STDIN has been set, then set it appropriately
976985
if (!in || !in->IsValid()) {
977986
if (top_reader_sp)
@@ -1009,17 +1018,17 @@ void Debugger::PushIOHandler(const IOHandlerSP &reader_sp,
10091018
if (!reader_sp)
10101019
return;
10111020

1012-
std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
1021+
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
10131022

10141023
// Get the current top input reader...
1015-
IOHandlerSP top_reader_sp(m_input_reader_stack.Top());
1024+
IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
10161025

10171026
// Don't push the same IO handler twice...
10181027
if (reader_sp == top_reader_sp)
10191028
return;
10201029

10211030
// Push our new input reader
1022-
m_input_reader_stack.Push(reader_sp);
1031+
m_io_handler_stack.Push(reader_sp);
10231032
reader_sp->Activate();
10241033

10251034
// 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) {
10351044
if (!pop_reader_sp)
10361045
return false;
10371046

1038-
std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
1047+
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
10391048

10401049
// The reader on the stop of the stack is done, so let the next read on the
10411050
// stack refresh its prompt and if there is one...
1042-
if (m_input_reader_stack.IsEmpty())
1051+
if (m_io_handler_stack.IsEmpty())
10431052
return false;
10441053

1045-
IOHandlerSP reader_sp(m_input_reader_stack.Top());
1054+
IOHandlerSP reader_sp(m_io_handler_stack.Top());
10461055

10471056
if (pop_reader_sp != reader_sp)
10481057
return false;
10491058

10501059
reader_sp->Deactivate();
10511060
reader_sp->Cancel();
1052-
m_input_reader_stack.Pop();
1061+
m_io_handler_stack.Pop();
10531062

1054-
reader_sp = m_input_reader_stack.Top();
1063+
reader_sp = m_io_handler_stack.Top();
10551064
if (reader_sp)
10561065
reader_sp->Activate();
10571066

lldb/source/Expression/REPL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
252252
lldb::IOHandlerSP io_handler_sp(ci.GetIOHandler());
253253
if (io_handler_sp) {
254254
io_handler_sp->SetIsDone(false);
255-
debugger.PushIOHandler(ci.GetIOHandler());
255+
debugger.RunIOHandlerAsync(ci.GetIOHandler());
256256
}
257257
}
258258
}
@@ -370,7 +370,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
370370
lldb::IOHandlerSP io_handler_sp(ci.GetIOHandler());
371371
if (io_handler_sp) {
372372
io_handler_sp->SetIsDone(false);
373-
debugger.PushIOHandler(ci.GetIOHandler());
373+
debugger.RunIOHandlerAsync(ci.GetIOHandler());
374374
}
375375
}
376376
break;
@@ -530,7 +530,7 @@ Status REPL::RunLoop() {
530530
save_default_line);
531531
}
532532

533-
debugger.PushIOHandler(io_handler_sp);
533+
debugger.RunIOHandlerAsync(io_handler_sp);
534534

535535
// Check if we are in dedicated REPL mode where LLDB was start with the "--
536536
// repl" option from the command line. Currently we know this by checking if

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ bool CommandInterpreter::Confirm(llvm::StringRef message, bool default_answer) {
18541854
IOHandlerConfirm *confirm =
18551855
new IOHandlerConfirm(m_debugger, message, default_answer);
18561856
IOHandlerSP io_handler_sp(confirm);
1857-
m_debugger.RunIOHandler(io_handler_sp);
1857+
m_debugger.RunIOHandlerSync(io_handler_sp);
18581858
return confirm->GetResponse();
18591859
}
18601860

@@ -2477,7 +2477,7 @@ void CommandInterpreter::HandleCommandsFromFile(
24772477

24782478
m_command_source_depth++;
24792479

2480-
debugger.RunIOHandler(io_handler_sp);
2480+
debugger.RunIOHandlerSync(io_handler_sp);
24812481
if (!m_command_source_flags.empty())
24822482
m_command_source_flags.pop_back();
24832483
m_command_source_depth--;
@@ -2854,7 +2854,7 @@ void CommandInterpreter::GetLLDBCommandsFromIOHandler(
28542854

28552855
if (io_handler_sp) {
28562856
io_handler_sp->SetUserData(baton);
2857-
debugger.PushIOHandler(io_handler_sp);
2857+
debugger.RunIOHandlerAsync(io_handler_sp);
28582858
}
28592859
}
28602860

@@ -2874,7 +2874,7 @@ void CommandInterpreter::GetPythonCommandsFromIOHandler(
28742874

28752875
if (io_handler_sp) {
28762876
io_handler_sp->SetUserData(baton);
2877-
debugger.PushIOHandler(io_handler_sp);
2877+
debugger.RunIOHandlerAsync(io_handler_sp);
28782878
}
28792879
}
28802880

@@ -2934,7 +2934,7 @@ void CommandInterpreter::RunCommandInterpreter(
29342934
// Always re-create the command interpreter when we run it in case any file
29352935
// handles have changed.
29362936
bool force_create = true;
2937-
m_debugger.PushIOHandler(GetIOHandler(force_create, &options));
2937+
m_debugger.RunIOHandlerAsync(GetIOHandler(force_create, &options));
29382938
m_stopped_for_crash = false;
29392939

29402940
if (auto_handle_events)

lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void ScriptInterpreterLua::ExecuteInterpreterLoop() {
8080
return;
8181

8282
IOHandlerSP io_handler_sp(new IOHandlerLuaInterpreter(debugger, *this));
83-
debugger.PushIOHandler(io_handler_sp);
83+
debugger.RunIOHandlerAsync(io_handler_sp);
8484
}
8585

8686
bool ScriptInterpreterLua::LoadScriptingModule(

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ void ScriptInterpreterPythonImpl::ExecuteInterpreterLoop() {
10641064

10651065
IOHandlerSP io_handler_sp(new IOHandlerPythonInterpreter(debugger, this));
10661066
if (io_handler_sp) {
1067-
debugger.PushIOHandler(io_handler_sp);
1067+
debugger.RunIOHandlerAsync(io_handler_sp);
10681068
}
10691069
}
10701070

lldb/source/Target/Process.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,7 +4460,8 @@ bool Process::PushProcessIOHandler() {
44604460
// existing IOHandler that potentially provides the user interface (e.g.
44614461
// the IOHandler for Editline).
44624462
bool cancel_top_handler = !m_mod_id.IsRunningUtilityFunction();
4463-
GetTarget().GetDebugger().PushIOHandler(io_handler_sp, cancel_top_handler);
4463+
GetTarget().GetDebugger().RunIOHandlerAsync(io_handler_sp,
4464+
cancel_top_handler);
44644465
return true;
44654466
}
44664467
return false;
@@ -4469,7 +4470,7 @@ bool Process::PushProcessIOHandler() {
44694470
bool Process::PopProcessIOHandler() {
44704471
IOHandlerSP io_handler_sp(m_process_input_reader);
44714472
if (io_handler_sp)
4472-
return GetTarget().GetDebugger().PopIOHandler(io_handler_sp);
4473+
return GetTarget().GetDebugger().RemoveIOHandler(io_handler_sp);
44734474
return false;
44744475
}
44754476

0 commit comments

Comments
 (0)