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 (const Symbol *symbol =
85 frame->GetSymbolContext(eSymbolContextSymbol).symbol) {
86 ProcessSP process_sp(current_plan->GetThread().GetProcess());
87 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
88 if (runtime->IsSymbolARuntimeThunk(*symbol) &&
91 log, "Stepping out past a language thunk %s for: %s",
92 frame->GetFunctionName(),
93 Language::GetNameForLanguageType(runtime->GetLanguageType()));
94 should_stop_here = false;
95 break;
96 }
97 }
98 }
99 }
100 // Always avoid code with line number 0.
101 // FIXME: At present the ShouldStop and the StepFromHere calculate this
102 // independently. If this ever
103 // becomes expensive (this one isn't) we can try to have this set a state
104 // that the StepFromHere can use.
105 if (frame) {
106 SymbolContext sc;
107 sc = frame->GetSymbolContext(eSymbolContextLineEntry);
108 if (sc.line_entry.line == 0)
109 should_stop_here = false;
110 }
111
112 return should_stop_here;
113}
114
116 ThreadPlan *current_plan, Flags &flags, FrameComparison operation,
117 Status &status, void *baton) {
118 const bool stop_others = false;
119 const size_t frame_index = 0;
120 ThreadPlanSP return_plan_sp;
121 // If we are stepping through code at line number 0, then we need to step
122 // over this range. Otherwise we will step out.
123 Log *log = GetLog(LLDBLog::Step);
124
125 StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
126 if (!frame)
127 return return_plan_sp;
128 SymbolContext sc;
129 sc = frame->GetSymbolContext(eSymbolContextLineEntry | eSymbolContextSymbol);
130
131 if (sc.line_entry.line == 0) {
132 AddressRange range = sc.line_entry.range;
133 bool just_step_out = false;
134 if (sc.symbol) {
135 ProcessSP process_sp(current_plan->GetThread().GetProcess());
136
137 // If this is a runtime thunk, step through it, rather than stepping out
138 // because it's marked line 0.
139 bool is_thunk = false;
140 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
141 if (runtime->IsSymbolARuntimeThunk(*sc.symbol) &&
143 LLDB_LOGF(
144 log, "Stepping out past a language thunk %s for: %s",
145 frame->GetFunctionName(),
146 Language::GetNameForLanguageType(runtime->GetLanguageType()));
147 is_thunk = true;
148 break;
149 }
150 }
151
152 // If the whole function is marked line 0 just step out, that's easier &
153 // faster than continuing to step through it.
154 // FIXME: This assumes that the function is a single line range. It could
155 // be a series of contiguous line 0 ranges. Check for that too.
156 if (!is_thunk && sc.symbol->ValueIsAddress()) {
157 Address symbol_end = sc.symbol->GetAddress();
158 symbol_end.Slide(sc.symbol->GetByteSize() - 1);
159 if (range.ContainsFileAddress(sc.symbol->GetAddress()) &&
160 range.ContainsFileAddress(symbol_end)) {
161 LLDB_LOGF(log, "Stopped in a function with only line 0 lines, just "
162 "stepping out.");
163 just_step_out = true;
164 }
165 }
166 }
167 if (!just_step_out) {
168 LLDB_LOGF(log, "ThreadPlanShouldStopHere::DefaultStepFromHereCallback "
169 "Queueing StepInRange plan to step through line 0 code.");
170
171 return_plan_sp = current_plan->GetThread().QueueThreadPlanForStepInRange(
172 false, range, sc, nullptr, eOnlyDuringStepping, status,
174 }
175 }
176
177 if (!return_plan_sp)
178 return_plan_sp =
180 false, nullptr, true, stop_others, eVoteNo, eVoteNoOpinion,
181 frame_index, status, true);
182 return return_plan_sp;
183}
184
187 Status &status) {
188 ThreadPlanSP return_plan_sp;
189 if (m_callbacks.step_from_here_callback) {
190 return_plan_sp = m_callbacks.step_from_here_callback(
191 m_owner, flags, operation, status, m_baton);
192 }
193 return return_plan_sp;
194}
195
197 lldb::FrameComparison operation, Status &status) {
198 if (!InvokeShouldStopHereCallback(operation, status))
199 return QueueStepOutFromHerePlan(m_flags, operation, status);
200 else
201 return ThreadPlanSP();
202}
#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)
Returns the internal LLDB name for the specified language.
Definition Language.cpp:309
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual const char * GetFunctionName()
Get the frame's demangled name.
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual 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:1327
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:1370
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:151