1%header %{ 2 3template <typename T> 4void 5PushSBClass(lua_State* L, T* obj); 6 7%} 8 9%wrapper %{ 10 11// This function is called from Lua::CallBreakpointCallback 12SWIGEXPORT llvm::Expected<bool> 13LLDBSwigLuaBreakpointCallbackFunction 14( 15 lua_State *L, 16 lldb::StackFrameSP stop_frame_sp, 17 lldb::BreakpointLocationSP bp_loc_sp, 18 StructuredDataImpl *extra_args_impl 19) 20{ 21 lldb::SBFrame sb_frame(stop_frame_sp); 22 lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp); 23 int nargs = 2; 24 25 llvm::Optional<lldb::SBStructuredData> extra_args; 26 if (extra_args_impl) 27 extra_args = lldb::SBStructuredData(extra_args_impl); 28 29 // Push the Lua wrappers 30 PushSBClass(L, &sb_frame); 31 PushSBClass(L, &sb_bp_loc); 32 33 if (extra_args.hasValue()) { 34 PushSBClass(L, extra_args.getPointer()); 35 nargs++; 36 } 37 38 // Call into the Lua callback passing 'sb_frame' and 'sb_bp_loc'. 39 // Expects a boolean return. 40 if (lua_pcall(L, nargs, 1, 0) != LUA_OK) { 41 llvm::Error E = llvm::make_error<llvm::StringError>( 42 llvm::formatv("{0}\n", lua_tostring(L, -1)), 43 llvm::inconvertibleErrorCode()); 44 // Pop error message from the stack. 45 lua_pop(L, 1); 46 return std::move(E); 47 } 48 49 // Boolean return from the callback 50 bool stop = lua_toboolean(L, -1); 51 lua_pop(L, 1); 52 53 return stop; 54} 55 56// This function is called from Lua::CallWatchpointCallback 57SWIGEXPORT llvm::Expected<bool> 58LLDBSwigLuaWatchpointCallbackFunction 59( 60 lua_State *L, 61 lldb::StackFrameSP stop_frame_sp, 62 lldb::WatchpointSP wp_sp 63) 64{ 65 lldb::SBFrame sb_frame(stop_frame_sp); 66 lldb::SBWatchpoint sb_wp(wp_sp); 67 int nargs = 2; 68 69 // Push the Lua wrappers 70 PushSBClass(L, &sb_frame); 71 PushSBClass(L, &sb_wp); 72 73 // Call into the Lua callback passing 'sb_frame' and 'sb_wp'. 74 // Expects a boolean return. 75 if (lua_pcall(L, nargs, 1, 0) != LUA_OK) { 76 llvm::Error E = llvm::make_error<llvm::StringError>( 77 llvm::formatv("{0}\n", lua_tostring(L, -1)), 78 llvm::inconvertibleErrorCode()); 79 // Pop error message from the stack. 80 lua_pop(L, 1); 81 return std::move(E); 82 } 83 84 // Boolean return from the callback 85 bool stop = lua_toboolean(L, -1); 86 lua_pop(L, 1); 87 88 return stop; 89} 90 91 92%} 93