[Lldb-commits] [lldb] 32c3224 - [lldb/CommandInterpreter] Move everything into CommandInterpreterRunOptions
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 30 13:20:15 PDT 2020
Author: Jonas Devlieghere
Date: 2020-04-30T13:20:06-07:00
New Revision: 32c3224612d84ee7e65907795eaba505f5c90e7c
URL: https://github.com/llvm/llvm-project/commit/32c3224612d84ee7e65907795eaba505f5c90e7c
DIFF: https://github.com/llvm/llvm-project/commit/32c3224612d84ee7e65907795eaba505f5c90e7c.diff
LOG: [lldb/CommandInterpreter] Move everything into CommandInterpreterRunOptions
This implements Greg's suggestion from D78825 to include "auto handle
events" and "spawn thread" in CommandInterpreterRunOptions. This change
is in preparation for adding a new overload for RunCommandInterpreter
that takes only SBCommandInterpreterRunOptions and returns
SBCommandInterpreterRunResults.
Differential revision: https://reviews.llvm.org/D79108
Added:
Modified:
lldb/include/lldb/API/SBCommandInterpreter.h
lldb/include/lldb/API/SBDebugger.h
lldb/include/lldb/Interpreter/CommandInterpreter.h
lldb/source/API/SBCommandInterpreter.cpp
lldb/source/API/SBDebugger.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/API/SBCommandInterpreter.h b/lldb/include/lldb/API/SBCommandInterpreter.h
index e07eeb58bf6a..9817794ff954 100644
--- a/lldb/include/lldb/API/SBCommandInterpreter.h
+++ b/lldb/include/lldb/API/SBCommandInterpreter.h
@@ -52,6 +52,14 @@ class LLDB_API SBCommandInterpreterRunOptions {
void SetAddToHistory(bool);
+ bool GetAutoHandleEvents() const;
+
+ void SetAutoHandleEvents(bool);
+
+ bool GetSpawnThread() const;
+
+ void SetSpawnThread(bool);
+
private:
lldb_private::CommandInterpreterRunOptions *get() const;
diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h
index 21fe77fa4f15..6f585540dd34 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -290,8 +290,42 @@ class LLDB_API SBDebugger {
SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier);
+ /// Run the command interpreter.
+ ///
+ /// \param[in] auto_handle_events
+ /// If true, automatically handle resulting events. This takes precedence
+ /// and overrides the corresponding option in
+ /// SBCommandInterpreterRunOptions.
+ ///
+ /// \param[in] spawn_thread
+ /// If true, start a new thread for IO handling. This takes precedence
+ /// and overrides the corresponding option in
+ /// SBCommandInterpreterRunOptions.
void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread);
+ /// Run the command interpreter.
+ ///
+ /// \param[in] auto_handle_events
+ /// If true, automatically handle resulting events. This takes precedence
+ /// and overrides the corresponding option in
+ /// SBCommandInterpreterRunOptions.
+ ///
+ /// \param[in] spawn_thread
+ /// If true, start a new thread for IO handling. This takes precedence
+ /// and overrides the corresponding option in
+ /// SBCommandInterpreterRunOptions.
+ ///
+ /// \param[in] options
+ /// Parameter collection of type SBCommandInterpreterRunOptions.
+ ///
+ /// \param[out] num_errors
+ /// The number of errors.
+ ///
+ /// \param[out] quit_requested
+ /// Whether a quit was requested.
+ ///
+ /// \param[out] stopped_for_crash
+ /// Whether the interpreter stopped for a crash.
void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread,
SBCommandInterpreterRunOptions &options,
int &num_errors, bool &quit_requested,
diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h
index 6a2ffc09cdd7..c65075cad966 100644
--- a/lldb/include/lldb/Interpreter/CommandInterpreter.h
+++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h
@@ -144,6 +144,20 @@ class CommandInterpreterRunOptions {
m_add_to_history = add_to_history ? eLazyBoolYes : eLazyBoolNo;
}
+ bool GetAutoHandleEvents() const {
+ return DefaultToYes(m_auto_handle_events);
+ }
+
+ void SetAutoHandleEvents(bool auto_handle_events) {
+ m_auto_handle_events = auto_handle_events ? eLazyBoolYes : eLazyBoolNo;
+ }
+
+ bool GetSpawnThread() const { return DefaultToNo(m_spawn_thread); }
+
+ void SetSpawnThread(bool spawn_thread) {
+ m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo;
+ }
+
LazyBool m_stop_on_continue;
LazyBool m_stop_on_error;
LazyBool m_stop_on_crash;
@@ -152,6 +166,8 @@ class CommandInterpreterRunOptions {
LazyBool m_print_results;
LazyBool m_print_errors;
LazyBool m_add_to_history;
+ LazyBool m_auto_handle_events;
+ LazyBool m_spawn_thread;
private:
static bool DefaultToYes(LazyBool flag) {
@@ -426,8 +442,7 @@ class CommandInterpreter : public Broadcaster,
bool IsActive();
- void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread,
- CommandInterpreterRunOptions &options);
+ void RunCommandInterpreter(CommandInterpreterRunOptions &options);
void GetLLDBCommandsFromIOHandler(const char *prompt,
IOHandlerDelegate &delegate,
diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp
index 14d738b27680..c191c00aa2d0 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -137,6 +137,35 @@ void SBCommandInterpreterRunOptions::SetAddToHistory(bool add_to_history) {
m_opaque_up->SetAddToHistory(add_to_history);
}
+bool SBCommandInterpreterRunOptions::GetAutoHandleEvents() const {
+ LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
+ GetAutoHandleEvents);
+
+ return m_opaque_up->GetAutoHandleEvents();
+}
+
+void SBCommandInterpreterRunOptions::SetAutoHandleEvents(
+ bool auto_handle_events) {
+ LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetAutoHandleEvents,
+ (bool), auto_handle_events);
+
+ m_opaque_up->SetAutoHandleEvents(auto_handle_events);
+}
+
+bool SBCommandInterpreterRunOptions::GetSpawnThread() const {
+ LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
+ GetSpawnThread);
+
+ return m_opaque_up->GetSpawnThread();
+}
+
+void SBCommandInterpreterRunOptions::SetSpawnThread(bool spawn_thread) {
+ LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetSpawnThread,
+ (bool), spawn_thread);
+
+ m_opaque_up->SetSpawnThread(spawn_thread);
+}
+
lldb_private::CommandInterpreterRunOptions *
SBCommandInterpreterRunOptions::get() const {
return m_opaque_up.get();
@@ -892,6 +921,14 @@ void RegisterMethods<SBCommandInterpreterRunOptions>(Registry &R) {
GetAddToHistory, ());
LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetAddToHistory,
(bool));
+ LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
+ GetAutoHandleEvents, ());
+ LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions,
+ SetAutoHandleEvents, (bool));
+ LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
+ GetSpawnThread, ());
+ LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetSpawnThread,
+ (bool));
LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter,
(lldb_private::CommandInterpreter *));
LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter,
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index bd5e256de2ac..ac5296af6665 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1166,9 +1166,9 @@ void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
if (m_opaque_sp) {
CommandInterpreterRunOptions options;
-
- m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(
- auto_handle_events, spawn_thread, options);
+ options.SetAutoHandleEvents(auto_handle_events);
+ options.SetSpawnThread(spawn_thread);
+ m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(options);
}
}
@@ -1186,9 +1186,10 @@ void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
quit_requested, stopped_for_crash);
if (m_opaque_sp) {
+ options.SetAutoHandleEvents(auto_handle_events);
+ options.SetSpawnThread(spawn_thread);
CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
- interp.RunCommandInterpreter(auto_handle_events, spawn_thread,
- options.ref());
+ interp.RunCommandInterpreter(options.ref());
num_errors = interp.GetNumErrors();
quit_requested = interp.GetQuitRequested();
stopped_for_crash = interp.GetStoppedForCrash();
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 65b3cf535bfc..2be5ca02cc5d 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2951,7 +2951,6 @@ CommandInterpreter::GetIOHandler(bool force_create,
}
void CommandInterpreter::RunCommandInterpreter(
- bool auto_handle_events, bool spawn_thread,
CommandInterpreterRunOptions &options) {
// Always re-create the command interpreter when we run it in case any file
// handles have changed.
@@ -2959,15 +2958,15 @@ void CommandInterpreter::RunCommandInterpreter(
m_debugger.RunIOHandlerAsync(GetIOHandler(force_create, &options));
m_stopped_for_crash = false;
- if (auto_handle_events)
+ if (options.GetAutoHandleEvents())
m_debugger.StartEventHandlerThread();
- if (spawn_thread) {
+ if (options.GetSpawnThread()) {
m_debugger.StartIOHandlerThread();
} else {
m_debugger.RunIOHandlers();
- if (auto_handle_events)
+ if (options.GetAutoHandleEvents())
m_debugger.StopEventHandlerThread();
}
}
More information about the lldb-commits
mailing list