diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2020-11-09 15:25:59 -0800 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2020-11-09 15:42:27 -0800 |
commit | b2fa3b922ecb219429ec7b839d15a06aedbc955a (patch) | |
tree | 266e4fc62625a1487f7620934bbc6b57fdf32d09 | |
parent | 554939583a122c48e8c3ffa1bff734b3ce963627 (diff) | |
download | llvm-b2fa3b922ecb219429ec7b839d15a06aedbc955a.zip llvm-b2fa3b922ecb219429ec7b839d15a06aedbc955a.tar.gz llvm-b2fa3b922ecb219429ec7b839d15a06aedbc955a.tar.bz2 |
[lldb] Make GetSelectedOrDummyTarget return the target by reference (NFC)
Return references from GetDummyTarget and GetSelectedOrDummyTarget. This
matches how the APIs are already used in practice.
-rw-r--r-- | lldb/include/lldb/Core/Debugger.h | 4 | ||||
-rw-r--r-- | lldb/include/lldb/Target/Target.h | 12 | ||||
-rw-r--r-- | lldb/source/API/SBDebugger.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectExpression.cpp | 22 | ||||
-rw-r--r-- | lldb/source/Core/Debugger.cpp | 9 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 12 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandObject.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Target/Target.cpp | 13 |
8 files changed, 31 insertions, 47 deletions
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index 252380d..68daae1 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -334,8 +334,8 @@ public: // This is for use in the command interpreter, when you either want the // selected target, or if no target is present you want to prime the dummy // target with entities that will be copied over to new targets. - Target *GetSelectedOrDummyTarget(bool prefer_dummy = false); - Target *GetDummyTarget() { return m_dummy_target_sp.get(); } + Target &GetSelectedOrDummyTarget(bool prefer_dummy = false); + Target &GetDummyTarget() { return *m_dummy_target_sp; } lldb::BroadcasterManagerSP GetBroadcasterManager() { return m_broadcaster_manager_sp; diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 41c07b7a..f77917a 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -212,7 +212,7 @@ public: bool GetInjectLocalVariables(ExecutionContext *exe_ctx) const; void SetInjectLocalVariables(ExecutionContext *exe_ctx, bool b); - + void SetRequireHardwareBreakpoints(bool b); bool GetRequireHardwareBreakpoints() const; @@ -1252,7 +1252,7 @@ public: StructuredDataImpl *m_extra_args; // We own this structured data, // but the SD itself manages the UP. /// This holds the python callback object. - StructuredData::GenericSP m_implementation_sp; + StructuredData::GenericSP m_implementation_sp; /// Use CreateStopHook to make a new empty stop hook. The GetCommandPointer /// and fill it with commands, and SetSpecifier to set the specifier shared @@ -1374,12 +1374,12 @@ protected: lldb::PlatformSP m_platform_sp; ///< The platform for this target. std::recursive_mutex m_mutex; ///< An API mutex that is used by the lldb::SB* /// classes make the SB interface thread safe - /// When the private state thread calls SB API's - usually because it is + /// When the private state thread calls SB API's - usually because it is /// running OS plugin or Python ThreadPlan code - it should not block on the /// API mutex that is held by the code that kicked off the sequence of events - /// that led us to run the code. We hand out this mutex instead when we + /// that led us to run the code. We hand out this mutex instead when we /// detect that code is running on the private state thread. - std::recursive_mutex m_private_mutex; + std::recursive_mutex m_private_mutex; Arch m_arch; ModuleList m_images; ///< The list of images for this process (shared /// libraries and anything dynamically loaded). @@ -1458,7 +1458,7 @@ private: bool ProcessIsValid(); // Copy breakpoints, stop hooks and so forth from the dummy target: - void PrimeFromDummyTarget(Target *dummy_target); + void PrimeFromDummyTarget(Target &target); void AddBreakpoint(lldb::BreakpointSP breakpoint_sp, bool internal); diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index f714e3b..a5bf457 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -858,7 +858,7 @@ SBTarget SBDebugger::GetDummyTarget() { SBTarget sb_target; if (m_opaque_sp) { - sb_target.SetSP(m_opaque_sp->GetDummyTarget()->shared_from_this()); + sb_target.SetSP(m_opaque_sp->GetDummyTarget().shared_from_this()); } Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); LLDB_LOGF(log, "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)", diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index b23adb0..58eaa3f 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -304,11 +304,8 @@ void CommandObjectExpression::HandleCompletion(CompletionRequest &request) { return; ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); - - Target *target = exe_ctx.GetTargetPtr(); - - if (!target) - target = &GetDummyTarget(); + Target *exe_target = exe_ctx.GetTargetPtr(); + Target &target = exe_target ? *exe_target : GetDummyTarget(); unsigned cursor_pos = request.GetRawCursorPos(); // Get the full user input including the suffix. The suffix is necessary @@ -342,7 +339,7 @@ void CommandObjectExpression::HandleCompletion(CompletionRequest &request) { auto language = exe_ctx.GetFrameRef().GetLanguage(); Status error; - lldb::UserExpressionSP expr(target->GetUserExpressionForLanguage( + lldb::UserExpressionSP expr(target.GetUserExpressionForLanguage( code, llvm::StringRef(), language, UserExpression::eResultTypeAny, options, nullptr, error)); if (error.Fail()) @@ -411,22 +408,19 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr, // command object DoExecute has finished when doing multi-line expression // that use an input reader... ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); - - Target *target = exe_ctx.GetTargetPtr(); - - if (!target) - target = &GetDummyTarget(); + Target *exe_target = exe_ctx.GetTargetPtr(); + Target &target = exe_target ? *exe_target : GetDummyTarget(); lldb::ValueObjectSP result_valobj_sp; StackFrame *frame = exe_ctx.GetFramePtr(); - const EvaluateExpressionOptions options = GetEvalOptions(*target); - ExpressionResults success = target->EvaluateExpression( + const EvaluateExpressionOptions options = GetEvalOptions(target); + ExpressionResults success = target.EvaluateExpression( expr, frame, result_valobj_sp, options, &m_fixed_expression); // We only tell you about the FixIt if we applied it. The compiler errors // will suggest the FixIt if it parsed. - if (!m_fixed_expression.empty() && target->GetEnableNotifyAboutFixIts()) { + if (!m_fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) { if (success == eExpressionCompleted) error_stream.Printf(" Fix-it applied, fixed expression was: \n %s\n", m_fixed_expression.c_str()); diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 5f75ac2..b16ce68 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1578,14 +1578,11 @@ void Debugger::JoinIOHandlerThread() { } } -Target *Debugger::GetSelectedOrDummyTarget(bool prefer_dummy) { - Target *target = nullptr; +Target &Debugger::GetSelectedOrDummyTarget(bool prefer_dummy) { if (!prefer_dummy) { - target = m_target_list.GetSelectedTarget().get(); - if (target) - return target; + if (TargetSP target = m_target_list.GetSelectedTarget()) + return *target; } - return GetDummyTarget(); } diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index d6b4b89..4d33d17 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1523,16 +1523,12 @@ Status CommandInterpreter::PreprocessCommand(std::string &command) { end_backtick - expr_content_start); ExecutionContext exe_ctx(GetExecutionContext()); - Target *target = exe_ctx.GetTargetPtr(); // Get a dummy target to allow for calculator mode while processing // backticks. This also helps break the infinite loop caused when target is // null. - if (!target) - target = m_debugger.GetDummyTarget(); - - if (!target) - continue; + Target *exe_target = exe_ctx.GetTargetPtr(); + Target &target = exe_target ? *exe_target : m_debugger.GetDummyTarget(); ValueObjectSP expr_result_valobj_sp; @@ -1545,8 +1541,8 @@ Status CommandInterpreter::PreprocessCommand(std::string &command) { options.SetTimeout(llvm::None); ExpressionResults expr_result = - target->EvaluateExpression(expr_str.c_str(), exe_ctx.GetFramePtr(), - expr_result_valobj_sp, options); + target.EvaluateExpression(expr_str.c_str(), exe_ctx.GetFramePtr(), + expr_result_valobj_sp, options); if (expr_result == eExpressionCompleted) { Scalar scalar; diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index 58e54e8..7e89faa 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -930,11 +930,11 @@ const char *CommandObject::GetArgumentDescriptionAsCString( } Target &CommandObject::GetDummyTarget() { - return *m_interpreter.GetDebugger().GetDummyTarget(); + return m_interpreter.GetDebugger().GetDummyTarget(); } Target &CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) { - return *m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy); + return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy); } Target &CommandObject::GetSelectedTarget() { diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index b4a5b53..9bed203 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -128,13 +128,10 @@ Target::~Target() { DeleteCurrentProcess(); } -void Target::PrimeFromDummyTarget(Target *target) { - if (!target) - return; - - m_stop_hooks = target->m_stop_hooks; +void Target::PrimeFromDummyTarget(Target &target) { + m_stop_hooks = target.m_stop_hooks; - for (const auto &breakpoint_sp : target->m_breakpoint_list.Breakpoints()) { + for (const auto &breakpoint_sp : target.m_breakpoint_list.Breakpoints()) { if (breakpoint_sp->IsInternal()) continue; @@ -143,14 +140,14 @@ void Target::PrimeFromDummyTarget(Target *target) { AddBreakpoint(std::move(new_bp), false); } - for (auto bp_name_entry : target->m_breakpoint_names) { + for (auto bp_name_entry : target.m_breakpoint_names) { BreakpointName *new_bp_name = new BreakpointName(*bp_name_entry.second); AddBreakpointName(new_bp_name); } m_frame_recognizer_manager_up = std::make_unique<StackFrameRecognizerManager>( - *target->m_frame_recognizer_manager_up); + *target.m_frame_recognizer_manager_up); } void Target::Dump(Stream *s, lldb::DescriptionLevel description_level) { |