summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-09-13 17:53:38 +0000
committerZachary Turner <zturner@google.com>2016-09-13 17:53:38 +0000
commit4e4fbe821119fd168f3dd65fc88fa4220f6826fe (patch)
treea8766b18f241bc05bd31c01ab88d20a8f1c7e6cb /lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
parent8ea02f4e1c050e2bccac28439265656e8a2645c4 (diff)
downloadbcm5719-llvm-4e4fbe821119fd168f3dd65fc88fa4220f6826fe.tar.gz
bcm5719-llvm-4e4fbe821119fd168f3dd65fc88fa4220f6826fe.zip
Some more pointer safety in Breakpoint.
Plumb unique_ptrs<> all the way through the baton interface. NFC, this is a minor improvement to remove the possibility of an accidental pointer ownership issue. Reviewed By: jingham Differential Revision: https://reviews.llvm.org/D24495 llvm-svn: 281360
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp79
1 files changed, 37 insertions, 42 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 3257afbba9b..86cceebb531 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -412,43 +412,18 @@ void ScriptInterpreterPython::IOHandlerInputComplete(IOHandler &io_handler,
if (!bp_options)
continue;
- std::unique_ptr<BreakpointOptions::CommandData> data_ap(
- new BreakpointOptions::CommandData());
- if (data_ap.get()) {
- data_ap->user_source.SplitIntoLines(data);
-
- if (GenerateBreakpointCommandCallbackData(data_ap->user_source,
- data_ap->script_source)
- .Success()) {
- BreakpointOptions::CommandBatonSP baton_sp(
- new BreakpointOptions::CommandBaton(data_ap.release()));
- bp_options->SetCallback(
- ScriptInterpreterPython::BreakpointCallbackFunction, baton_sp);
- } else if (!batch_mode) {
- StreamFileSP error_sp = io_handler.GetErrorStreamFile();
- if (error_sp) {
- error_sp->Printf("Warning: No command attached to breakpoint.\n");
- error_sp->Flush();
- }
- }
- }
- }
- m_active_io_handler = eIOHandlerNone;
- } break;
- case eIOHandlerWatchpoint: {
- WatchpointOptions *wp_options =
- (WatchpointOptions *)io_handler.GetUserData();
- std::unique_ptr<WatchpointOptions::CommandData> data_ap(
- new WatchpointOptions::CommandData());
- if (data_ap.get()) {
+ auto data_ap = llvm::make_unique<BreakpointOptions::CommandData>();
+ if (!data_ap)
+ break;
data_ap->user_source.SplitIntoLines(data);
- if (GenerateWatchpointCommandCallbackData(data_ap->user_source,
- data_ap->script_source)) {
- BatonSP baton_sp(
- new WatchpointOptions::CommandBaton(data_ap.release()));
- wp_options->SetCallback(
- ScriptInterpreterPython::WatchpointCallbackFunction, baton_sp);
+ if (GenerateBreakpointCommandCallbackData(data_ap->user_source,
+ data_ap->script_source)
+ .Success()) {
+ auto baton_sp = std::make_shared<BreakpointOptions::CommandBaton>(
+ std::move(data_ap));
+ bp_options->SetCallback(
+ ScriptInterpreterPython::BreakpointCallbackFunction, baton_sp);
} else if (!batch_mode) {
StreamFileSP error_sp = io_handler.GetErrorStreamFile();
if (error_sp) {
@@ -459,6 +434,27 @@ void ScriptInterpreterPython::IOHandlerInputComplete(IOHandler &io_handler,
}
m_active_io_handler = eIOHandlerNone;
} break;
+ case eIOHandlerWatchpoint: {
+ WatchpointOptions *wp_options =
+ (WatchpointOptions *)io_handler.GetUserData();
+ auto data_ap = llvm::make_unique<WatchpointOptions::CommandData>();
+ data_ap->user_source.SplitIntoLines(data);
+
+ if (GenerateWatchpointCommandCallbackData(data_ap->user_source,
+ data_ap->script_source)) {
+ auto baton_sp =
+ std::make_shared<WatchpointOptions::CommandBaton>(std::move(data_ap));
+ wp_options->SetCallback(
+ ScriptInterpreterPython::WatchpointCallbackFunction, baton_sp);
+ } else if (!batch_mode) {
+ StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+ if (error_sp) {
+ error_sp->Printf("Warning: No command attached to breakpoint.\n");
+ error_sp->Flush();
+ }
+ }
+ m_active_io_handler = eIOHandlerNone;
+ } break;
}
}
@@ -1238,8 +1234,7 @@ void ScriptInterpreterPython::SetBreakpointCommandCallbackFunction(
// Set a Python one-liner as the callback for the breakpoint.
Error ScriptInterpreterPython::SetBreakpointCommandCallback(
BreakpointOptions *bp_options, const char *command_body_text) {
- std::unique_ptr<BreakpointOptions::CommandData> data_ap(
- new BreakpointOptions::CommandData());
+ auto data_ap = llvm::make_unique<BreakpointOptions::CommandData>();
// Split the command_body_text into lines, and pass that to
// GenerateBreakpointCommandCallbackData. That will
@@ -1251,8 +1246,8 @@ Error ScriptInterpreterPython::SetBreakpointCommandCallback(
Error error = GenerateBreakpointCommandCallbackData(data_ap->user_source,
data_ap->script_source);
if (error.Success()) {
- BreakpointOptions::CommandBatonSP baton_sp(
- new BreakpointOptions::CommandBaton(data_ap.release()));
+ auto baton_sp =
+ std::make_shared<BreakpointOptions::CommandBaton>(std::move(data_ap));
bp_options->SetCallback(ScriptInterpreterPython::BreakpointCallbackFunction,
baton_sp);
return error;
@@ -1263,8 +1258,7 @@ Error ScriptInterpreterPython::SetBreakpointCommandCallback(
// Set a Python one-liner as the callback for the watchpoint.
void ScriptInterpreterPython::SetWatchpointCommandCallback(
WatchpointOptions *wp_options, const char *oneliner) {
- std::unique_ptr<WatchpointOptions::CommandData> data_ap(
- new WatchpointOptions::CommandData());
+ auto data_ap = llvm::make_unique<WatchpointOptions::CommandData>();
// It's necessary to set both user_source and script_source to the oneliner.
// The former is used to generate callback description (as in watchpoint
@@ -1277,7 +1271,8 @@ void ScriptInterpreterPython::SetWatchpointCommandCallback(
if (GenerateWatchpointCommandCallbackData(data_ap->user_source,
data_ap->script_source)) {
- BatonSP baton_sp(new WatchpointOptions::CommandBaton(data_ap.release()));
+ auto baton_sp =
+ std::make_shared<WatchpointOptions::CommandBaton>(std::move(data_ap));
wp_options->SetCallback(ScriptInterpreterPython::WatchpointCallbackFunction,
baton_sp);
}
OpenPOWER on IntegriCloud