[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG532e4203c5be: [lldb/Lua] add support for Lua function breakpoint (authored by tammela). Changed prior to commit: https://reviews.llvm.org/D93649?vs=318775=319148#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93649/new/ https://reviews.llvm.org/D93649 Files: lldb/bindings/lua/lua-swigsafecast.swig lldb/bindings/lua/lua-typemaps.swig lldb/bindings/lua/lua-wrapper.swig lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp Index: lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp === --- lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp +++ lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp @@ -24,10 +24,9 @@ #pragma warning (disable : 4190) #endif -extern "C" llvm::Expected -LLDBSwigLuaBreakpointCallbackFunction(lua_State *L, - lldb::StackFrameSP stop_frame_sp, - lldb::BreakpointLocationSP bp_loc_sp) { +extern "C" llvm::Expected LLDBSwigLuaBreakpointCallbackFunction( +lua_State *L, lldb::StackFrameSP stop_frame_sp, +lldb::BreakpointLocationSP bp_loc_sp, StructuredDataImpl *extra_args_impl) { return false; } Index: lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test === --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test @@ -0,0 +1,23 @@ +# REQUIRES: lua +# RUN: echo "int main() { return 0; }" | %clang_host -x c - -o %t +# RUN: %lldb -s %s --script-language lua %t 2>&1 | FileCheck %s +b main +script +function abc(a, b, c, ...) +print(c) +if c then print(c:GetValueForKey("foo"):GetStringValue(32)) end +end +quit +breakpoint command add -s lua -F abc +r +# CHECK: nil +breakpoint command add -s lua -F abc -k foo -v 123pizza! +r +# CHECK: +# CHECK: 123pizza! +breakpoint command add -s lua -o "abc(frame, bp_loc, ...)" +r +# CHECK: nil +breakpoint command add -s lua -F typo +r +# CHECK: attempt to call a nil value Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h === --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h @@ -9,6 +9,7 @@ #ifndef liblldb_ScriptInterpreterLua_h_ #define liblldb_ScriptInterpreterLua_h_ +#include "lldb/Core/StructuredDataImpl.h" #include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Utility/Status.h" #include "lldb/lldb-enumerations.h" @@ -22,6 +23,11 @@ CommandDataLua() : BreakpointOptions::CommandData() { interpreter = lldb::eScriptLanguageLua; } +CommandDataLua(StructuredData::ObjectSP extra_args_sp) +: BreakpointOptions::CommandData(), m_extra_args_sp(extra_args_sp) { + interpreter = lldb::eScriptLanguageLua; +} +StructuredData::ObjectSP m_extra_args_sp; }; ScriptInterpreterLua(Debugger ); @@ -72,9 +78,17 @@ Status SetBreakpointCommandCallback(BreakpointOptions *bp_options, const char *command_body_text) override; + Status SetBreakpointCommandCallbackFunction( + BreakpointOptions *bp_options, const char *function_name, + StructuredData::ObjectSP extra_args_sp) override; + private: std::unique_ptr m_lua; bool m_session_is_active = false; + + Status RegisterBreakpointCallback(BreakpointOptions *bp_options, +const char *command_body_text, +StructuredData::ObjectSP extra_args_sp); }; } // namespace lldb_private Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp === --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp @@ -264,8 +264,9 @@ debugger.GetScriptInterpreter(true, eScriptLanguageLua)); Lua = lua_interpreter->GetLua(); - llvm::Expected BoolOrErr = - lua.CallBreakpointCallback(baton, stop_frame_sp, bp_loc_sp); + CommandDataLua *bp_option_data = static_cast(baton); + llvm::Expected BoolOrErr = lua.CallBreakpointCallback( + baton, stop_frame_sp, bp_loc_sp, bp_option_data->m_extra_args_sp); if (llvm::Error E = BoolOrErr.takeError()) { debugger.GetErrorStream() << toString(std::move(E)); return true; @@ -283,10 +284,25 @@
[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
JDevlieghere accepted this revision. JDevlieghere added a comment. This revision is now accepted and ready to land. LGTM Comment at: lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test:15 +r +# CHECK: +breakpoint command add -s lua -o "abc(frame, bp_loc, ...)" tammela wrote: > JDevlieghere wrote: > > Can we unpack the SBStructuredData and check for `foo` or `123` in the > > output? > While I was doing this change, I noted that the `SBStructuredData` API for > `GetStringValue` is quite odd. > For Lua, the auto-generated SWIG wrapper enforces code like this: > ``` > local result = "" > sd:GetStringValue(result, 3) -- 'sd' should be a value with at most 3 > characters > ``` > This sort of API leaks all sorts of details to the Lua script. I think it > could be improved to just return a `std::string` / `llvm::StringRef` object. > > The SWIG wrapper also has some bugs for this class. For instance it's using > `lua_pushnumber` where it should be `lua_pushinteger` for the > `GetIntegerValue` method. > > I will report this to the SWIG authors. I still think this is important. Can you add a FIXME so we remember update this in the future? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93649/new/ https://reviews.llvm.org/D93649 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
tammela added a comment. @JDevlieghere Addressed all your comments. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93649/new/ https://reviews.llvm.org/D93649 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
tammela updated this revision to Diff 318775. tammela added a comment. Rebasing and unwrapping the SBStructuredData test case Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93649/new/ https://reviews.llvm.org/D93649 Files: lldb/bindings/lua/lua-swigsafecast.swig lldb/bindings/lua/lua-wrapper.swig lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp Index: lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp === --- lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp +++ lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp @@ -24,10 +24,9 @@ #pragma warning (disable : 4190) #endif -extern "C" llvm::Expected -LLDBSwigLuaBreakpointCallbackFunction(lua_State *L, - lldb::StackFrameSP stop_frame_sp, - lldb::BreakpointLocationSP bp_loc_sp) { +extern "C" llvm::Expected LLDBSwigLuaBreakpointCallbackFunction( +lua_State *L, lldb::StackFrameSP stop_frame_sp, +lldb::BreakpointLocationSP bp_loc_sp, StructuredDataImpl *extra_args_impl) { return false; } Index: lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test === --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test @@ -0,0 +1,23 @@ +# REQUIRES: lua +# RUN: echo "int main() { return 0; }" | %clang_host -x c - -o %t +# RUN: %lldb -s %s --script-language lua %t 2>&1 | FileCheck %s +b main +script +function abc(a, b, c, ...) +print(c) +if c then print(c:GetValueForKey("foo"):GetStringValue(32)) end +end +quit +breakpoint command add -s lua -F abc +r +# CHECK: nil +breakpoint command add -s lua -F abc -k foo -v 123pizza! +r +# CHECK: +# CHECK: 123pizza! +breakpoint command add -s lua -o "abc(frame, bp_loc, ...)" +r +# CHECK: nil +breakpoint command add -s lua -F typo +r +# CHECK: attempt to call a nil value Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h === --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h @@ -9,6 +9,7 @@ #ifndef liblldb_ScriptInterpreterLua_h_ #define liblldb_ScriptInterpreterLua_h_ +#include "lldb/Core/StructuredDataImpl.h" #include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Utility/Status.h" #include "lldb/lldb-enumerations.h" @@ -22,6 +23,11 @@ CommandDataLua() : BreakpointOptions::CommandData() { interpreter = lldb::eScriptLanguageLua; } +CommandDataLua(StructuredData::ObjectSP extra_args_sp) +: BreakpointOptions::CommandData(), m_extra_args_sp(extra_args_sp) { + interpreter = lldb::eScriptLanguageLua; +} +StructuredData::ObjectSP m_extra_args_sp; }; ScriptInterpreterLua(Debugger ); @@ -72,9 +78,17 @@ Status SetBreakpointCommandCallback(BreakpointOptions *bp_options, const char *command_body_text) override; + Status SetBreakpointCommandCallbackFunction( + BreakpointOptions *bp_options, const char *function_name, + StructuredData::ObjectSP extra_args_sp) override; + private: std::unique_ptr m_lua; bool m_session_is_active = false; + + Status RegisterBreakpointCallback(BreakpointOptions *bp_options, +const char *command_body_text, +StructuredData::ObjectSP extra_args_sp); }; } // namespace lldb_private Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp === --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp @@ -264,8 +264,9 @@ debugger.GetScriptInterpreter(true, eScriptLanguageLua)); Lua = lua_interpreter->GetLua(); - llvm::Expected BoolOrErr = - lua.CallBreakpointCallback(baton, stop_frame_sp, bp_loc_sp); + CommandDataLua *bp_option_data = static_cast(baton); + llvm::Expected BoolOrErr = lua.CallBreakpointCallback( + baton, stop_frame_sp, bp_loc_sp, bp_option_data->m_extra_args_sp); if (llvm::Error E = BoolOrErr.takeError()) { debugger.GetErrorStream() << toString(std::move(E)); return true; @@ -283,10 +284,25 @@ m_debugger.RunIOHandlerAsync(io_handler_sp); } +Status ScriptInterpreterLua::SetBreakpointCommandCallbackFunction( +BreakpointOptions *bp_options, const char *function_name, +StructuredData::ObjectSP extra_args_sp)
[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
tammela added inline comments. Comment at: lldb/bindings/lua/lua-wrapper.swig:25-29 + auto extra_args = [&]() -> llvm::Optional { + if (extra_args_impl == nullptr) + return {}; + return lldb::SBStructuredData(extra_args_impl); + } (); JDevlieghere wrote: > I don't think you need the lambda. I used `unique_ptr` but `llvm:Optional` > would work as well. `{}` is not valid on the ternary operator, but I think the version suits your suggestion. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93649/new/ https://reviews.llvm.org/D93649 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
tammela updated this revision to Diff 317395. tammela added a comment. Addressing comment Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93649/new/ https://reviews.llvm.org/D93649 Files: lldb/bindings/lua/lua-swigsafecast.swig lldb/bindings/lua/lua-wrapper.swig lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp Index: lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp === --- lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp +++ lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp @@ -24,10 +24,9 @@ #pragma warning (disable : 4190) #endif -extern "C" llvm::Expected -LLDBSwigLuaBreakpointCallbackFunction(lua_State *L, - lldb::StackFrameSP stop_frame_sp, - lldb::BreakpointLocationSP bp_loc_sp) { +extern "C" llvm::Expected LLDBSwigLuaBreakpointCallbackFunction( +lua_State *L, lldb::StackFrameSP stop_frame_sp, +lldb::BreakpointLocationSP bp_loc_sp, StructuredDataImpl *extra_args_impl) { return false; } Index: lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test === --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test @@ -0,0 +1,21 @@ +# REQUIRES: lua +# RUN: echo "int main() { return 0; }" | %clang_host -x c - -o %t +# RUN: %lldb -s %s --script-language lua %t 2>&1 | FileCheck %s +b main +script +function abc(a, b, c, ...) +print(c) +end +quit +breakpoint command add -s lua -F abc +r +# CHECK: nil +breakpoint command add -s lua -F abc -k foo -v 123 +r +# CHECK: +breakpoint command add -s lua -o "abc(frame, bp_loc, ...)" +r +# CHECK: nil +breakpoint command add -s lua -F typo +r +# CHECK: attempt to call a nil value Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h === --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h @@ -9,6 +9,7 @@ #ifndef liblldb_ScriptInterpreterLua_h_ #define liblldb_ScriptInterpreterLua_h_ +#include "lldb/Core/StructuredDataImpl.h" #include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Utility/Status.h" #include "lldb/lldb-enumerations.h" @@ -22,6 +23,11 @@ CommandDataLua() : BreakpointOptions::CommandData() { interpreter = lldb::eScriptLanguageLua; } +CommandDataLua(StructuredData::ObjectSP extra_args_sp) +: BreakpointOptions::CommandData(), m_extra_args_sp(extra_args_sp) { + interpreter = lldb::eScriptLanguageLua; +} +StructuredData::ObjectSP m_extra_args_sp; }; ScriptInterpreterLua(Debugger ); @@ -72,9 +78,17 @@ Status SetBreakpointCommandCallback(BreakpointOptions *bp_options, const char *command_body_text) override; + Status SetBreakpointCommandCallbackFunction( + BreakpointOptions *bp_options, const char *function_name, + StructuredData::ObjectSP extra_args_sp) override; + private: std::unique_ptr m_lua; bool m_session_is_active = false; + + Status RegisterBreakpointCallback(BreakpointOptions *bp_options, +const char *command_body_text, +StructuredData::ObjectSP extra_args_sp); }; } // namespace lldb_private Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp === --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp @@ -264,8 +264,9 @@ debugger.GetScriptInterpreter(true, eScriptLanguageLua)); Lua = lua_interpreter->GetLua(); - llvm::Expected BoolOrErr = - lua.CallBreakpointCallback(baton, stop_frame_sp, bp_loc_sp); + CommandDataLua *bp_option_data = static_cast(baton); + llvm::Expected BoolOrErr = lua.CallBreakpointCallback( + baton, stop_frame_sp, bp_loc_sp, bp_option_data->m_extra_args_sp); if (llvm::Error E = BoolOrErr.takeError()) { debugger.GetErrorStream() << toString(std::move(E)); return true; @@ -283,10 +284,25 @@ m_debugger.RunIOHandlerAsync(io_handler_sp); } +Status ScriptInterpreterLua::SetBreakpointCommandCallbackFunction( +BreakpointOptions *bp_options, const char *function_name, +StructuredData::ObjectSP extra_args_sp) { + const char *fmt_str = "return {0}(frame, bp_loc, ...)"; + std::string oneliner = llvm::formatv(fmt_str,
[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
tammela added inline comments. Comment at: lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test:15 +r +# CHECK: +breakpoint command add -s lua -o "abc(frame, bp_loc, ...)" JDevlieghere wrote: > Can we unpack the SBStructuredData and check for `foo` or `123` in the output? While I was doing this change, I noted that the `SBStructuredData` API for `GetStringValue` is quite odd. For Lua, the auto-generated SWIG wrapper enforces code like this: ``` local result = "" sd:GetStringValue(result, 3) -- 'sd' should be a value with at most 3 characters ``` This sort of API leaks all sorts of details to the Lua script. I think it could be improved to just return a `std::string` / `llvm::StringRef` object. The SWIG wrapper also has some bugs for this class. For instance it's using `lua_pushnumber` where it should be `lua_pushinteger` for the `GetIntegerValue` method. I will report this to the SWIG authors. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93649/new/ https://reviews.llvm.org/D93649 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
JDevlieghere added inline comments. Comment at: lldb/bindings/lua/lua-wrapper.swig:25-29 + auto extra_args = [&]() -> llvm::Optional { + if (extra_args_impl == nullptr) + return {}; + return lldb::SBStructuredData(extra_args_impl); + } (); I don't think you need the lambda. I used `unique_ptr` but `llvm:Optional` would work as well. Comment at: lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test:15 +r +# CHECK: +breakpoint command add -s lua -o "abc(frame, bp_loc, ...)" Can we unpack the SBStructuredData and check for `foo` or `123` in the output? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93649/new/ https://reviews.llvm.org/D93649 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
tammela added a comment. ping Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93649/new/ https://reviews.llvm.org/D93649 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D93649: [lldb/Lua] add support for Lua function breakpoint
tammela created this revision. tammela requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits. Adds support for running a Lua function when a breakpoint is hit. Example: breakpoint command add -s lua -F abc The above runs the Lua function 'abc' passing 2 arguments. 'frame', 'bp_loc' and 'extra_args'. A third parameter 'extra_args' is only present when there is structured data declared in the command line. Example: breakpoint command add -s lua -F abc -k foo -v bar Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D93649 Files: lldb/bindings/lua/lua-swigsafecast.swig lldb/bindings/lua/lua-wrapper.swig lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp Index: lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp === --- lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp +++ lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp @@ -24,10 +24,9 @@ #pragma warning (disable : 4190) #endif -extern "C" llvm::Expected -LLDBSwigLuaBreakpointCallbackFunction(lua_State *L, - lldb::StackFrameSP stop_frame_sp, - lldb::BreakpointLocationSP bp_loc_sp) { +extern "C" llvm::Expected LLDBSwigLuaBreakpointCallbackFunction( +lua_State *L, lldb::StackFrameSP stop_frame_sp, +lldb::BreakpointLocationSP bp_loc_sp, StructuredDataImpl *extra_args_impl) { return false; } Index: lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test === --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test @@ -0,0 +1,21 @@ +# REQUIRES: lua +# RUN: echo "int main() { return 0; }" | %clang_host -x c - -o %t +# RUN: %lldb -s %s --script-language lua %t 2>&1 | FileCheck %s +b main +script +function abc(a, b, c, ...) +print(c) +end +quit +breakpoint command add -s lua -F abc +r +# CHECK: nil +breakpoint command add -s lua -F abc -k foo -v 123 +r +# CHECK: +breakpoint command add -s lua -o "abc(frame, bp_loc, ...)" +r +# CHECK: nil +breakpoint command add -s lua -F typo +r +# CHECK: attempt to call a nil value Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h === --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h @@ -9,6 +9,7 @@ #ifndef liblldb_ScriptInterpreterLua_h_ #define liblldb_ScriptInterpreterLua_h_ +#include "lldb/Core/StructuredDataImpl.h" #include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Utility/Status.h" #include "lldb/lldb-enumerations.h" @@ -22,6 +23,11 @@ CommandDataLua() : BreakpointOptions::CommandData() { interpreter = lldb::eScriptLanguageLua; } +CommandDataLua(StructuredData::ObjectSP extra_args_sp) +: BreakpointOptions::CommandData(), m_extra_args_sp(extra_args_sp) { + interpreter = lldb::eScriptLanguageLua; +} +StructuredData::ObjectSP m_extra_args_sp; }; ScriptInterpreterLua(Debugger ); @@ -72,9 +78,17 @@ Status SetBreakpointCommandCallback(BreakpointOptions *bp_options, const char *command_body_text) override; + Status SetBreakpointCommandCallbackFunction( + BreakpointOptions *bp_options, const char *function_name, + StructuredData::ObjectSP extra_args_sp) override; + private: std::unique_ptr m_lua; bool m_session_is_active = false; + + Status RegisterBreakpointCallback(BreakpointOptions *bp_options, +const char *command_body_text, +StructuredData::ObjectSP extra_args_sp); }; } // namespace lldb_private Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp === --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp @@ -265,8 +265,9 @@ debugger.GetScriptInterpreter(true, eScriptLanguageLua)); Lua = lua_interpreter->GetLua(); - llvm::Expected BoolOrErr = - lua.CallBreakpointCallback(baton, stop_frame_sp, bp_loc_sp); + CommandDataLua *bp_option_data = static_cast(baton); + llvm::Expected BoolOrErr = lua.CallBreakpointCallback( + baton, stop_frame_sp, bp_loc_sp, bp_option_data->m_extra_args_sp); if (llvm::Error E = BoolOrErr.takeError()) { debugger.GetErrorStream() << toString(std::move(E)); return true; @@