aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
index d5423b7..e46851c 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -27,7 +27,13 @@ public:
: IOHandlerEditline(debugger, IOHandler::Type::LuaInterpreter, "lua",
">>> ", "..> ", true, debugger.GetUseColor(), 0,
*this, nullptr),
- m_script_interpreter(script_interpreter) {}
+ m_script_interpreter(script_interpreter) {
+ llvm::cantFail(m_script_interpreter.EnterSession(debugger.GetID()));
+ }
+
+ ~IOHandlerLuaInterpreter() {
+ llvm::cantFail(m_script_interpreter.LeaveSession());
+ }
void IOHandlerInputComplete(IOHandler &io_handler,
std::string &data) override {
@@ -89,6 +95,33 @@ void ScriptInterpreterLua::Initialize() {
void ScriptInterpreterLua::Terminate() {}
+llvm::Error ScriptInterpreterLua::EnterSession(user_id_t debugger_id) {
+ if (m_session_is_active)
+ return llvm::Error::success();
+
+ const char *fmt_str =
+ "lldb.debugger = lldb.SBDebugger.FindDebuggerWithID({0}); "
+ "lldb.target = lldb.debugger:GetSelectedTarget(); "
+ "lldb.process = lldb.target:GetProcess(); "
+ "lldb.thread = lldb.process:GetSelectedThread(); "
+ "lldb.frame = lldb.thread:GetSelectedFrame()";
+ return m_lua->Run(llvm::formatv(fmt_str, debugger_id).str());
+}
+
+llvm::Error ScriptInterpreterLua::LeaveSession() {
+ if (!m_session_is_active)
+ return llvm::Error::success();
+
+ m_session_is_active = false;
+
+ llvm::StringRef str = "lldb.debugger = nil; "
+ "lldb.target = nil; "
+ "lldb.process = nil; "
+ "lldb.thread = nil; "
+ "lldb.frame = nil";
+ return m_lua->Run(str);
+}
+
lldb::ScriptInterpreterSP
ScriptInterpreterLua::CreateInstance(Debugger &debugger) {
return std::make_shared<ScriptInterpreterLua>(debugger);