[Lldb-commits] [lldb] r359330 - [ScriptInterpreter] Pass the debugger instead of the command interpreter
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 26 10:58:19 PDT 2019
Author: jdevlieghere
Date: Fri Apr 26 10:58:19 2019
New Revision: 359330
URL: http://llvm.org/viewvc/llvm-project?rev=359330&view=rev
Log:
[ScriptInterpreter] Pass the debugger instead of the command interpreter
As discussed in D61090, there's no good reason for the script
interpreter to depend on the command interpreter. When looking at the
code, it becomes clear that we mostly use the command interpreter as a
way to access the debugger. Hence, it makes more sense to just pass that
to the script interpreter directly.
This is part 1 out of 2. I have another patch in the pipeline that
changes the ownership of the script interpreter to the debugger as well,
but I didn't get around to finish that today.
Differential revision: https://reviews.llvm.org/D61172
Modified:
lldb/trunk/include/lldb/Core/PluginManager.h
lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
lldb/trunk/include/lldb/lldb-private-interfaces.h
lldb/trunk/source/Core/PluginManager.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Interpreter/ScriptInterpreter.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
Modified: lldb/trunk/include/lldb/Core/PluginManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/PluginManager.h?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/PluginManager.h (original)
+++ lldb/trunk/include/lldb/Core/PluginManager.h Fri Apr 26 10:58:19 2019
@@ -263,7 +263,7 @@ public:
static lldb::ScriptInterpreterSP
GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang,
- CommandInterpreter &interpreter);
+ Debugger &debugger);
// StructuredDataPlugin
Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Fri Apr 26 10:58:19 2019
@@ -52,8 +52,7 @@ public:
eScriptReturnTypeOpaqueObject
} ScriptReturnType;
- ScriptInterpreter(CommandInterpreter &interpreter,
- lldb::ScriptLanguage script_lang);
+ ScriptInterpreter(Debugger &debugger, lldb::ScriptLanguage script_lang);
~ScriptInterpreter() override;
@@ -247,7 +246,7 @@ public:
lldb::BreakpointSP &bkpt_sp) {
return StructuredData::GenericSP();
}
-
+
virtual bool
ScriptedBreakpointResolverSearchCallback(StructuredData::GenericSP implementor_sp,
SymbolContext *sym_ctx)
@@ -460,8 +459,6 @@ public:
int GetMasterFileDescriptor();
- CommandInterpreter &GetCommandInterpreter();
-
static std::string LanguageToString(lldb::ScriptLanguage language);
static lldb::ScriptLanguage StringToLanguage(const llvm::StringRef &string);
@@ -471,7 +468,7 @@ public:
lldb::ScriptLanguage GetLanguage() { return m_script_lang; }
protected:
- CommandInterpreter &m_interpreter;
+ Debugger &m_debugger;
lldb::ScriptLanguage m_script_lang;
};
Modified: lldb/trunk/include/lldb/lldb-private-interfaces.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-interfaces.h?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-private-interfaces.h (original)
+++ lldb/trunk/include/lldb/lldb-private-interfaces.h Fri Apr 26 10:58:19 2019
@@ -66,7 +66,7 @@ typedef lldb::ProcessSP (*ProcessCreateI
lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
const FileSpec *crash_file_path);
typedef lldb::ScriptInterpreterSP (*ScriptInterpreterCreateInstance)(
- CommandInterpreter &interpreter);
+ Debugger &debugger);
typedef SymbolFile *(*SymbolFileCreateInstance)(ObjectFile *obj_file);
typedef SymbolVendor *(*SymbolVendorCreateInstance)(
const lldb::ModuleSP &module_sp,
Modified: lldb/trunk/source/Core/PluginManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/PluginManager.cpp?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/source/Core/PluginManager.cpp (original)
+++ lldb/trunk/source/Core/PluginManager.cpp Fri Apr 26 10:58:19 2019
@@ -1516,8 +1516,9 @@ PluginManager::GetScriptInterpreterCreat
return nullptr;
}
-lldb::ScriptInterpreterSP PluginManager::GetScriptInterpreterForLanguage(
- lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter) {
+lldb::ScriptInterpreterSP
+PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang,
+ Debugger &debugger) {
std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
@@ -1528,12 +1529,12 @@ lldb::ScriptInterpreterSP PluginManager:
none_instance = pos->create_callback;
if (script_lang == pos->language)
- return pos->create_callback(interpreter);
+ return pos->create_callback(debugger);
}
// If we didn't find one, return the ScriptInterpreter for the null language.
assert(none_instance != nullptr);
- return none_instance(interpreter);
+ return none_instance(debugger);
}
#pragma mark -
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Fri Apr 26 10:58:19 2019
@@ -2507,7 +2507,7 @@ ScriptInterpreter *CommandInterpreter::G
return nullptr;
lldb::ScriptLanguage script_lang = GetDebugger().GetScriptLanguage();
m_script_interpreter_sp =
- PluginManager::GetScriptInterpreterForLanguage(script_lang, *this);
+ PluginManager::GetScriptInterpreterForLanguage(script_lang, m_debugger);
}
return m_script_interpreter_sp.get();
}
Modified: lldb/trunk/source/Interpreter/ScriptInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreter.cpp?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreter.cpp Fri Apr 26 10:58:19 2019
@@ -21,16 +21,12 @@
using namespace lldb;
using namespace lldb_private;
-ScriptInterpreter::ScriptInterpreter(CommandInterpreter &interpreter,
+ScriptInterpreter::ScriptInterpreter(Debugger &debugger,
lldb::ScriptLanguage script_lang)
- : m_interpreter(interpreter), m_script_lang(script_lang) {}
+ : m_debugger(debugger), m_script_lang(script_lang) {}
ScriptInterpreter::~ScriptInterpreter() {}
-CommandInterpreter &ScriptInterpreter::GetCommandInterpreter() {
- return m_interpreter;
-}
-
void ScriptInterpreter::CollectDataForBreakpointCommandCallback(
std::vector<BreakpointOptions *> &bp_options_vec,
CommandReturnObject &result) {
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp Fri Apr 26 10:58:19 2019
@@ -10,7 +10,6 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/StreamFile.h"
-#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StringList.h"
@@ -21,21 +20,21 @@
using namespace lldb;
using namespace lldb_private;
-ScriptInterpreterNone::ScriptInterpreterNone(CommandInterpreter &interpreter)
- : ScriptInterpreter(interpreter, eScriptLanguageNone) {}
+ScriptInterpreterNone::ScriptInterpreterNone(Debugger &debugger)
+ : ScriptInterpreter(debugger, eScriptLanguageNone) {}
ScriptInterpreterNone::~ScriptInterpreterNone() {}
bool ScriptInterpreterNone::ExecuteOneLine(llvm::StringRef command,
CommandReturnObject *,
const ExecuteScriptOptions &) {
- m_interpreter.GetDebugger().GetErrorFile()->PutCString(
+ m_debugger.GetErrorFile()->PutCString(
"error: there is no embedded script interpreter in this mode.\n");
return false;
}
void ScriptInterpreterNone::ExecuteInterpreterLoop() {
- m_interpreter.GetDebugger().GetErrorFile()->PutCString(
+ m_debugger.GetErrorFile()->PutCString(
"error: there is no embedded script interpreter in this mode.\n");
}
@@ -52,8 +51,8 @@ void ScriptInterpreterNone::Initialize()
void ScriptInterpreterNone::Terminate() {}
lldb::ScriptInterpreterSP
-ScriptInterpreterNone::CreateInstance(CommandInterpreter &interpreter) {
- return std::make_shared<ScriptInterpreterNone>(interpreter);
+ScriptInterpreterNone::CreateInstance(Debugger &debugger) {
+ return std::make_shared<ScriptInterpreterNone>(debugger);
}
lldb_private::ConstString ScriptInterpreterNone::GetPluginNameStatic() {
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h Fri Apr 26 10:58:19 2019
@@ -15,7 +15,7 @@ namespace lldb_private {
class ScriptInterpreterNone : public ScriptInterpreter {
public:
- ScriptInterpreterNone(CommandInterpreter &interpreter);
+ ScriptInterpreterNone(Debugger &debugger);
~ScriptInterpreterNone() override;
@@ -30,8 +30,7 @@ public:
static void Terminate();
- static lldb::ScriptInterpreterSP
- CreateInstance(CommandInterpreter &interpreter);
+ static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger);
static lldb_private::ConstString GetPluginNameStatic();
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp Fri Apr 26 10:58:19 2019
@@ -441,15 +441,13 @@ ScriptInterpreterPythonImpl::Locker::~Lo
DoFreeLock();
}
-ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(
- CommandInterpreter &interpreter)
- : ScriptInterpreterPython(interpreter), m_saved_stdin(), m_saved_stdout(),
+ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger)
+ : ScriptInterpreterPython(debugger), m_saved_stdin(), m_saved_stdout(),
m_saved_stderr(), m_main_module(),
m_session_dict(PyInitialValue::Invalid),
m_sys_module_dict(PyInitialValue::Invalid), m_run_one_line_function(),
m_run_one_line_str_global(),
- m_dictionary_name(
- interpreter.GetDebugger().GetInstanceName().AsCString()),
+ m_dictionary_name(m_debugger.GetInstanceName().AsCString()),
m_terminal_state(), m_active_io_handler(eIOHandlerNone),
m_session_is_active(false), m_pty_slave_is_open(false),
m_valid_session(true), m_lock_count(0), m_command_thread_state(nullptr) {
@@ -495,8 +493,7 @@ ScriptInterpreterPythonImpl::ScriptInter
run_string.Printf("run_one_line (%s, 'lldb.debugger_unique_id = %" PRIu64
"; pydoc.pager = pydoc.plainpager')",
- m_dictionary_name.c_str(),
- interpreter.GetDebugger().GetID());
+ m_dictionary_name.c_str(), m_debugger.GetID());
PyRun_SimpleString(run_string.GetData());
}
@@ -549,7 +546,7 @@ def function (frame, bp_loc, internal_di
void ScriptInterpreterPythonImpl::IOHandlerInputComplete(IOHandler &io_handler,
std::string &data) {
io_handler.SetIsDone(true);
- bool batch_mode = m_interpreter.GetBatchCommandMode();
+ bool batch_mode = m_debugger.GetCommandInterpreter().GetBatchCommandMode();
switch (m_active_io_handler) {
case eIOHandlerNone:
@@ -608,8 +605,8 @@ void ScriptInterpreterPythonImpl::IOHand
}
lldb::ScriptInterpreterSP
-ScriptInterpreterPythonImpl::CreateInstance(CommandInterpreter &interpreter) {
- return std::make_shared<ScriptInterpreterPythonImpl>(interpreter);
+ScriptInterpreterPythonImpl::CreateInstance(Debugger &debugger) {
+ return std::make_shared<ScriptInterpreterPythonImpl>(debugger);
}
void ScriptInterpreterPythonImpl::ResetOutputFileHandle(FILE *fh) {}
@@ -711,11 +708,10 @@ bool ScriptInterpreterPythonImpl::EnterS
if (on_entry_flags & Locker::InitGlobals) {
run_string.Printf("run_one_line (%s, 'lldb.debugger_unique_id = %" PRIu64,
- m_dictionary_name.c_str(),
- GetCommandInterpreter().GetDebugger().GetID());
+ m_dictionary_name.c_str(), m_debugger.GetID());
run_string.Printf(
"; lldb.debugger = lldb.SBDebugger.FindDebuggerWithID (%" PRIu64 ")",
- GetCommandInterpreter().GetDebugger().GetID());
+ m_debugger.GetID());
run_string.PutCString("; lldb.target = lldb.debugger.GetSelectedTarget()");
run_string.PutCString("; lldb.process = lldb.target.GetProcess()");
run_string.PutCString("; lldb.thread = lldb.process.GetSelectedThread ()");
@@ -725,11 +721,10 @@ bool ScriptInterpreterPythonImpl::EnterS
// If we aren't initing the globals, we should still always set the
// debugger (since that is always unique.)
run_string.Printf("run_one_line (%s, 'lldb.debugger_unique_id = %" PRIu64,
- m_dictionary_name.c_str(),
- GetCommandInterpreter().GetDebugger().GetID());
+ m_dictionary_name.c_str(), m_debugger.GetID());
run_string.Printf(
"; lldb.debugger = lldb.SBDebugger.FindDebuggerWithID (%" PRIu64 ")",
- GetCommandInterpreter().GetDebugger().GetID());
+ m_debugger.GetID());
run_string.PutCString("')");
}
@@ -746,8 +741,7 @@ bool ScriptInterpreterPythonImpl::EnterS
lldb::StreamFileSP out_sp;
lldb::StreamFileSP err_sp;
if (!in_file.IsValid() || !out_file.IsValid() || !err_file.IsValid())
- m_interpreter.GetDebugger().AdoptTopIOHandlerFilesIfInvalid(in_sp, out_sp,
- err_sp);
+ m_debugger.AdoptTopIOHandlerFilesIfInvalid(in_sp, out_sp, err_sp);
if (on_entry_flags & Locker::NoSTDIN) {
m_saved_stdin.Reset();
@@ -871,7 +865,7 @@ bool ScriptInterpreterPythonImpl::Execut
// another string to pass to PyRun_SimpleString messes up the escaping. So
// we use the following more complicated method to pass the command string
// directly down to Python.
- Debugger &debugger = m_interpreter.GetDebugger();
+ Debugger &debugger = m_debugger;
StreamFileSP input_file_sp;
StreamFileSP output_file_sp;
@@ -1018,7 +1012,7 @@ void ScriptInterpreterPythonImpl::Execut
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
- Debugger &debugger = GetCommandInterpreter().GetDebugger();
+ Debugger &debugger = m_debugger;
// At the moment, the only time the debugger does not have an input file
// handle is when this is called directly from Python, in which case it is
@@ -1274,14 +1268,15 @@ void ScriptInterpreterPythonImpl::Collec
std::vector<BreakpointOptions *> &bp_options_vec,
CommandReturnObject &result) {
m_active_io_handler = eIOHandlerBreakpoint;
- m_interpreter.GetPythonCommandsFromIOHandler(" ", *this, true,
- &bp_options_vec);
+ m_debugger.GetCommandInterpreter().GetPythonCommandsFromIOHandler(
+ " ", *this, true, &bp_options_vec);
}
void ScriptInterpreterPythonImpl::CollectDataForWatchpointCommandCallback(
WatchpointOptions *wp_options, CommandReturnObject &result) {
m_active_io_handler = eIOHandlerWatchpoint;
- m_interpreter.GetPythonCommandsFromIOHandler(" ", *this, true, wp_options);
+ m_debugger.GetCommandInterpreter().GetPythonCommandsFromIOHandler(
+ " ", *this, true, wp_options);
}
void ScriptInterpreterPythonImpl::SetBreakpointCommandCallbackFunction(
@@ -1290,8 +1285,9 @@ void ScriptInterpreterPythonImpl::SetBre
std::string oneliner("return ");
oneliner += function_name;
oneliner += "(frame, bp_loc, internal_dict)";
- m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback(
- bp_options, oneliner.c_str());
+ m_debugger.GetCommandInterpreter()
+ .GetScriptInterpreter()
+ ->SetBreakpointCommandCallback(bp_options, oneliner.c_str());
}
Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback(
@@ -2109,8 +2105,7 @@ ScriptInterpreterPythonImpl::CreateSynth
StructuredData::GenericSP
ScriptInterpreterPythonImpl::CreateScriptCommandObject(const char *class_name) {
- DebuggerSP debugger_sp(
- GetCommandInterpreter().GetDebugger().shared_from_this());
+ DebuggerSP debugger_sp(m_debugger.shared_from_this());
if (class_name == nullptr || class_name[0] == '\0')
return StructuredData::GenericSP();
@@ -2718,7 +2713,7 @@ bool ScriptInterpreterPythonImpl::LoadSc
return false;
}
- lldb::DebuggerSP debugger_sp = m_interpreter.GetDebugger().shared_from_this();
+ lldb::DebuggerSP debugger_sp = m_debugger.shared_from_this();
{
FileSpec target_file(pathname);
@@ -2912,7 +2907,7 @@ bool ScriptInterpreterPythonImpl::RunScr
return false;
}
- lldb::DebuggerSP debugger_sp = m_interpreter.GetDebugger().shared_from_this();
+ lldb::DebuggerSP debugger_sp = m_debugger.shared_from_this();
lldb::ExecutionContextRefSP exe_ctx_ref_sp(new ExecutionContextRef(exe_ctx));
if (!debugger_sp.get()) {
@@ -2956,7 +2951,7 @@ bool ScriptInterpreterPythonImpl::RunScr
return false;
}
- lldb::DebuggerSP debugger_sp = m_interpreter.GetDebugger().shared_from_this();
+ lldb::DebuggerSP debugger_sp = m_debugger.shared_from_this();
lldb::ExecutionContextRefSP exe_ctx_ref_sp(new ExecutionContextRef(exe_ctx));
if (!debugger_sp.get()) {
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h Fri Apr 26 10:58:19 2019
@@ -36,8 +36,8 @@ public:
}
};
- ScriptInterpreterPython(CommandInterpreter &interpreter)
- : ScriptInterpreter(interpreter, lldb::eScriptLanguagePython),
+ ScriptInterpreterPython(Debugger &debugger)
+ : ScriptInterpreter(debugger, lldb::eScriptLanguagePython),
IOHandlerDelegateMultiline("DONE") {}
static void Initialize();
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h?rev=359330&r1=359329&r2=359330&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h Fri Apr 26 10:58:19 2019
@@ -29,7 +29,7 @@ class ScriptInterpreterPythonImpl : publ
public:
friend class IOHandlerPythonInterpreter;
- ScriptInterpreterPythonImpl(CommandInterpreter &interpreter);
+ ScriptInterpreterPythonImpl(Debugger &debugger);
~ScriptInterpreterPythonImpl() override;
@@ -273,8 +273,7 @@ public:
void IOHandlerInputComplete(IOHandler &io_handler,
std::string &data) override;
- static lldb::ScriptInterpreterSP
- CreateInstance(CommandInterpreter &interpreter);
+ static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger);
// PluginInterface protocol
lldb_private::ConstString GetPluginName() override;
More information about the lldb-commits
mailing list