diff options
| author | Jim Ingham <jingham@apple.com> | 2021-06-11 17:00:46 -0700 |
|---|---|---|
| committer | Jim Ingham <jingham@apple.com> | 2021-06-15 14:34:02 -0700 |
| commit | cfb96d845a684a5c567823dbe2aa4392937ee979 (patch) | |
| tree | 90bd697e80379e5571851ea981486af352823f1b /lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp | |
| parent | 56da28240f3c9d1c0b7152749bfd4777c67828e0 (diff) | |
Convert functions that were returning BreakpointOption * to BreakpointOption &.
This is an NFC cleanup.
Many of the API's that returned BreakpointOptions always returned valid ones.
Internally the BreakpointLocations usually have null BreakpointOptions, since they
use their owner's options until an option is set specifically on the location.
So the original code used pointers & unique_ptr everywhere for consistency.
But that made the code hard to reason about from the outside.
This patch changes the code so that everywhere an API is guaranteed to
return a non-null BreakpointOption, it returns it as a reference to make
that clear.
It also changes the Breakpoint to hold a BreakpointOption
member where it previously had a UP. Since we were always filling the UP
in the Breakpoint constructor, having the UP wasn't helping anything.
Differential Revision: https://reviews.llvm.org/D104162
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp')
| -rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp index 920e334f51aa..e6d850d73f7c 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp @@ -98,9 +98,10 @@ public: std::string &data) override { switch (m_active_io_handler) { case eIOHandlerBreakpoint: { - auto *bp_options_vec = static_cast<std::vector<BreakpointOptions *> *>( - io_handler.GetUserData()); - for (auto *bp_options : *bp_options_vec) { + auto *bp_options_vec = + static_cast<std::vector<std::reference_wrapper<BreakpointOptions>> *>( + io_handler.GetUserData()); + for (BreakpointOptions &bp_options : *bp_options_vec) { Status error = m_script_interpreter.SetBreakpointCommandCallback( bp_options, data.c_str()); if (error.Fail()) @@ -276,7 +277,7 @@ bool ScriptInterpreterLua::BreakpointCallbackFunction( } void ScriptInterpreterLua::CollectDataForBreakpointCommandCallback( - std::vector<BreakpointOptions *> &bp_options_vec, + std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec, CommandReturnObject &result) { IOHandlerSP io_handler_sp( new IOHandlerLuaInterpreter(m_debugger, *this, eIOHandlerBreakpoint)); @@ -285,7 +286,7 @@ void ScriptInterpreterLua::CollectDataForBreakpointCommandCallback( } Status ScriptInterpreterLua::SetBreakpointCommandCallbackFunction( - BreakpointOptions *bp_options, const char *function_name, + 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(); @@ -294,12 +295,12 @@ Status ScriptInterpreterLua::SetBreakpointCommandCallbackFunction( } Status ScriptInterpreterLua::SetBreakpointCommandCallback( - BreakpointOptions *bp_options, const char *command_body_text) { + 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, + BreakpointOptions &bp_options, const char *command_body_text, StructuredData::ObjectSP extra_args_sp) { Status error; auto data_up = std::make_unique<CommandDataLua>(extra_args_sp); @@ -308,8 +309,8 @@ Status ScriptInterpreterLua::RegisterBreakpointCallback( return error; auto baton_sp = std::make_shared<BreakpointOptions::CommandBaton>(std::move(data_up)); - bp_options->SetCallback(ScriptInterpreterLua::BreakpointCallbackFunction, - baton_sp); + bp_options.SetCallback(ScriptInterpreterLua::BreakpointCallbackFunction, + baton_sp); return error; } |
