summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
diff options
context:
space:
mode:
authorPedro Tammela <pctammela@gmail.com>2020-12-21 17:59:35 +0000
committerPedro Tammela <pctammela@gmail.com>2021-01-25 23:40:57 +0000
commit532e4203c5be909af701df4dedfd36c9b8f85034 (patch)
tree86af93b0ded9c0e6e94d80ddd435023a9f6b999d /lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
parentce7f9cdb50a98cef5ee6e232e45e16c150c966e9 (diff)
[lldb/Lua] add support for Lua function breakpoint
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 Differential Revision: https://reviews.llvm.org/D93649
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
index 1dbadb90813c..920e334f51aa 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -264,8 +264,9 @@ bool ScriptInterpreterLua::BreakpointCallbackFunction(
debugger.GetScriptInterpreter(true, eScriptLanguageLua));
Lua &lua = lua_interpreter->GetLua();
- llvm::Expected<bool> BoolOrErr =
- lua.CallBreakpointCallback(baton, stop_frame_sp, bp_loc_sp);
+ CommandDataLua *bp_option_data = static_cast<CommandDataLua *>(baton);
+ llvm::Expected<bool> 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 @@ void ScriptInterpreterLua::CollectDataForBreakpointCommandCallback(
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, function_name).str();
+ return RegisterBreakpointCallback(bp_options, oneliner.c_str(),
+ extra_args_sp);
+}
+
Status ScriptInterpreterLua::SetBreakpointCommandCallback(
BreakpointOptions *bp_options, const char *command_body_text) {
+ return RegisterBreakpointCallback(bp_options, command_body_text, {});
+}
+
+Status ScriptInterpreterLua::RegisterBreakpointCallback(
+ BreakpointOptions *bp_options, const char *command_body_text,
+ StructuredData::ObjectSP extra_args_sp) {
Status error;
- auto data_up = std::make_unique<CommandDataLua>();
+ auto data_up = std::make_unique<CommandDataLua>(extra_args_sp);
error = m_lua->RegisterBreakpointCallback(data_up.get(), command_body_text);
if (error.Fail())
return error;