LLDB mainline
ThreadPlanShouldStopHere.cpp
Go to the documentation of this file.
1//===-- ThreadPlanShouldStopHere.cpp --------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Symbol/Symbol.h"
14#include "lldb/Target/Thread.h"
16#include "lldb/Utility/Log.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
21// ThreadPlanShouldStopHere constructor
30
38
40
42 FrameComparison operation, Status &status) {
43 bool should_stop_here = true;
44 if (m_callbacks.should_stop_here_callback) {
45 should_stop_here = m_callbacks.should_stop_here_callback(
46 m_owner, m_flags, operation, status, m_baton);
47 Log *log = GetLog(LLDBLog::Step);
48 if (log) {
49 lldb::addr_t current_addr =
50 m_owner->GetThread().GetRegisterContext()->GetPC(0);
51
52 LLDB_LOGF(log, "ShouldStopHere callback returned %u from 0x%" PRIx64 ".",
53 should_stop_here, current_addr);
54 }
55 }
56
57 return should_stop_here;
58}
59
61 ThreadPlan *current_plan, Flags &flags, FrameComparison operation,
62 Status &status, void *baton) {
63 bool should_stop_here = true;
64 StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
65 if (!frame)
66 return true;
67
68 Log *log = GetLog(LLDBLog::Step);
69
70 if ((operation == eFrameCompareOlder && flags.Test(eStepOutAvoidNoDebug)) ||
71 (operation == eFrameCompareYounger && flags.Test(eStepInAvoidNoDebug)) ||
72 (operation == eFrameCompareSameParent &&
73 flags.Test(eStepInAvoidNoDebug))) {
74 if (!frame->HasDebugInformation()) {
75 LLDB_LOGF(log, "Stepping out of frame with no debug info");
76
77 should_stop_here = false;
78 }
79 }
80
81 // Check whether the frame we are in is a language runtime thunk, only for
82 // step out:
83 if (operation == eFrameCompareOlder) {
84 if (Symbol *symbol = frame->GetSymbolContext(eSymbolContextSymbol).symbol) {
85 ProcessSP process_sp(current_plan->GetThread().GetProcess());
86 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
87 if (runtime->IsSymbolARuntimeThunk(*symbol) &&
90 log, "Stepping out past a language thunk %s for: %s",
91 frame->GetFunctionName(),
92 Language::GetNameForLanguageType(runtime->GetLanguageType()));
93 should_stop_here = false;
94 break;
95 }
96 }
97 }
98 }
99 // Always avoid code with line number 0.
100 // FIXME: At present the ShouldStop and the StepFromHere calculate this
101 // independently. If this ever
102 // becomes expensive (this one isn't) we can try to have this set a state
103 // that the StepFromHere can use.
104 if (frame) {
105 SymbolContext sc;
106 sc = frame->GetSymbolContext(eSymbolContextLineEntry);
107 if (sc.line_entry.line == 0)
108 should_stop_here = false;
109 }
110
111 return should_stop_here;
112}
113
115 ThreadPlan *current_plan, Flags &flags, FrameComparison operation,
116 Status &status, void *baton) {
117 const bool stop_others = false;
118 const size_t frame_index = 0;
119 ThreadPlanSP return_plan_sp;
120 // If we are stepping through code at line number 0, then we need to step
121 // over this range. Otherwise we will step out.
122 Log *log = GetLog(LLDBLog::Step);
123
124 StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
125 if (!frame)
126 return return_plan_sp;
127 SymbolContext sc;
128 sc = frame->GetSymbolContext(eSymbolContextLineEntry | eSymbolContextSymbol);
129
130 if (sc.line_entry.line == 0) {
131 AddressRange range = sc.line_entry.range;
132 bool just_step_out = false;
133 if (sc.symbol) {
134 ProcessSP process_sp(current_plan->GetThread().GetProcess());
135
136 // If this is a runtime thunk, step through it, rather than stepping out
137 // because it's marked line 0.
138 bool is_thunk = false;
139 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
140 if (runtime->IsSymbolARuntimeThunk(*sc.symbol) &&
142 LLDB_LOGF(
143 log, "Stepping out past a language thunk %s for: %s",
144 frame->GetFunctionName(),
145 Language::GetNameForLanguageType(runtime->GetLanguageType()));
146 is_thunk = true;
147 break;
148 }
149 }
150
151 // If the whole function is marked line 0 just step out, that's easier &
152 // faster than continuing to step through it.
153 // FIXME: This assumes that the function is a single line range. It could
154 // be a series of contiguous line 0 ranges. Check for that too.
155 if (!is_thunk && sc.symbol->ValueIsAddress()) {
156 Address symbol_end = sc.symbol->GetAddress();
157 symbol_end.Slide(sc.symbol->GetByteSize() - 1);
158 if (range.ContainsFileAddress(sc.symbol->GetAddress()) &&
159 range.ContainsFileAddress(symbol_end)) {
160 LLDB_LOGF(log, "Stopped in a function with only line 0 lines, just "
161 "stepping out.");
162 just_step_out = true;
163 }
164 }
165 }
166 if (!just_step_out) {
167 LLDB_LOGF(log, "ThreadPlanShouldStopHere::DefaultStepFromHereCallback "
168 "Queueing StepInRange plan to step through line 0 code.");
169
170 return_plan_sp = current_plan->GetThread().QueueThreadPlanForStepInRange(
171 false, range, sc, nullptr, eOnlyDuringStepping, status,
173 }
174 }
175
176 if (!return_plan_sp)
177 return_plan_sp =
179 false, nullptr, true, stop_others, eVoteNo, eVoteNoOpinion,
180 frame_index, status, true);
181 return return_plan_sp;
182}
183
186 Status &status) {
187 ThreadPlanSP return_plan_sp;
188 if (m_callbacks.step_from_here_callback) {
189 return_plan_sp = m_callbacks.step_from_here_callback(
190 m_owner, flags, operation, status, m_baton);
191 }
192 return return_plan_sp;
193}
194
196 lldb::FrameComparison operation, Status &status) {
197 if (!InvokeShouldStopHereCallback(operation, status))
198 return QueueStepOutFromHerePlan(m_flags, operation, status);
199 else
200 return ThreadPlanSP();
201}
#define LLDB_LOGF(log,...)
Definition Log.h:376
A section + offset based address range class.
bool ContainsFileAddress(const Address &so_addr) const
Check if a section offset address is contained in this range.
A section + offset based address class.
Definition Address.h:62
bool Slide(int64_t offset)
Definition Address.h:452
A class to manage flags.
Definition Flags.h:22
bool Test(ValueType bit) const
Test a single flag bit.
Definition Flags.h:96
static const char * GetNameForLanguageType(lldb::LanguageType language)
Definition Language.cpp:266
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual const char * GetFunctionName()
Get the frame's demangled name.
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
An error handling class.
Definition Status.h:118
Defines a symbol context baton that can be handed other debug core functions.
Symbol * symbol
The Symbol for a given query.
LineEntry line_entry
The LineEntry for a given query.
bool ValueIsAddress() const
Definition Symbol.cpp:165
lldb::addr_t GetByteSize() const
Definition Symbol.cpp:431
Address GetAddress() const
Definition Symbol.h:89
virtual lldb::ThreadPlanSP QueueStepOutFromHerePlan(Flags &flags, lldb::FrameComparison operation, Status &status)
ThreadPlanShouldStopHereCallbacks m_callbacks
void SetShouldStopHereCallbacks(const ThreadPlanShouldStopHereCallbacks *callbacks, void *baton)
static bool DefaultShouldStopHereCallback(ThreadPlan *current_plan, Flags &flags, lldb::FrameComparison operation, Status &status, void *baton)
static lldb::ThreadPlanSP DefaultStepFromHereCallback(ThreadPlan *current_plan, Flags &flags, lldb::FrameComparison operation, Status &status, void *baton)
bool InvokeShouldStopHereCallback(lldb::FrameComparison operation, Status &status)
lldb::ThreadPlanSP CheckShouldStopHereAndQueueStepOut(lldb::FrameComparison operation, Status &status)
Thread & GetThread()
Returns the Thread that is using this thread plan.
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition Thread.h:431
lldb::ProcessSP GetProcess() const
Definition Thread.h:158
virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange(bool abort_other_plans, const AddressRange &range, const SymbolContext &addr_context, const char *step_in_target, lldb::RunMode stop_other_threads, Status &status, LazyBool step_in_avoids_code_without_debug_info=eLazyBoolCalculate, LazyBool step_out_avoids_code_without_debug_info=eLazyBoolCalculate)
Queues the plan used to step through an address range, stepping into functions.
Definition Thread.cpp:1312
virtual lldb::ThreadPlanSP QueueThreadPlanForStepOutNoShouldStop(bool abort_other_plans, SymbolContext *addr_context, bool first_insn, bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote, uint32_t frame_idx, Status &status, bool continue_to_next_branch=false)
Queue the plan used to step out of the function at the current PC of a thread.
Definition Thread.cpp:1355
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
FrameComparison
This is the return value for frame comparisons.
@ eFrameCompareSameParent
@ eFrameCompareYounger
std::shared_ptr< lldb_private::Process > ProcessSP
uint64_t addr_t
Definition lldb-types.h:80
@ eOnlyDuringStepping
AddressRange range
The section offset address range for this line entry.
Definition LineEntry.h:137
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition LineEntry.h:147