Index: lldb/CMakeLists.txt =================================================================== --- lldb/CMakeLists.txt +++ lldb/CMakeLists.txt @@ -50,10 +50,10 @@ file(TO_CMAKE_PATH ${LLDB_PYTHON_DEFAULT_RELATIVE_PATH} LLDB_PYTHON_DEFAULT_RELATIVE_PATH) set(LLDB_PYTHON_RELATIVE_PATH ${LLDB_PYTHON_DEFAULT_RELATIVE_PATH} CACHE STRING "Path where Python modules are installed, relative to install prefix") - - add_subdirectory(scripts) endif () +add_subdirectory(scripts) + # We need the headers generated by instrinsics_gen before we can compile # any source file in LLDB as the imported Clang modules might include # some of these generated headers. This approach is copied from Clang's main Index: lldb/scripts/CMakeLists.txt =================================================================== --- lldb/scripts/CMakeLists.txt +++ lldb/scripts/CMakeLists.txt @@ -27,31 +27,57 @@ set(DARWIN_EXTRAS "") endif() -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py - DEPENDS ${SWIG_SOURCES} - DEPENDS ${SWIG_INTERFACES} - DEPENDS ${SWIG_HEADERS} - COMMAND ${SWIG_EXECUTABLE} - -c++ - -shadow - -python - -features autodoc - -threads - -I${LLDB_SOURCE_DIR}/include - -I${CMAKE_CURRENT_SOURCE_DIR} - -D__STDC_LIMIT_MACROS - -D__STDC_CONSTANT_MACROS - ${DARWIN_EXTRAS} - -outdir ${CMAKE_CURRENT_BINARY_DIR} - -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - ${LLDB_SOURCE_DIR}/scripts/lldb.swig - VERBATIM - COMMENT "Builds LLDB Python wrapper") - -add_custom_target(swig_wrapper ALL DEPENDS - ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - ${CMAKE_CURRENT_BINARY_DIR}/lldb.py +set(SWIG_COMMON_FLAGS + -c++ + -features autodoc + -I${LLDB_SOURCE_DIR}/include + -I${CMAKE_CURRENT_SOURCE_DIR} + -D__STDC_LIMIT_MACROS + -D__STDC_CONSTANT_MACROS + ${DARWIN_EXTRAS} + -outdir ${CMAKE_CURRENT_BINARY_DIR} ) + +if (LLDB_ENABLE_PYTHON) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py + DEPENDS ${SWIG_SOURCES} + DEPENDS ${SWIG_INTERFACES} + DEPENDS ${SWIG_HEADERS} + COMMAND ${SWIG_EXECUTABLE} + ${SWIG_COMMON_FLAGS} + -c++ + -shadow + -python + -threads + -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp + ${LLDB_SOURCE_DIR}/scripts/lldb.swig + VERBATIM + COMMENT "Builds LLDB Python wrapper") + + add_custom_target(swig_wrapper ALL DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp + ${CMAKE_CURRENT_BINARY_DIR}/lldb.py + ) +endif() + +if (LLDB_ENABLE_LUA) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp + DEPENDS ${SWIG_SOURCES} + DEPENDS ${SWIG_INTERFACES} + DEPENDS ${SWIG_HEADERS} + COMMAND ${SWIG_EXECUTABLE} + ${SWIG_COMMON_FLAGS} + -lua + -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp + ${LLDB_SOURCE_DIR}/scripts/lldb_lua.swig + VERBATIM + COMMENT "Builds LLDB Lua wrapper") + + add_custom_target(swig_wrapper_lua ALL DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp + ) +endif() Index: lldb/scripts/lldb_lua.swig =================================================================== --- /dev/null +++ lldb/scripts/lldb_lua.swig @@ -0,0 +1,18 @@ +/* + lldb.swig + + This is the input file for SWIG, to create the appropriate C++ wrappers and + functions for various scripting languages, to enable them to call the + liblldb Script Bridge functions. +*/ + +%module lldb + +%include "./headers.swig" + +%{ +using namespace lldb_private; +using namespace lldb; +%} + +%include "./interfaces.swig" Index: lldb/source/API/CMakeLists.txt =================================================================== --- lldb/source/API/CMakeLists.txt +++ lldb/source/API/CMakeLists.txt @@ -9,6 +9,11 @@ set(lldb_python_wrapper ${lldb_scripts_dir}/LLDBWrapPython.cpp) endif() +if(LLDB_ENABLE_LUA) + get_target_property(lldb_scripts_dir swig_wrapper_lua BINARY_DIR) + set(lldb_lua_wrapper ${lldb_scripts_dir}/LLDBWrapLua.cpp) +endif() + if(LLDB_BUILD_FRAMEWORK) set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR}) set(option_framework FRAMEWORK) @@ -85,6 +90,7 @@ SBUnixSignals.cpp SystemInitializerFull.cpp ${lldb_python_wrapper} + ${lldb_lua_wrapper} LINK_LIBS lldbBase @@ -130,6 +136,19 @@ endif () endif() +if(lldb_lua_wrapper) + add_dependencies(liblldb swig_wrapper_lua) + target_include_directories(liblldb PRIVATE ${LUA_INCLUDE_DIR}) + + if (MSVC) + set_property(SOURCE ${lldb_lua_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0") + else() + set_property(SOURCE ${lldb_lua_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " -w") + endif() + + set_source_files_properties(${lldb_lua_wrapper} PROPERTIES GENERATED ON) +endif() + set_target_properties(liblldb PROPERTIES VERSION ${LLDB_VERSION} Index: lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt +++ lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Lua REQUIRED) + add_lldb_library(lldbPluginScriptInterpreterLua PLUGIN ScriptInterpreterLua.cpp Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp @@ -26,6 +26,10 @@ #include +extern "C" { +int luaopen_lldb(lua_State *L); +} + using namespace lldb; using namespace lldb_private; @@ -34,6 +38,7 @@ Lua() : m_lua_state(luaL_newstate()) { assert(m_lua_state); luaL_openlibs(m_lua_state); + luaopen_lldb(m_lua_state); } ~Lua() { assert(m_lua_state); Index: lldb/test/Shell/ScriptInterpreter/Lua/bindings.test =================================================================== --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Lua/bindings.test @@ -0,0 +1,6 @@ +# REQUIRES: lua +# RUN: cat %s | %lldb --script-language lua 2>&1 | FileCheck %s +script +debugger = lldb.SBDebugger.Create() +print(string.format("debugger is valid: %s", debugger:IsValid())) +# CHECK: debugger is valid: true