[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.
This commit is contained in:
parent
554939583a
commit
b2fa3b922e
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)",
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -128,13 +128,10 @@ Target::~Target() {
|
|||
DeleteCurrentProcess();
|
||||
}
|
||||
|
||||
void Target::PrimeFromDummyTarget(Target *target) {
|
||||
if (!target)
|
||||
return;
|
||||
void Target::PrimeFromDummyTarget(Target &target) {
|
||||
m_stop_hooks = target.m_stop_hooks;
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue