From 532e4203c5be909af701df4dedfd36c9b8f85034 Mon Sep 17 00:00:00 2001 From: Pedro Tammela Date: Mon, 21 Dec 2020 17:59:35 +0000 Subject: [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 --- .../ScriptInterpreter/Lua/ScriptInterpreterLua.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp') 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 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 @@ 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(); + auto data_up = std::make_unique(extra_args_sp); error = m_lua->RegisterBreakpointCallback(data_up.get(), command_body_text); if (error.Fail()) return error; -- cgit v1.2.3