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/Python/ScriptInterpreterPython.cpp | |
parent | 56da28240f3c9d1c0b7152749bfd4777c67828e0 (diff) | |
download | llvm-cfb96d845a684a5c567823dbe2aa4392937ee979.zip llvm-cfb96d845a684a5c567823dbe2aa4392937ee979.tar.gz llvm-cfb96d845a684a5c567823dbe2aa4392937ee979.tar.bz2 |
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/Python/ScriptInterpreterPython.cpp')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index fd4157d..9a59308 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -635,11 +635,10 @@ void ScriptInterpreterPythonImpl::IOHandlerInputComplete(IOHandler &io_handler, case eIOHandlerNone: break; case eIOHandlerBreakpoint: { - std::vector<BreakpointOptions *> *bp_options_vec = - (std::vector<BreakpointOptions *> *)io_handler.GetUserData(); - for (auto bp_options : *bp_options_vec) { - if (!bp_options) - continue; + std::vector<std::reference_wrapper<BreakpointOptions>> *bp_options_vec = + (std::vector<std::reference_wrapper<BreakpointOptions>> *) + io_handler.GetUserData(); + for (BreakpointOptions &bp_options : *bp_options_vec) { auto data_up = std::make_unique<CommandDataPython>(); if (!data_up) @@ -653,7 +652,7 @@ void ScriptInterpreterPythonImpl::IOHandlerInputComplete(IOHandler &io_handler, .Success()) { auto baton_sp = std::make_shared<BreakpointOptions::CommandBaton>( std::move(data_up)); - bp_options->SetCallback( + bp_options.SetCallback( ScriptInterpreterPythonImpl::BreakpointCallbackFunction, baton_sp); } else if (!batch_mode) { StreamFileSP error_sp = io_handler.GetErrorStreamFileSP(); @@ -1226,7 +1225,7 @@ Status ScriptInterpreterPythonImpl::ExecuteMultipleLines( } void ScriptInterpreterPythonImpl::CollectDataForBreakpointCommandCallback( - std::vector<BreakpointOptions *> &bp_options_vec, + std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec, CommandReturnObject &result) { m_active_io_handler = eIOHandlerBreakpoint; m_debugger.GetCommandInterpreter().GetPythonCommandsFromIOHandler( @@ -1241,7 +1240,7 @@ void ScriptInterpreterPythonImpl::CollectDataForWatchpointCommandCallback( } Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallbackFunction( - BreakpointOptions *bp_options, const char *function_name, + BreakpointOptions &bp_options, const char *function_name, StructuredData::ObjectSP extra_args_sp) { Status error; // For now just cons up a oneliner that calls the provided function. @@ -1283,7 +1282,7 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallbackFunction( } Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( - BreakpointOptions *bp_options, + BreakpointOptions &bp_options, std::unique_ptr<BreakpointOptions::CommandData> &cmd_data_up) { Status error; error = GenerateBreakpointCommandCallbackData(cmd_data_up->user_source, @@ -1294,21 +1293,20 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( } auto baton_sp = std::make_shared<BreakpointOptions::CommandBaton>(std::move(cmd_data_up)); - bp_options->SetCallback( + bp_options.SetCallback( ScriptInterpreterPythonImpl::BreakpointCallbackFunction, baton_sp); return error; } Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( - BreakpointOptions *bp_options, const char *command_body_text) { + BreakpointOptions &bp_options, const char *command_body_text) { return SetBreakpointCommandCallback(bp_options, command_body_text, {},false); } // Set a Python one-liner as the callback for the breakpoint. Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( - BreakpointOptions *bp_options, const char *command_body_text, - StructuredData::ObjectSP extra_args_sp, - bool uses_extra_args) { + BreakpointOptions &bp_options, const char *command_body_text, + StructuredData::ObjectSP extra_args_sp, bool uses_extra_args) { auto data_up = std::make_unique<CommandDataPython>(extra_args_sp); // Split the command_body_text into lines, and pass that to // GenerateBreakpointCommandCallbackData. That will wrap the body in an @@ -1322,7 +1320,7 @@ Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback( if (error.Success()) { auto baton_sp = std::make_shared<BreakpointOptions::CommandBaton>(std::move(data_up)); - bp_options->SetCallback( + bp_options.SetCallback( ScriptInterpreterPythonImpl::BreakpointCallbackFunction, baton_sp); return error; } |