LLDB mainline
ThreadPlanStepThrough.cpp
Go to the documentation of this file.
1//===-- ThreadPlanStepThrough.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
13#include "lldb/Target/Process.h"
15#include "lldb/Target/Target.h"
17#include "lldb/Utility/Log.h"
18#include "lldb/Utility/Stream.h"
19
20using namespace lldb;
21using namespace lldb_private;
22
23// ThreadPlanStepThrough: If the current instruction is a trampoline, step
24// through it If it is the beginning of the prologue of a function, step
25// through that as well.
26
28 StackID &m_stack_id,
29 bool stop_others)
30 : ThreadPlan(ThreadPlan::eKindStepThrough,
31 "Step through trampolines and prologues", thread,
33 m_start_address(0), m_backstop_bkpt_id(LLDB_INVALID_BREAK_ID),
34 m_backstop_addr(LLDB_INVALID_ADDRESS), m_return_stack_id(m_stack_id),
35 m_stop_others(stop_others) {
37
38 // If we don't get a valid step through plan, don't bother to set up a
39 // backstop.
40 if (m_sub_plan_sp) {
42
43 // We are going to return back to the concrete frame 1, we might pass by
44 // some inlined code that we're in the middle of by doing this, but it's
45 // easier than trying to figure out where the inlined code might return to.
46
47 StackFrameSP return_frame_sp = thread.GetFrameWithStackID(m_stack_id);
48
49 if (return_frame_sp) {
50 m_backstop_addr = return_frame_sp->GetFrameCodeAddress().GetLoadAddress(
51 thread.CalculateTarget().get());
52 Breakpoint *return_bp =
55 .get();
56
57 if (return_bp != nullptr) {
58 if (return_bp->IsHardware() && !return_bp->HasResolvedLocations())
60 return_bp->SetThreadID(m_tid);
61 m_backstop_bkpt_id = return_bp->GetID();
62 return_bp->SetBreakpointKind("step-through-backstop");
63 }
64 Log *log = GetLog(LLDBLog::Step);
65 if (log) {
66 LLDB_LOGF(log, "Setting backstop breakpoint %d at address: 0x%" PRIx64,
68 }
69 }
70 }
71}
72
74
76 if (m_sub_plan_sp)
78}
79
81 Thread &thread = GetThread();
82 DynamicLoader *loader = thread.GetProcess()->GetDynamicLoader();
83 if (loader)
85
86 // If the DynamicLoader was unable to provide us with a ThreadPlan, then we
87 // try the LanguageRuntimes.
88 if (!m_sub_plan_sp) {
91 runtime->GetStepThroughTrampolinePlan(thread, m_stop_others);
92
93 if (m_sub_plan_sp)
94 break;
95 }
96 }
97
98 Log *log = GetLog(LLDBLog::Step);
99 if (log) {
100 lldb::addr_t current_address = GetThread().GetRegisterContext()->GetPC(0);
101 if (m_sub_plan_sp) {
102 StreamString s;
103 m_sub_plan_sp->GetDescription(&s, lldb::eDescriptionLevelFull);
104 LLDB_LOGF(log, "Found step through plan from 0x%" PRIx64 ": %s",
105 current_address, s.GetData());
106 } else {
107 LLDB_LOGF(log,
108 "Couldn't find step through plan from address 0x%" PRIx64 ".",
109 current_address);
110 }
111 }
112}
113
116 if (level == lldb::eDescriptionLevelBrief)
117 s->Printf("Step through");
118 else {
119 s->PutCString("Stepping through trampoline code from: ");
122 s->Printf(" with backstop breakpoint ID: %d at address: ",
125 } else
126 s->PutCString(" unable to set a backstop breakpoint.");
127 }
128}
129
132 if (error)
133 error->PutCString(
134 "Could not create hardware breakpoint for thread plan.");
135 return false;
136 }
137
139 if (error)
140 error->PutCString("Could not create backstop breakpoint.");
141 return false;
142 }
143
144 if (!m_sub_plan_sp.get()) {
145 if (error)
146 error->PutCString("Does not have a subplan.");
147 return false;
148 }
149
150 return true;
151}
152
154 // If we have a sub-plan, it will have been asked first if we explain the
155 // stop, and we won't get asked. The only time we would be the one directly
156 // asked this question is if we hit our backstop breakpoint.
157
159}
160
162 // If we've already marked ourselves done, then we're done...
163 if (IsPlanComplete())
164 return true;
165
166 // First, did we hit the backstop breakpoint?
168 SetPlanComplete(true);
169 return true;
170 }
171
172 // If we don't have a sub-plan, then we're also done (can't see how we would
173 // ever get here without a plan, but just in case.
174
175 if (!m_sub_plan_sp) {
177 return true;
178 }
179
180 // If the current sub plan is not done, we don't want to stop. Actually, we
181 // probably won't ever get here in this state, since we generally won't get
182 // asked any questions if out current sub-plan is not done...
183 if (!m_sub_plan_sp->IsPlanComplete())
184 return false;
185
186 // If our current sub plan failed, then let's just run to our backstop. If
187 // we can't do that then just stop.
188 if (!m_sub_plan_sp->PlanSucceeded()) {
190 m_sub_plan_sp.reset();
191 return false;
192 } else {
193 SetPlanComplete(false);
194 return true;
195 }
196 }
197
198 // Next see if there is a specific step through plan at our current pc (these
199 // might chain, for instance stepping through a dylib trampoline to the objc
200 // dispatch function...)
202 if (m_sub_plan_sp) {
204 return false;
205 } else {
207 return true;
208 }
209}
210
212
214
216 bool current_plan) {
217 return true;
218}
219
220bool ThreadPlanStepThrough::WillStop() { return true; }
221
227 }
228}
229
231 Log *log = GetLog(LLDBLog::Step);
232
233 if (!IsPlanComplete()) {
234 return false;
235 } else {
236 LLDB_LOGF(log, "Completed step through step plan.");
237
240 return true;
241 }
242}
243
245 Thread &thread = GetThread();
246 StopInfoSP stop_info_sp(thread.GetStopInfo());
247 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonBreakpoint) {
248 break_id_t stop_value = (break_id_t)stop_info_sp->GetValue();
249 BreakpointSiteSP cur_site_sp =
251 if (cur_site_sp &&
252 cur_site_sp->IsBreakpointAtThisSite(m_backstop_bkpt_id)) {
253 StackID cur_frame_zero_id = thread.GetStackFrameAtIndex(0)->GetStackID();
254
255 if (cur_frame_zero_id == m_return_stack_id) {
256 Log *log = GetLog(LLDBLog::Step);
257 if (log)
258 log->PutCString("ThreadPlanStepThrough hit backstop breakpoint.");
259 return true;
260 }
261 }
262 }
263 return false;
264}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:366
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition: Breakpoint.h:81
void SetBreakpointKind(const char *kind)
Set the "kind" description for a breakpoint.
Definition: Breakpoint.h:452
bool HasResolvedLocations() const
Return whether this breakpoint has any resolved locations.
Definition: Breakpoint.cpp:826
bool IsHardware() const
Definition: Breakpoint.h:520
void SetThreadID(lldb::tid_t thread_id)
Set the valid thread to be checked when the breakpoint is hit.
Definition: Breakpoint.cpp:336
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:53
virtual lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, bool stop_others)=0
Provides a plan to step through the dynamic loader trampoline for the current state of thread.
void PutCString(const char *cstr)
Definition: Log.cpp:135
StopPointSiteList< lldb_private::BreakpointSite > & GetBreakpointSiteList()
Definition: Process.cpp:1610
std::vector< LanguageRuntime * > GetLanguageRuntimes()
Definition: Process.cpp:1537
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1285
StopPointSiteSP FindByID(typename StopPointSite::SiteID site_id)
Returns a shared pointer to the site with id site_id.
lldb::break_id_t GetID() const
Definition: Stoppoint.cpp:22
const char * GetData() const
Definition: StreamString.h:45
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:401
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
bool RemoveBreakpointByID(lldb::break_id_t break_id)
Definition: Target.cpp:1005
lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, uint32_t column, lldb::addr_t offset, LazyBool check_inlines, LazyBool skip_prologue, bool internal, bool request_hardware, LazyBool move_to_nearest_code)
Definition: Target.cpp:396
lldb::StateType GetPlanRunState() override
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override
bool DoPlanExplainsStop(Event *event_ptr) override
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
ThreadPlanStepThrough(Thread &thread, StackID &return_stack_id, bool stop_others)
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
bool ShouldStop(Event *event_ptr) override
void PushPlan(lldb::ThreadPlanSP &thread_plan_sp)
Definition: ThreadPlan.h:510
void SetPlanComplete(bool success=true)
Definition: ThreadPlan.cpp:66
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:42
virtual bool MischiefManaged()
Definition: ThreadPlan.cpp:72
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:408
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb::TargetSP CalculateTarget() override
Definition: Thread.cpp:1401
lldb::ProcessSP GetProcess() const
Definition: Thread.h:157
virtual lldb::StackFrameSP GetFrameWithStackID(const StackID &stack_id)
Definition: Thread.h:434
lldb::StopInfoSP GetStopInfo()
Definition: Thread.cpp:347
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
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:331
void DumpAddress(llvm::raw_ostream &s, uint64_t addr, uint32_t addr_size, const char *prefix=nullptr, const char *suffix=nullptr)
Output an address value to this stream.
Definition: Stream.cpp:108
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:420
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
Definition: lldb-forward.h:321
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelBrief
@ eDescriptionLevelFull
StateType
Process and Thread States.
@ eStateRunning
Process or thread is running and can't be examined.
int32_t break_id_t
Definition: lldb-types.h:86
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
Definition: lldb-forward.h:427
uint64_t addr_t
Definition: lldb-types.h:80
@ eStopReasonBreakpoint