1ac7ddfbfSEd Maste //===-- ThreadPlanStepInRange.cpp -------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
109f2f44ceSEd Maste #include "lldb/Target/ThreadPlanStepInRange.h"
114ba319b5SDimitry Andric #include "lldb/Core/Architecture.h"
1212b93ac6SEd Maste #include "lldb/Core/Module.h"
13ac7ddfbfSEd Maste #include "lldb/Symbol/Function.h"
14435933ddSDimitry Andric #include "lldb/Symbol/Symbol.h"
15ac7ddfbfSEd Maste #include "lldb/Target/Process.h"
16ac7ddfbfSEd Maste #include "lldb/Target/RegisterContext.h"
174ba319b5SDimitry Andric #include "lldb/Target/SectionLoadList.h"
18ac7ddfbfSEd Maste #include "lldb/Target/Target.h"
19ac7ddfbfSEd Maste #include "lldb/Target/Thread.h"
20ac7ddfbfSEd Maste #include "lldb/Target/ThreadPlanStepOut.h"
21ac7ddfbfSEd Maste #include "lldb/Target/ThreadPlanStepThrough.h"
22f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
23f678e45dSDimitry Andric #include "lldb/Utility/RegularExpression.h"
24f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
25ac7ddfbfSEd Maste
26ac7ddfbfSEd Maste using namespace lldb;
27ac7ddfbfSEd Maste using namespace lldb_private;
28ac7ddfbfSEd Maste
29435933ddSDimitry Andric uint32_t ThreadPlanStepInRange::s_default_flag_values =
30435933ddSDimitry Andric ThreadPlanShouldStopHere::eStepInAvoidNoDebug;
31ac7ddfbfSEd Maste
32ac7ddfbfSEd Maste //----------------------------------------------------------------------
33435933ddSDimitry Andric // ThreadPlanStepInRange: Step through a stack range, either stepping over or
344ba319b5SDimitry Andric // into based on the value of \a type.
35ac7ddfbfSEd Maste //----------------------------------------------------------------------
36ac7ddfbfSEd Maste
ThreadPlanStepInRange(Thread & thread,const AddressRange & range,const SymbolContext & addr_context,lldb::RunMode stop_others,LazyBool step_in_avoids_code_without_debug_info,LazyBool step_out_avoids_code_without_debug_info)37435933ddSDimitry Andric ThreadPlanStepInRange::ThreadPlanStepInRange(
38435933ddSDimitry Andric Thread &thread, const AddressRange &range,
39435933ddSDimitry Andric const SymbolContext &addr_context, lldb::RunMode stop_others,
400127ef0fSEd Maste LazyBool step_in_avoids_code_without_debug_info,
41435933ddSDimitry Andric LazyBool step_out_avoids_code_without_debug_info)
42435933ddSDimitry Andric : ThreadPlanStepRange(ThreadPlan::eKindStepInRange,
43435933ddSDimitry Andric "Step Range stepping in", thread, range, addr_context,
44435933ddSDimitry Andric stop_others),
45435933ddSDimitry Andric ThreadPlanShouldStopHere(this), m_step_past_prologue(true),
46435933ddSDimitry Andric m_virtual_step(false) {
470127ef0fSEd Maste SetCallbacks();
48ac7ddfbfSEd Maste SetFlagsToDefault();
49435933ddSDimitry Andric SetupAvoidNoDebug(step_in_avoids_code_without_debug_info,
50435933ddSDimitry Andric step_out_avoids_code_without_debug_info);
51ac7ddfbfSEd Maste }
52ac7ddfbfSEd Maste
ThreadPlanStepInRange(Thread & thread,const AddressRange & range,const SymbolContext & addr_context,const char * step_into_target,lldb::RunMode stop_others,LazyBool step_in_avoids_code_without_debug_info,LazyBool step_out_avoids_code_without_debug_info)53435933ddSDimitry Andric ThreadPlanStepInRange::ThreadPlanStepInRange(
54435933ddSDimitry Andric Thread &thread, const AddressRange &range,
55435933ddSDimitry Andric const SymbolContext &addr_context, const char *step_into_target,
56435933ddSDimitry Andric lldb::RunMode stop_others, LazyBool step_in_avoids_code_without_debug_info,
57435933ddSDimitry Andric LazyBool step_out_avoids_code_without_debug_info)
58435933ddSDimitry Andric : ThreadPlanStepRange(ThreadPlan::eKindStepInRange,
59435933ddSDimitry Andric "Step Range stepping in", thread, range, addr_context,
60435933ddSDimitry Andric stop_others),
61435933ddSDimitry Andric ThreadPlanShouldStopHere(this), m_step_past_prologue(true),
62435933ddSDimitry Andric m_virtual_step(false), m_step_into_target(step_into_target) {
630127ef0fSEd Maste SetCallbacks();
64ac7ddfbfSEd Maste SetFlagsToDefault();
65435933ddSDimitry Andric SetupAvoidNoDebug(step_in_avoids_code_without_debug_info,
66435933ddSDimitry Andric step_out_avoids_code_without_debug_info);
67ac7ddfbfSEd Maste }
68ac7ddfbfSEd Maste
699f2f44ceSEd Maste ThreadPlanStepInRange::~ThreadPlanStepInRange() = default;
70ac7ddfbfSEd Maste
SetupAvoidNoDebug(LazyBool step_in_avoids_code_without_debug_info,LazyBool step_out_avoids_code_without_debug_info)71435933ddSDimitry Andric void ThreadPlanStepInRange::SetupAvoidNoDebug(
72435933ddSDimitry Andric LazyBool step_in_avoids_code_without_debug_info,
73435933ddSDimitry Andric LazyBool step_out_avoids_code_without_debug_info) {
740127ef0fSEd Maste bool avoid_nodebug = true;
750127ef0fSEd Maste
76435933ddSDimitry Andric switch (step_in_avoids_code_without_debug_info) {
770127ef0fSEd Maste case eLazyBoolYes:
780127ef0fSEd Maste avoid_nodebug = true;
790127ef0fSEd Maste break;
800127ef0fSEd Maste case eLazyBoolNo:
810127ef0fSEd Maste avoid_nodebug = false;
820127ef0fSEd Maste break;
830127ef0fSEd Maste case eLazyBoolCalculate:
840127ef0fSEd Maste avoid_nodebug = m_thread.GetStepInAvoidsNoDebug();
850127ef0fSEd Maste break;
860127ef0fSEd Maste }
870127ef0fSEd Maste if (avoid_nodebug)
880127ef0fSEd Maste GetFlags().Set(ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
890127ef0fSEd Maste else
900127ef0fSEd Maste GetFlags().Clear(ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
910127ef0fSEd Maste
92435933ddSDimitry Andric switch (step_out_avoids_code_without_debug_info) {
930127ef0fSEd Maste case eLazyBoolYes:
940127ef0fSEd Maste avoid_nodebug = true;
950127ef0fSEd Maste break;
960127ef0fSEd Maste case eLazyBoolNo:
970127ef0fSEd Maste avoid_nodebug = false;
980127ef0fSEd Maste break;
990127ef0fSEd Maste case eLazyBoolCalculate:
1000127ef0fSEd Maste avoid_nodebug = m_thread.GetStepOutAvoidsNoDebug();
1010127ef0fSEd Maste break;
1020127ef0fSEd Maste }
1030127ef0fSEd Maste if (avoid_nodebug)
1040127ef0fSEd Maste GetFlags().Set(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
1050127ef0fSEd Maste else
1060127ef0fSEd Maste GetFlags().Clear(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
1070127ef0fSEd Maste }
1080127ef0fSEd Maste
GetDescription(Stream * s,lldb::DescriptionLevel level)109435933ddSDimitry Andric void ThreadPlanStepInRange::GetDescription(Stream *s,
110435933ddSDimitry Andric lldb::DescriptionLevel level) {
111*b5893f02SDimitry Andric
112*b5893f02SDimitry Andric auto PrintFailureIfAny = [&]() {
113*b5893f02SDimitry Andric if (m_status.Success())
114*b5893f02SDimitry Andric return;
115*b5893f02SDimitry Andric s->Printf(" failed (%s)", m_status.AsCString());
116*b5893f02SDimitry Andric };
117*b5893f02SDimitry Andric
118435933ddSDimitry Andric if (level == lldb::eDescriptionLevelBrief) {
1197aa51b79SEd Maste s->Printf("step in");
120*b5893f02SDimitry Andric PrintFailureIfAny();
1217aa51b79SEd Maste return;
1227aa51b79SEd Maste }
1237aa51b79SEd Maste
1247aa51b79SEd Maste s->Printf("Stepping in");
1257aa51b79SEd Maste bool printed_line_info = false;
126435933ddSDimitry Andric if (m_addr_context.line_entry.IsValid()) {
1277aa51b79SEd Maste s->Printf(" through line ");
1287aa51b79SEd Maste m_addr_context.line_entry.DumpStopContext(s, false);
1297aa51b79SEd Maste printed_line_info = true;
1307aa51b79SEd Maste }
1317aa51b79SEd Maste
132ac7ddfbfSEd Maste const char *step_into_target = m_step_into_target.AsCString();
133ac7ddfbfSEd Maste if (step_into_target && step_into_target[0] != '\0')
1347aa51b79SEd Maste s->Printf(" targeting %s", m_step_into_target.AsCString());
1357aa51b79SEd Maste
136435933ddSDimitry Andric if (!printed_line_info || level == eDescriptionLevelVerbose) {
1377aa51b79SEd Maste s->Printf(" using ranges:");
1387aa51b79SEd Maste DumpRanges(s);
139ac7ddfbfSEd Maste }
1407aa51b79SEd Maste
141*b5893f02SDimitry Andric PrintFailureIfAny();
142*b5893f02SDimitry Andric
1437aa51b79SEd Maste s->PutChar('.');
144ac7ddfbfSEd Maste }
145ac7ddfbfSEd Maste
ShouldStop(Event * event_ptr)146435933ddSDimitry Andric bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) {
147ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
148ac7ddfbfSEd Maste
149435933ddSDimitry Andric if (log) {
150ac7ddfbfSEd Maste StreamString s;
151435933ddSDimitry Andric s.Address(
152435933ddSDimitry Andric m_thread.GetRegisterContext()->GetPC(),
153ac7ddfbfSEd Maste m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
154ac7ddfbfSEd Maste log->Printf("ThreadPlanStepInRange reached %s.", s.GetData());
155ac7ddfbfSEd Maste }
156ac7ddfbfSEd Maste
157ac7ddfbfSEd Maste if (IsPlanComplete())
158ac7ddfbfSEd Maste return true;
159ac7ddfbfSEd Maste
160ac7ddfbfSEd Maste m_no_more_plans = false;
161435933ddSDimitry Andric if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete()) {
162435933ddSDimitry Andric if (!m_sub_plan_sp->PlanSucceeded()) {
163ac7ddfbfSEd Maste SetPlanComplete();
164ac7ddfbfSEd Maste m_no_more_plans = true;
165ac7ddfbfSEd Maste return true;
166435933ddSDimitry Andric } else
167ac7ddfbfSEd Maste m_sub_plan_sp.reset();
168ac7ddfbfSEd Maste }
169ac7ddfbfSEd Maste
170435933ddSDimitry Andric if (m_virtual_step) {
171435933ddSDimitry Andric // If we've just completed a virtual step, all we need to do is check for a
1724ba319b5SDimitry Andric // ShouldStopHere plan, and otherwise we're done.
173435933ddSDimitry Andric // FIXME - This can be both a step in and a step out. Probably should
174435933ddSDimitry Andric // record which in the m_virtual_step.
175*b5893f02SDimitry Andric m_sub_plan_sp =
176*b5893f02SDimitry Andric CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger, m_status);
177435933ddSDimitry Andric } else {
178435933ddSDimitry Andric // Stepping through should be done running other threads in general, since
1794ba319b5SDimitry Andric // we're setting a breakpoint and continuing. So only stop others if we
1804ba319b5SDimitry Andric // are explicitly told to do so.
181ac7ddfbfSEd Maste
1829f2f44ceSEd Maste bool stop_others = (m_stop_others == lldb::eOnlyThisThread);
183ac7ddfbfSEd Maste
184ac7ddfbfSEd Maste FrameComparison frame_order = CompareCurrentFrameToStartFrame();
185ac7ddfbfSEd Maste
186435933ddSDimitry Andric if (frame_order == eFrameCompareOlder ||
187435933ddSDimitry Andric frame_order == eFrameCompareSameParent) {
188ac7ddfbfSEd Maste // If we're in an older frame then we should stop.
189ac7ddfbfSEd Maste //
190435933ddSDimitry Andric // A caveat to this is if we think the frame is older but we're actually
191435933ddSDimitry Andric // in a trampoline.
192435933ddSDimitry Andric // I'm going to make the assumption that you wouldn't RETURN to a
1934ba319b5SDimitry Andric // trampoline. So if we are in a trampoline we think the frame is older
1944ba319b5SDimitry Andric // because the trampoline confused the backtracer.
195*b5893f02SDimitry Andric m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough(
196*b5893f02SDimitry Andric m_stack_id, false, stop_others, m_status);
197435933ddSDimitry Andric if (!m_sub_plan_sp) {
1980127ef0fSEd Maste // Otherwise check the ShouldStopHere for step out:
199*b5893f02SDimitry Andric m_sub_plan_sp =
200*b5893f02SDimitry Andric CheckShouldStopHereAndQueueStepOut(frame_order, m_status);
201acac075bSDimitry Andric if (log) {
202acac075bSDimitry Andric if (m_sub_plan_sp)
203acac075bSDimitry Andric log->Printf("ShouldStopHere found plan to step out of this frame.");
204acac075bSDimitry Andric else
205acac075bSDimitry Andric log->Printf("ShouldStopHere no plan to step out of this frame.");
206acac075bSDimitry Andric }
207435933ddSDimitry Andric } else if (log) {
208435933ddSDimitry Andric log->Printf(
209435933ddSDimitry Andric "Thought I stepped out, but in fact arrived at a trampoline.");
2100127ef0fSEd Maste }
211435933ddSDimitry Andric } else if (frame_order == eFrameCompareEqual && InSymbol()) {
2124ba319b5SDimitry Andric // If we are not in a place we should step through, we're done. One
2134ba319b5SDimitry Andric // tricky bit here is that some stubs don't push a frame, so we have to
2144ba319b5SDimitry Andric // check both the case of a frame that is younger, or the same as this
2154ba319b5SDimitry Andric // frame. However, if the frame is the same, and we are still in the
2164ba319b5SDimitry Andric // symbol we started in, the we don't need to do this. This first check
2174ba319b5SDimitry Andric // isn't strictly necessary, but it is more efficient.
218ac7ddfbfSEd Maste
219435933ddSDimitry Andric // If we're still in the range, keep going, either by running to the next
2204ba319b5SDimitry Andric // branch breakpoint, or by stepping.
221435933ddSDimitry Andric if (InRange()) {
222ac7ddfbfSEd Maste SetNextBranchBreakpoint();
223ac7ddfbfSEd Maste return false;
224ac7ddfbfSEd Maste }
225ac7ddfbfSEd Maste
226ac7ddfbfSEd Maste SetPlanComplete();
227ac7ddfbfSEd Maste m_no_more_plans = true;
228ac7ddfbfSEd Maste return true;
229ac7ddfbfSEd Maste }
230ac7ddfbfSEd Maste
231435933ddSDimitry Andric // If we get to this point, we're not going to use a previously set "next
232435933ddSDimitry Andric // branch" breakpoint, so delete it:
233ac7ddfbfSEd Maste ClearNextBranchBreakpoint();
234ac7ddfbfSEd Maste
235ac7ddfbfSEd Maste // We may have set the plan up above in the FrameIsOlder section:
236ac7ddfbfSEd Maste
237ac7ddfbfSEd Maste if (!m_sub_plan_sp)
238*b5893f02SDimitry Andric m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough(
239*b5893f02SDimitry Andric m_stack_id, false, stop_others, m_status);
240ac7ddfbfSEd Maste
241435933ddSDimitry Andric if (log) {
242ac7ddfbfSEd Maste if (m_sub_plan_sp)
243ac7ddfbfSEd Maste log->Printf("Found a step through plan: %s", m_sub_plan_sp->GetName());
244ac7ddfbfSEd Maste else
245ac7ddfbfSEd Maste log->Printf("No step through plan found.");
246ac7ddfbfSEd Maste }
247ac7ddfbfSEd Maste
2484ba319b5SDimitry Andric // If not, give the "should_stop" callback a chance to push a plan to get
2494ba319b5SDimitry Andric // us out of here. But only do that if we actually have stepped in.
250ac7ddfbfSEd Maste if (!m_sub_plan_sp && frame_order == eFrameCompareYounger)
251*b5893f02SDimitry Andric m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order, m_status);
252ac7ddfbfSEd Maste
253435933ddSDimitry Andric // If we've stepped in and we are going to stop here, check to see if we
2544ba319b5SDimitry Andric // were asked to run past the prologue, and if so do that.
255ac7ddfbfSEd Maste
256435933ddSDimitry Andric if (!m_sub_plan_sp && frame_order == eFrameCompareYounger &&
257435933ddSDimitry Andric m_step_past_prologue) {
258ac7ddfbfSEd Maste lldb::StackFrameSP curr_frame = m_thread.GetStackFrameAtIndex(0);
259435933ddSDimitry Andric if (curr_frame) {
260ac7ddfbfSEd Maste size_t bytes_to_skip = 0;
261ac7ddfbfSEd Maste lldb::addr_t curr_addr = m_thread.GetRegisterContext()->GetPC();
262ac7ddfbfSEd Maste Address func_start_address;
263ac7ddfbfSEd Maste
264435933ddSDimitry Andric SymbolContext sc = curr_frame->GetSymbolContext(eSymbolContextFunction |
265435933ddSDimitry Andric eSymbolContextSymbol);
266ac7ddfbfSEd Maste
267435933ddSDimitry Andric if (sc.function) {
268ac7ddfbfSEd Maste func_start_address = sc.function->GetAddressRange().GetBaseAddress();
269435933ddSDimitry Andric if (curr_addr ==
270435933ddSDimitry Andric func_start_address.GetLoadAddress(
271435933ddSDimitry Andric m_thread.CalculateTarget().get()))
272ac7ddfbfSEd Maste bytes_to_skip = sc.function->GetPrologueByteSize();
273435933ddSDimitry Andric } else if (sc.symbol) {
274ac7ddfbfSEd Maste func_start_address = sc.symbol->GetAddress();
275435933ddSDimitry Andric if (curr_addr ==
276435933ddSDimitry Andric func_start_address.GetLoadAddress(
277435933ddSDimitry Andric m_thread.CalculateTarget().get()))
278ac7ddfbfSEd Maste bytes_to_skip = sc.symbol->GetPrologueByteSize();
279ac7ddfbfSEd Maste }
280ac7ddfbfSEd Maste
2814ba319b5SDimitry Andric if (bytes_to_skip == 0 && sc.symbol) {
2824ba319b5SDimitry Andric TargetSP target = m_thread.CalculateTarget();
2834ba319b5SDimitry Andric const Architecture *arch = target->GetArchitecturePlugin();
2844ba319b5SDimitry Andric if (arch) {
2854ba319b5SDimitry Andric Address curr_sec_addr;
2864ba319b5SDimitry Andric target->GetSectionLoadList().ResolveLoadAddress(curr_addr,
2874ba319b5SDimitry Andric curr_sec_addr);
2884ba319b5SDimitry Andric bytes_to_skip = arch->GetBytesToSkip(*sc.symbol, curr_sec_addr);
2894ba319b5SDimitry Andric }
2904ba319b5SDimitry Andric }
2914ba319b5SDimitry Andric
292435933ddSDimitry Andric if (bytes_to_skip != 0) {
293ac7ddfbfSEd Maste func_start_address.Slide(bytes_to_skip);
294ac7ddfbfSEd Maste log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP);
295ac7ddfbfSEd Maste if (log)
296ac7ddfbfSEd Maste log->Printf("Pushing past prologue ");
297ac7ddfbfSEd Maste
298435933ddSDimitry Andric m_sub_plan_sp = m_thread.QueueThreadPlanForRunToAddress(
299*b5893f02SDimitry Andric false, func_start_address, true, m_status);
300ac7ddfbfSEd Maste }
301ac7ddfbfSEd Maste }
302ac7ddfbfSEd Maste }
303ac7ddfbfSEd Maste }
304ac7ddfbfSEd Maste
305435933ddSDimitry Andric if (!m_sub_plan_sp) {
306ac7ddfbfSEd Maste m_no_more_plans = true;
307ac7ddfbfSEd Maste SetPlanComplete();
308ac7ddfbfSEd Maste return true;
309435933ddSDimitry Andric } else {
310ac7ddfbfSEd Maste m_no_more_plans = false;
3117aa51b79SEd Maste m_sub_plan_sp->SetPrivate(true);
312ac7ddfbfSEd Maste return false;
313ac7ddfbfSEd Maste }
314ac7ddfbfSEd Maste }
315ac7ddfbfSEd Maste
SetAvoidRegexp(const char * name)316435933ddSDimitry Andric void ThreadPlanStepInRange::SetAvoidRegexp(const char *name) {
317435933ddSDimitry Andric auto name_ref = llvm::StringRef::withNullAsEmpty(name);
3189f2f44ceSEd Maste if (!m_avoid_regexp_ap)
319435933ddSDimitry Andric m_avoid_regexp_ap.reset(new RegularExpression(name_ref));
320ac7ddfbfSEd Maste
321435933ddSDimitry Andric m_avoid_regexp_ap->Compile(name_ref);
322ac7ddfbfSEd Maste }
323ac7ddfbfSEd Maste
SetDefaultFlagValue(uint32_t new_value)324435933ddSDimitry Andric void ThreadPlanStepInRange::SetDefaultFlagValue(uint32_t new_value) {
325ac7ddfbfSEd Maste // TODO: Should we test this for sanity?
326ac7ddfbfSEd Maste ThreadPlanStepInRange::s_default_flag_values = new_value;
327ac7ddfbfSEd Maste }
328ac7ddfbfSEd Maste
FrameMatchesAvoidCriteria()329435933ddSDimitry Andric bool ThreadPlanStepInRange::FrameMatchesAvoidCriteria() {
330ac7ddfbfSEd Maste StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
331ac7ddfbfSEd Maste
33212b93ac6SEd Maste // Check the library list first, as that's cheapest:
33312b93ac6SEd Maste bool libraries_say_avoid = false;
33412b93ac6SEd Maste
33512b93ac6SEd Maste FileSpecList libraries_to_avoid(GetThread().GetLibrariesToAvoid());
33612b93ac6SEd Maste size_t num_libraries = libraries_to_avoid.GetSize();
337435933ddSDimitry Andric if (num_libraries > 0) {
33812b93ac6SEd Maste SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
33912b93ac6SEd Maste FileSpec frame_library(sc.module_sp->GetFileSpec());
34012b93ac6SEd Maste
341435933ddSDimitry Andric if (frame_library) {
342435933ddSDimitry Andric for (size_t i = 0; i < num_libraries; i++) {
34312b93ac6SEd Maste const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
344435933ddSDimitry Andric if (FileSpec::Equal(file_spec, frame_library, false)) {
34512b93ac6SEd Maste libraries_say_avoid = true;
34612b93ac6SEd Maste break;
34712b93ac6SEd Maste }
34812b93ac6SEd Maste }
34912b93ac6SEd Maste }
35012b93ac6SEd Maste }
35112b93ac6SEd Maste if (libraries_say_avoid)
35212b93ac6SEd Maste return true;
35312b93ac6SEd Maste
354ac7ddfbfSEd Maste const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get();
3559f2f44ceSEd Maste if (avoid_regexp_to_use == nullptr)
356ac7ddfbfSEd Maste avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
357ac7ddfbfSEd Maste
358435933ddSDimitry Andric if (avoid_regexp_to_use != nullptr) {
359435933ddSDimitry Andric SymbolContext sc = frame->GetSymbolContext(
360435933ddSDimitry Andric eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
361435933ddSDimitry Andric if (sc.symbol != nullptr) {
362435933ddSDimitry Andric const char *frame_function_name =
363435933ddSDimitry Andric sc.GetFunctionName(Mangled::ePreferDemangledWithoutArguments)
364435933ddSDimitry Andric .GetCString();
365435933ddSDimitry Andric if (frame_function_name) {
366ac7ddfbfSEd Maste size_t num_matches = 0;
367ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
368ac7ddfbfSEd Maste if (log)
369ac7ddfbfSEd Maste num_matches = 1;
370ac7ddfbfSEd Maste
371ac7ddfbfSEd Maste RegularExpression::Match regex_match(num_matches);
372ac7ddfbfSEd Maste
373435933ddSDimitry Andric bool return_value =
374435933ddSDimitry Andric avoid_regexp_to_use->Execute(frame_function_name, ®ex_match);
375435933ddSDimitry Andric if (return_value) {
376435933ddSDimitry Andric if (log) {
377ac7ddfbfSEd Maste std::string match;
378ac7ddfbfSEd Maste regex_match.GetMatchAtIndex(frame_function_name, 0, match);
379435933ddSDimitry Andric log->Printf("Stepping out of function \"%s\" because it matches "
380435933ddSDimitry Andric "the avoid regexp \"%s\" - match substring: \"%s\".",
381ac7ddfbfSEd Maste frame_function_name,
382435933ddSDimitry Andric avoid_regexp_to_use->GetText().str().c_str(),
383ac7ddfbfSEd Maste match.c_str());
384ac7ddfbfSEd Maste }
385ac7ddfbfSEd Maste }
386ac7ddfbfSEd Maste return return_value;
387ac7ddfbfSEd Maste }
388ac7ddfbfSEd Maste }
389ac7ddfbfSEd Maste }
390ac7ddfbfSEd Maste return false;
391ac7ddfbfSEd Maste }
392ac7ddfbfSEd Maste
DefaultShouldStopHereCallback(ThreadPlan * current_plan,Flags & flags,FrameComparison operation,Status & status,void * baton)393435933ddSDimitry Andric bool ThreadPlanStepInRange::DefaultShouldStopHereCallback(
394435933ddSDimitry Andric ThreadPlan *current_plan, Flags &flags, FrameComparison operation,
395*b5893f02SDimitry Andric Status &status, void *baton) {
3960127ef0fSEd Maste bool should_stop_here = true;
397ac7ddfbfSEd Maste StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
398ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
399ac7ddfbfSEd Maste
400435933ddSDimitry Andric // First see if the ThreadPlanShouldStopHere default implementation thinks we
401435933ddSDimitry Andric // should get out of here:
402435933ddSDimitry Andric should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback(
403*b5893f02SDimitry Andric current_plan, flags, operation, status, baton);
4040127ef0fSEd Maste if (!should_stop_here)
4050127ef0fSEd Maste return should_stop_here;
406ac7ddfbfSEd Maste
407435933ddSDimitry Andric if (should_stop_here && current_plan->GetKind() == eKindStepInRange &&
408435933ddSDimitry Andric operation == eFrameCompareYounger) {
409435933ddSDimitry Andric ThreadPlanStepInRange *step_in_range_plan =
410435933ddSDimitry Andric static_cast<ThreadPlanStepInRange *>(current_plan);
411435933ddSDimitry Andric if (step_in_range_plan->m_step_into_target) {
412435933ddSDimitry Andric SymbolContext sc = frame->GetSymbolContext(
413435933ddSDimitry Andric eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
414435933ddSDimitry Andric if (sc.symbol != nullptr) {
4154ba319b5SDimitry Andric // First try an exact match, since that's cheap with ConstStrings.
4164ba319b5SDimitry Andric // Then do a strstr compare.
417435933ddSDimitry Andric if (step_in_range_plan->m_step_into_target == sc.GetFunctionName()) {
4180127ef0fSEd Maste should_stop_here = true;
419435933ddSDimitry Andric } else {
420435933ddSDimitry Andric const char *target_name =
421435933ddSDimitry Andric step_in_range_plan->m_step_into_target.AsCString();
422ac7ddfbfSEd Maste const char *function_name = sc.GetFunctionName().AsCString();
423ac7ddfbfSEd Maste
4249f2f44ceSEd Maste if (function_name == nullptr)
4250127ef0fSEd Maste should_stop_here = false;
4269f2f44ceSEd Maste else if (strstr(function_name, target_name) == nullptr)
4270127ef0fSEd Maste should_stop_here = false;
428ac7ddfbfSEd Maste }
4290127ef0fSEd Maste if (log && !should_stop_here)
430435933ddSDimitry Andric log->Printf("Stepping out of frame %s which did not match step into "
431435933ddSDimitry Andric "target %s.",
432ac7ddfbfSEd Maste sc.GetFunctionName().AsCString(),
433ac7ddfbfSEd Maste step_in_range_plan->m_step_into_target.AsCString());
434ac7ddfbfSEd Maste }
435ac7ddfbfSEd Maste }
436ac7ddfbfSEd Maste
437435933ddSDimitry Andric if (should_stop_here) {
438435933ddSDimitry Andric ThreadPlanStepInRange *step_in_range_plan =
439435933ddSDimitry Andric static_cast<ThreadPlanStepInRange *>(current_plan);
440435933ddSDimitry Andric // Don't log the should_step_out here, it's easier to do it in
441435933ddSDimitry Andric // FrameMatchesAvoidCriteria.
4420127ef0fSEd Maste should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria();
443ac7ddfbfSEd Maste }
444ac7ddfbfSEd Maste }
445ac7ddfbfSEd Maste
4460127ef0fSEd Maste return should_stop_here;
447ac7ddfbfSEd Maste }
448ac7ddfbfSEd Maste
DoPlanExplainsStop(Event * event_ptr)449435933ddSDimitry Andric bool ThreadPlanStepInRange::DoPlanExplainsStop(Event *event_ptr) {
450ac7ddfbfSEd Maste // We always explain a stop. Either we've just done a single step, in which
4514ba319b5SDimitry Andric // case we'll do our ordinary processing, or we stopped for some reason that
4524ba319b5SDimitry Andric // isn't handled by our sub-plans, in which case we want to just stop right
4534ba319b5SDimitry Andric // away. In general, we don't want to mark the plan as complete for
4544ba319b5SDimitry Andric // unexplained stops. For instance, if you step in to some code with no debug
4554ba319b5SDimitry Andric // info, so you step out and in the course of that hit a breakpoint, then you
4564ba319b5SDimitry Andric // want to stop & show the user the breakpoint, but not unship the step in
4574ba319b5SDimitry Andric // plan, since you still may want to complete that plan when you continue.
4584ba319b5SDimitry Andric // This is particularly true when doing "step in to target function."
459ac7ddfbfSEd Maste // stepping.
460ac7ddfbfSEd Maste //
4614ba319b5SDimitry Andric // The only variation is that if we are doing "step by running to next
4624ba319b5SDimitry Andric // branch" in which case if we hit our branch breakpoint we don't set the
4634ba319b5SDimitry Andric // plan to complete.
464ac7ddfbfSEd Maste
4659f2f44ceSEd Maste bool return_value = false;
466ac7ddfbfSEd Maste
467435933ddSDimitry Andric if (m_virtual_step) {
468ac7ddfbfSEd Maste return_value = true;
469435933ddSDimitry Andric } else {
470ac7ddfbfSEd Maste StopInfoSP stop_info_sp = GetPrivateStopInfo();
471435933ddSDimitry Andric if (stop_info_sp) {
472ac7ddfbfSEd Maste StopReason reason = stop_info_sp->GetStopReason();
473ac7ddfbfSEd Maste
474435933ddSDimitry Andric if (reason == eStopReasonBreakpoint) {
475435933ddSDimitry Andric if (NextRangeBreakpointExplainsStop(stop_info_sp)) {
476ac7ddfbfSEd Maste return_value = true;
477ac7ddfbfSEd Maste }
478435933ddSDimitry Andric } else if (IsUsuallyUnexplainedStopReason(reason)) {
479ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
480ac7ddfbfSEd Maste if (log)
481435933ddSDimitry Andric log->PutCString("ThreadPlanStepInRange got asked if it explains the "
482435933ddSDimitry Andric "stop for some reason other than step.");
483ac7ddfbfSEd Maste return_value = false;
484435933ddSDimitry Andric } else {
485ac7ddfbfSEd Maste return_value = true;
486ac7ddfbfSEd Maste }
487435933ddSDimitry Andric } else
488ac7ddfbfSEd Maste return_value = true;
489ac7ddfbfSEd Maste }
490ac7ddfbfSEd Maste
491ac7ddfbfSEd Maste return return_value;
492ac7ddfbfSEd Maste }
493ac7ddfbfSEd Maste
DoWillResume(lldb::StateType resume_state,bool current_plan)494435933ddSDimitry Andric bool ThreadPlanStepInRange::DoWillResume(lldb::StateType resume_state,
495435933ddSDimitry Andric bool current_plan) {
4961c3bbb01SEd Maste m_virtual_step = false;
497435933ddSDimitry Andric if (resume_state == eStateStepping && current_plan) {
498ac7ddfbfSEd Maste // See if we are about to step over a virtual inlined call.
499ac7ddfbfSEd Maste bool step_without_resume = m_thread.DecrementCurrentInlinedDepth();
500435933ddSDimitry Andric if (step_without_resume) {
501ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
502ac7ddfbfSEd Maste if (log)
503435933ddSDimitry Andric log->Printf("ThreadPlanStepInRange::DoWillResume: returning false, "
504435933ddSDimitry Andric "inline_depth: %d",
505ac7ddfbfSEd Maste m_thread.GetCurrentInlinedDepth());
506ac7ddfbfSEd Maste SetStopInfo(StopInfo::CreateStopReasonToTrace(m_thread));
507ac7ddfbfSEd Maste
508435933ddSDimitry Andric // FIXME: Maybe it would be better to create a InlineStep stop reason, but
509435933ddSDimitry Andric // then
510ac7ddfbfSEd Maste // the whole rest of the world would have to handle that stop reason.
511ac7ddfbfSEd Maste m_virtual_step = true;
512ac7ddfbfSEd Maste }
513ac7ddfbfSEd Maste return !step_without_resume;
514ac7ddfbfSEd Maste }
515ac7ddfbfSEd Maste return true;
516ac7ddfbfSEd Maste }
517ac7ddfbfSEd Maste
IsVirtualStep()518435933ddSDimitry Andric bool ThreadPlanStepInRange::IsVirtualStep() { return m_virtual_step; }
519