diff options
author | Siger Yang <sigeryeung@gmail.com> | 2021-07-04 19:38:12 -0300 |
---|---|---|
committer | Pedro Tammela <pctammela@gmail.com> | 2021-07-07 14:51:02 -0300 |
commit | e81ba283131cf76ae62fa9b601a24d080578efaa (patch) | |
tree | 0939a8b3fcd96a847409c32bec8a59f8821e0c56 /lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp | |
parent | 3ebfeb258698db82b7525cfaa1efd04db93d72ba (diff) | |
download | llvm-e81ba283131cf76ae62fa9b601a24d080578efaa.zip llvm-e81ba283131cf76ae62fa9b601a24d080578efaa.tar.gz llvm-e81ba283131cf76ae62fa9b601a24d080578efaa.tar.bz2 |
[lldb/lua] Add scripted watchpoints for Lua
Add support for Lua scripted watchpoints, with basic tests.
Differential Revision: https://reviews.llvm.org/D105034
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp index f14e273..e99b7b8 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp @@ -30,6 +30,9 @@ extern "C" llvm::Expected<bool> LLDBSwigLuaBreakpointCallbackFunction( lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::BreakpointLocationSP bp_loc_sp, StructuredDataImpl *extra_args_impl); +extern "C" llvm::Expected<bool> LLDBSwigLuaWatchpointCallbackFunction( + lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp); + #if _MSC_VER #pragma warning (pop) #endif @@ -113,6 +116,32 @@ Lua::CallBreakpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp, bp_loc_sp, extra_args_impl); } +llvm::Error Lua::RegisterWatchpointCallback(void *baton, const char *body) { + lua_pushlightuserdata(m_lua_state, baton); + const char *fmt_str = "return function(frame, wp, ...) {0} end"; + std::string func_str = llvm::formatv(fmt_str, body).str(); + if (luaL_dostring(m_lua_state, func_str.c_str()) != LUA_OK) { + llvm::Error e = llvm::make_error<llvm::StringError>( + llvm::formatv("{0}", lua_tostring(m_lua_state, -1)), + llvm::inconvertibleErrorCode()); + // Pop error message from the stack. + lua_pop(m_lua_state, 2); + return e; + } + lua_settable(m_lua_state, LUA_REGISTRYINDEX); + return llvm::Error::success(); +} + +llvm::Expected<bool> +Lua::CallWatchpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp, + lldb::WatchpointSP wp_sp) { + + lua_pushlightuserdata(m_lua_state, baton); + lua_gettable(m_lua_state, LUA_REGISTRYINDEX); + return LLDBSwigLuaWatchpointCallbackFunction(m_lua_state, stop_frame_sp, + wp_sp); +} + llvm::Error Lua::CheckSyntax(llvm::StringRef buffer) { int error = luaL_loadbuffer(m_lua_state, buffer.data(), buffer.size(), "buffer"); |