[Lldb-commits] [lldb] 67de896 - [lldb/Lua] Add Boilerplate for a Lua Script Interpreter
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Dec 19 10:16:59 PST 2019
Author: Jonas Devlieghere
Date: 2019-12-19T10:13:51-08:00
New Revision: 67de896229c0f1918f50a48973b7ce0007a181a9
URL: https://github.com/llvm/llvm-project/commit/67de896229c0f1918f50a48973b7ce0007a181a9
DIFF: https://github.com/llvm/llvm-project/commit/67de896229c0f1918f50a48973b7ce0007a181a9.diff
LOG: [lldb/Lua] Add Boilerplate for a Lua Script Interpreter
This adds the boilerplate necessary to support the Lua script
interpreter. The interpreter is not functional yet and just reports that
it's not implemented.
Discussion on the mailing list:
http://lists.llvm.org/pipermail/lldb-dev/2019-December/015812.html
Differential revision: https://reviews.llvm.org/D71232
Added:
lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
Modified:
lldb/cmake/modules/LLDBConfig.cmake
lldb/include/lldb/Host/Config.h.cmake
lldb/include/lldb/lldb-enumerations.h
lldb/source/API/SystemInitializerFull.cpp
lldb/source/Interpreter/OptionArgParser.cpp
lldb/source/Plugins/ScriptInterpreter/CMakeLists.txt
Removed:
################################################################################
diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index da006039b268..063c1fdaa376 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -25,6 +25,7 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darw
endif()
set(default_enable_python ON)
+set(default_enable_lua OFF) # Experimental
set(default_enable_libedit ON)
set(default_enable_curses ON)
@@ -49,13 +50,16 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(default_enable_curses OFF)
elseif(CMAKE_SYSTEM_NAME MATCHES "Android")
set(default_enable_python OFF)
+ set(default_enable_lua OFF)
set(default_enable_libedit OFF)
set(default_enable_curses OFF)
elseif(IOS)
set(default_enable_python OFF)
+ set(default_enable_lua OFF)
endif()
option(LLDB_ENABLE_PYTHON "Enable Python scripting integration." ${default_enable_python})
+option(LLDB_ENABLE_PYTHON "Enable Lua scripting integration." ${default_enable_lua})
option(LLDB_ENABLE_LIBEDIT "Enable the use of editline." ${default_enable_libedit})
option(LLDB_ENABLE_CURSES "Enable Curses integration." ${default_enable_curses})
option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to locate Python." OFF)
diff --git a/lldb/include/lldb/Host/Config.h.cmake b/lldb/include/lldb/Host/Config.h.cmake
index 8012d790954e..e9065ed04caa 100644
--- a/lldb/include/lldb/Host/Config.h.cmake
+++ b/lldb/include/lldb/Host/Config.h.cmake
@@ -42,6 +42,8 @@
#cmakedefine01 LLDB_ENABLE_LIBXML2
+#cmakedefine01 LLDB_ENABLE_LUA
+
#cmakedefine01 LLDB_ENABLE_PYTHON
#cmakedefine LLDB_PYTHON_HOME "${LLDB_PYTHON_HOME}"
diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h
index 0a92365544f9..5640a16c8f44 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -213,6 +213,7 @@ enum DescriptionLevel {
enum ScriptLanguage {
eScriptLanguageNone,
eScriptLanguagePython,
+ eScriptLanguageLua,
eScriptLanguageDefault = eScriptLanguagePython,
eScriptLanguageUnknown
};
diff --git a/lldb/source/API/SystemInitializerFull.cpp b/lldb/source/API/SystemInitializerFull.cpp
index 35a02ec29515..06f1a6cd3b75 100644
--- a/lldb/source/API/SystemInitializerFull.cpp
+++ b/lldb/source/API/SystemInitializerFull.cpp
@@ -14,6 +14,10 @@
#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
#endif
+#if LLDB_ENABLE_LUA
+#include "Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h"
+#endif
+
#include "lldb/Core/Debugger.h"
#include "lldb/Host/Host.h"
#include "lldb/Initialization/SystemInitializerCommon.h"
@@ -187,6 +191,10 @@ llvm::Error SystemInitializerFull::Initialize() {
ScriptInterpreterPython::Initialize();
#endif
+#if LLDB_ENABLE_LUA
+ ScriptInterpreterLua::Initialize();
+#endif
+
platform_freebsd::PlatformFreeBSD::Initialize();
platform_linux::PlatformLinux::Initialize();
platform_netbsd::PlatformNetBSD::Initialize();
diff --git a/lldb/source/Interpreter/OptionArgParser.cpp b/lldb/source/Interpreter/OptionArgParser.cpp
index 14b81cd7b3d2..56d99a4220f0 100644
--- a/lldb/source/Interpreter/OptionArgParser.cpp
+++ b/lldb/source/Interpreter/OptionArgParser.cpp
@@ -127,6 +127,8 @@ lldb::ScriptLanguage OptionArgParser::ToScriptLanguage(
if (s.equals_lower("python"))
return eScriptLanguagePython;
+ if (s.equals_lower("lua"))
+ return eScriptLanguageLua;
if (s.equals_lower("default"))
return eScriptLanguageDefault;
if (s.equals_lower("none"))
diff --git a/lldb/source/Plugins/ScriptInterpreter/CMakeLists.txt b/lldb/source/Plugins/ScriptInterpreter/CMakeLists.txt
index 416f68005139..fa1c72a32fe1 100644
--- a/lldb/source/Plugins/ScriptInterpreter/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/CMakeLists.txt
@@ -2,3 +2,7 @@ add_subdirectory(None)
if (LLDB_ENABLE_PYTHON)
add_subdirectory(Python)
endif()
+
+if (LLDB_ENABLE_LUA)
+ add_subdirectory(Lua)
+endif()
diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt b/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
new file mode 100644
index 000000000000..51161638a3d0
--- /dev/null
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_lldb_library(lldbPluginScriptInterpreterLua PLUGIN
+ ScriptInterpreterLua.cpp
+
+ LINK_LIBS
+ lldbCore
+ lldbInterpreter
+ )
\ No newline at end of file
diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
new file mode 100644
index 000000000000..78aa91a6959e
--- /dev/null
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -0,0 +1,71 @@
+//===-- ScriptInterpreterLua.cpp --------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "ScriptInterpreterLua.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Utility/Stream.h"
+#include "lldb/Utility/StringList.h"
+
+#include "llvm/Support/Threading.h"
+
+#include <mutex>
+
+using namespace lldb;
+using namespace lldb_private;
+
+ScriptInterpreterLua::ScriptInterpreterLua(Debugger &debugger)
+ : ScriptInterpreter(debugger, eScriptLanguageLua) {}
+
+ScriptInterpreterLua::~ScriptInterpreterLua() {}
+
+bool ScriptInterpreterLua::ExecuteOneLine(llvm::StringRef command,
+ CommandReturnObject *,
+ const ExecuteScriptOptions &) {
+ m_debugger.GetErrorStream().PutCString(
+ "error: the lua script interpreter is not yet implemented.\n");
+ return false;
+}
+
+void ScriptInterpreterLua::ExecuteInterpreterLoop() {
+ m_debugger.GetErrorStream().PutCString(
+ "error: the lua script interpreter is not yet implemented.\n");
+}
+
+void ScriptInterpreterLua::Initialize() {
+ static llvm::once_flag g_once_flag;
+
+ llvm::call_once(g_once_flag, []() {
+ PluginManager::RegisterPlugin(GetPluginNameStatic(),
+ GetPluginDescriptionStatic(),
+ lldb::eScriptLanguageLua, CreateInstance);
+ });
+}
+
+void ScriptInterpreterLua::Terminate() {}
+
+lldb::ScriptInterpreterSP
+ScriptInterpreterLua::CreateInstance(Debugger &debugger) {
+ return std::make_shared<ScriptInterpreterLua>(debugger);
+}
+
+lldb_private::ConstString ScriptInterpreterLua::GetPluginNameStatic() {
+ static ConstString g_name("script-lua");
+ return g_name;
+}
+
+const char *ScriptInterpreterLua::GetPluginDescriptionStatic() {
+ return "Lua script interpreter";
+}
+
+lldb_private::ConstString ScriptInterpreterLua::GetPluginName() {
+ return GetPluginNameStatic();
+}
+
+uint32_t ScriptInterpreterLua::GetPluginVersion() { return 1; }
diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
new file mode 100644
index 000000000000..7f69a73f5882
--- /dev/null
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
@@ -0,0 +1,47 @@
+//===-- ScriptInterpreterLua.h ----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ScriptInterpreterLua_h_
+#define liblldb_ScriptInterpreterLua_h_
+
+#include "lldb/Interpreter/ScriptInterpreter.h"
+
+namespace lldb_private {
+
+class ScriptInterpreterLua : public ScriptInterpreter {
+public:
+ ScriptInterpreterLua(Debugger &debugger);
+
+ ~ScriptInterpreterLua() override;
+
+ bool ExecuteOneLine(
+ llvm::StringRef command, CommandReturnObject *result,
+ const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
+
+ void ExecuteInterpreterLoop() override;
+
+ // Static Functions
+ static void Initialize();
+
+ static void Terminate();
+
+ static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger);
+
+ static lldb_private::ConstString GetPluginNameStatic();
+
+ static const char *GetPluginDescriptionStatic();
+
+ // PluginInterface protocol
+ lldb_private::ConstString GetPluginName() override;
+
+ uint32_t GetPluginVersion() override;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_ScriptInterpreterLua_h_
More information about the lldb-commits
mailing list