xref: /openbsd-src/gnu/llvm/lldb/source/Target/ThreadPlanStepInRange.cpp (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1dda28197Spatrick //===-- ThreadPlanStepInRange.cpp -----------------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9061da546Spatrick #include "lldb/Target/ThreadPlanStepInRange.h"
10061da546Spatrick #include "lldb/Core/Architecture.h"
11061da546Spatrick #include "lldb/Core/Module.h"
12061da546Spatrick #include "lldb/Symbol/Function.h"
13061da546Spatrick #include "lldb/Symbol/Symbol.h"
14061da546Spatrick #include "lldb/Target/Process.h"
15061da546Spatrick #include "lldb/Target/RegisterContext.h"
16061da546Spatrick #include "lldb/Target/SectionLoadList.h"
17061da546Spatrick #include "lldb/Target/Target.h"
18061da546Spatrick #include "lldb/Target/Thread.h"
19061da546Spatrick #include "lldb/Target/ThreadPlanStepOut.h"
20061da546Spatrick #include "lldb/Target/ThreadPlanStepThrough.h"
21*f6aab3d8Srobert #include "lldb/Utility/LLDBLog.h"
22061da546Spatrick #include "lldb/Utility/Log.h"
23061da546Spatrick #include "lldb/Utility/RegularExpression.h"
24061da546Spatrick #include "lldb/Utility/Stream.h"
25061da546Spatrick 
26061da546Spatrick using namespace lldb;
27061da546Spatrick using namespace lldb_private;
28061da546Spatrick 
29061da546Spatrick uint32_t ThreadPlanStepInRange::s_default_flag_values =
30061da546Spatrick     ThreadPlanShouldStopHere::eStepInAvoidNoDebug;
31061da546Spatrick 
32061da546Spatrick // ThreadPlanStepInRange: Step through a stack range, either stepping over or
33061da546Spatrick // into based on the value of \a type.
34061da546Spatrick 
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)35061da546Spatrick ThreadPlanStepInRange::ThreadPlanStepInRange(
36061da546Spatrick     Thread &thread, const AddressRange &range,
37061da546Spatrick     const SymbolContext &addr_context, const char *step_into_target,
38061da546Spatrick     lldb::RunMode stop_others, LazyBool step_in_avoids_code_without_debug_info,
39061da546Spatrick     LazyBool step_out_avoids_code_without_debug_info)
40061da546Spatrick     : ThreadPlanStepRange(ThreadPlan::eKindStepInRange,
41061da546Spatrick                           "Step Range stepping in", thread, range, addr_context,
42061da546Spatrick                           stop_others),
43061da546Spatrick       ThreadPlanShouldStopHere(this), m_step_past_prologue(true),
44061da546Spatrick       m_virtual_step(false), m_step_into_target(step_into_target) {
45061da546Spatrick   SetCallbacks();
46061da546Spatrick   SetFlagsToDefault();
47061da546Spatrick   SetupAvoidNoDebug(step_in_avoids_code_without_debug_info,
48061da546Spatrick                     step_out_avoids_code_without_debug_info);
49061da546Spatrick }
50061da546Spatrick 
51061da546Spatrick ThreadPlanStepInRange::~ThreadPlanStepInRange() = default;
52061da546Spatrick 
SetupAvoidNoDebug(LazyBool step_in_avoids_code_without_debug_info,LazyBool step_out_avoids_code_without_debug_info)53061da546Spatrick void ThreadPlanStepInRange::SetupAvoidNoDebug(
54061da546Spatrick     LazyBool step_in_avoids_code_without_debug_info,
55061da546Spatrick     LazyBool step_out_avoids_code_without_debug_info) {
56061da546Spatrick   bool avoid_nodebug = true;
57dda28197Spatrick   Thread &thread = GetThread();
58061da546Spatrick   switch (step_in_avoids_code_without_debug_info) {
59061da546Spatrick   case eLazyBoolYes:
60061da546Spatrick     avoid_nodebug = true;
61061da546Spatrick     break;
62061da546Spatrick   case eLazyBoolNo:
63061da546Spatrick     avoid_nodebug = false;
64061da546Spatrick     break;
65061da546Spatrick   case eLazyBoolCalculate:
66dda28197Spatrick     avoid_nodebug = thread.GetStepInAvoidsNoDebug();
67061da546Spatrick     break;
68061da546Spatrick   }
69061da546Spatrick   if (avoid_nodebug)
70061da546Spatrick     GetFlags().Set(ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
71061da546Spatrick   else
72061da546Spatrick     GetFlags().Clear(ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
73061da546Spatrick 
74061da546Spatrick   switch (step_out_avoids_code_without_debug_info) {
75061da546Spatrick   case eLazyBoolYes:
76061da546Spatrick     avoid_nodebug = true;
77061da546Spatrick     break;
78061da546Spatrick   case eLazyBoolNo:
79061da546Spatrick     avoid_nodebug = false;
80061da546Spatrick     break;
81061da546Spatrick   case eLazyBoolCalculate:
82dda28197Spatrick     avoid_nodebug = thread.GetStepOutAvoidsNoDebug();
83061da546Spatrick     break;
84061da546Spatrick   }
85061da546Spatrick   if (avoid_nodebug)
86061da546Spatrick     GetFlags().Set(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
87061da546Spatrick   else
88061da546Spatrick     GetFlags().Clear(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
89061da546Spatrick }
90061da546Spatrick 
GetDescription(Stream * s,lldb::DescriptionLevel level)91061da546Spatrick void ThreadPlanStepInRange::GetDescription(Stream *s,
92061da546Spatrick                                            lldb::DescriptionLevel level) {
93061da546Spatrick 
94061da546Spatrick   auto PrintFailureIfAny = [&]() {
95061da546Spatrick     if (m_status.Success())
96061da546Spatrick       return;
97061da546Spatrick     s->Printf(" failed (%s)", m_status.AsCString());
98061da546Spatrick   };
99061da546Spatrick 
100061da546Spatrick   if (level == lldb::eDescriptionLevelBrief) {
101061da546Spatrick     s->Printf("step in");
102061da546Spatrick     PrintFailureIfAny();
103061da546Spatrick     return;
104061da546Spatrick   }
105061da546Spatrick 
106061da546Spatrick   s->Printf("Stepping in");
107061da546Spatrick   bool printed_line_info = false;
108061da546Spatrick   if (m_addr_context.line_entry.IsValid()) {
109061da546Spatrick     s->Printf(" through line ");
110061da546Spatrick     m_addr_context.line_entry.DumpStopContext(s, false);
111061da546Spatrick     printed_line_info = true;
112061da546Spatrick   }
113061da546Spatrick 
114061da546Spatrick   const char *step_into_target = m_step_into_target.AsCString();
115061da546Spatrick   if (step_into_target && step_into_target[0] != '\0')
116061da546Spatrick     s->Printf(" targeting %s", m_step_into_target.AsCString());
117061da546Spatrick 
118061da546Spatrick   if (!printed_line_info || level == eDescriptionLevelVerbose) {
119061da546Spatrick     s->Printf(" using ranges:");
120061da546Spatrick     DumpRanges(s);
121061da546Spatrick   }
122061da546Spatrick 
123061da546Spatrick   PrintFailureIfAny();
124061da546Spatrick 
125061da546Spatrick   s->PutChar('.');
126061da546Spatrick }
127061da546Spatrick 
ShouldStop(Event * event_ptr)128061da546Spatrick bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) {
129*f6aab3d8Srobert   Log *log = GetLog(LLDBLog::Step);
130061da546Spatrick 
131061da546Spatrick   if (log) {
132061da546Spatrick     StreamString s;
133dda28197Spatrick     DumpAddress(s.AsRawOstream(), GetThread().GetRegisterContext()->GetPC(),
134dda28197Spatrick                 GetTarget().GetArchitecture().GetAddressByteSize());
135061da546Spatrick     LLDB_LOGF(log, "ThreadPlanStepInRange reached %s.", s.GetData());
136061da546Spatrick   }
137061da546Spatrick 
138061da546Spatrick   if (IsPlanComplete())
139061da546Spatrick     return true;
140061da546Spatrick 
141061da546Spatrick   m_no_more_plans = false;
142061da546Spatrick   if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete()) {
143061da546Spatrick     if (!m_sub_plan_sp->PlanSucceeded()) {
144061da546Spatrick       SetPlanComplete();
145061da546Spatrick       m_no_more_plans = true;
146061da546Spatrick       return true;
147061da546Spatrick     } else
148061da546Spatrick       m_sub_plan_sp.reset();
149061da546Spatrick   }
150061da546Spatrick 
151061da546Spatrick   if (m_virtual_step) {
152061da546Spatrick     // If we've just completed a virtual step, all we need to do is check for a
153061da546Spatrick     // ShouldStopHere plan, and otherwise we're done.
154061da546Spatrick     // FIXME - This can be both a step in and a step out.  Probably should
155061da546Spatrick     // record which in the m_virtual_step.
156061da546Spatrick     m_sub_plan_sp =
157061da546Spatrick         CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger, m_status);
158061da546Spatrick   } else {
159061da546Spatrick     // Stepping through should be done running other threads in general, since
160061da546Spatrick     // we're setting a breakpoint and continuing.  So only stop others if we
161061da546Spatrick     // are explicitly told to do so.
162061da546Spatrick 
163061da546Spatrick     bool stop_others = (m_stop_others == lldb::eOnlyThisThread);
164061da546Spatrick 
165061da546Spatrick     FrameComparison frame_order = CompareCurrentFrameToStartFrame();
166061da546Spatrick 
167dda28197Spatrick     Thread &thread = GetThread();
168061da546Spatrick     if (frame_order == eFrameCompareOlder ||
169061da546Spatrick         frame_order == eFrameCompareSameParent) {
170061da546Spatrick       // If we're in an older frame then we should stop.
171061da546Spatrick       //
172061da546Spatrick       // A caveat to this is if we think the frame is older but we're actually
173061da546Spatrick       // in a trampoline.
174061da546Spatrick       // I'm going to make the assumption that you wouldn't RETURN to a
175061da546Spatrick       // trampoline.  So if we are in a trampoline we think the frame is older
176061da546Spatrick       // because the trampoline confused the backtracer.
177dda28197Spatrick       m_sub_plan_sp = thread.QueueThreadPlanForStepThrough(
178061da546Spatrick           m_stack_id, false, stop_others, m_status);
179061da546Spatrick       if (!m_sub_plan_sp) {
180061da546Spatrick         // Otherwise check the ShouldStopHere for step out:
181061da546Spatrick         m_sub_plan_sp =
182061da546Spatrick             CheckShouldStopHereAndQueueStepOut(frame_order, m_status);
183061da546Spatrick         if (log) {
184061da546Spatrick           if (m_sub_plan_sp)
185061da546Spatrick             LLDB_LOGF(log,
186061da546Spatrick                       "ShouldStopHere found plan to step out of this frame.");
187061da546Spatrick           else
188061da546Spatrick             LLDB_LOGF(log, "ShouldStopHere no plan to step out of this frame.");
189061da546Spatrick         }
190061da546Spatrick       } else if (log) {
191061da546Spatrick         LLDB_LOGF(
192061da546Spatrick             log, "Thought I stepped out, but in fact arrived at a trampoline.");
193061da546Spatrick       }
194061da546Spatrick     } else if (frame_order == eFrameCompareEqual && InSymbol()) {
195061da546Spatrick       // If we are not in a place we should step through, we're done. One
196061da546Spatrick       // tricky bit here is that some stubs don't push a frame, so we have to
197061da546Spatrick       // check both the case of a frame that is younger, or the same as this
198061da546Spatrick       // frame. However, if the frame is the same, and we are still in the
199061da546Spatrick       // symbol we started in, the we don't need to do this.  This first check
200061da546Spatrick       // isn't strictly necessary, but it is more efficient.
201061da546Spatrick 
202061da546Spatrick       // If we're still in the range, keep going, either by running to the next
203061da546Spatrick       // branch breakpoint, or by stepping.
204061da546Spatrick       if (InRange()) {
205061da546Spatrick         SetNextBranchBreakpoint();
206061da546Spatrick         return false;
207061da546Spatrick       }
208061da546Spatrick 
209061da546Spatrick       SetPlanComplete();
210061da546Spatrick       m_no_more_plans = true;
211061da546Spatrick       return true;
212061da546Spatrick     }
213061da546Spatrick 
214061da546Spatrick     // If we get to this point, we're not going to use a previously set "next
215061da546Spatrick     // branch" breakpoint, so delete it:
216061da546Spatrick     ClearNextBranchBreakpoint();
217061da546Spatrick 
218061da546Spatrick     // We may have set the plan up above in the FrameIsOlder section:
219061da546Spatrick 
220061da546Spatrick     if (!m_sub_plan_sp)
221dda28197Spatrick       m_sub_plan_sp = thread.QueueThreadPlanForStepThrough(
222061da546Spatrick           m_stack_id, false, stop_others, m_status);
223061da546Spatrick 
224061da546Spatrick     if (log) {
225061da546Spatrick       if (m_sub_plan_sp)
226061da546Spatrick         LLDB_LOGF(log, "Found a step through plan: %s",
227061da546Spatrick                   m_sub_plan_sp->GetName());
228061da546Spatrick       else
229061da546Spatrick         LLDB_LOGF(log, "No step through plan found.");
230061da546Spatrick     }
231061da546Spatrick 
232061da546Spatrick     // If not, give the "should_stop" callback a chance to push a plan to get
233061da546Spatrick     // us out of here. But only do that if we actually have stepped in.
234061da546Spatrick     if (!m_sub_plan_sp && frame_order == eFrameCompareYounger)
235061da546Spatrick       m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order, m_status);
236061da546Spatrick 
237061da546Spatrick     // If we've stepped in and we are going to stop here, check to see if we
238061da546Spatrick     // were asked to run past the prologue, and if so do that.
239061da546Spatrick 
240061da546Spatrick     if (!m_sub_plan_sp && frame_order == eFrameCompareYounger &&
241061da546Spatrick         m_step_past_prologue) {
242dda28197Spatrick       lldb::StackFrameSP curr_frame = thread.GetStackFrameAtIndex(0);
243061da546Spatrick       if (curr_frame) {
244061da546Spatrick         size_t bytes_to_skip = 0;
245dda28197Spatrick         lldb::addr_t curr_addr = thread.GetRegisterContext()->GetPC();
246061da546Spatrick         Address func_start_address;
247061da546Spatrick 
248061da546Spatrick         SymbolContext sc = curr_frame->GetSymbolContext(eSymbolContextFunction |
249061da546Spatrick                                                         eSymbolContextSymbol);
250061da546Spatrick 
251061da546Spatrick         if (sc.function) {
252061da546Spatrick           func_start_address = sc.function->GetAddressRange().GetBaseAddress();
253dda28197Spatrick           if (curr_addr == func_start_address.GetLoadAddress(&GetTarget()))
254061da546Spatrick             bytes_to_skip = sc.function->GetPrologueByteSize();
255061da546Spatrick         } else if (sc.symbol) {
256061da546Spatrick           func_start_address = sc.symbol->GetAddress();
257dda28197Spatrick           if (curr_addr == func_start_address.GetLoadAddress(&GetTarget()))
258061da546Spatrick             bytes_to_skip = sc.symbol->GetPrologueByteSize();
259061da546Spatrick         }
260061da546Spatrick 
261061da546Spatrick         if (bytes_to_skip == 0 && sc.symbol) {
262dda28197Spatrick           const Architecture *arch = GetTarget().GetArchitecturePlugin();
263061da546Spatrick           if (arch) {
264061da546Spatrick             Address curr_sec_addr;
265dda28197Spatrick             GetTarget().GetSectionLoadList().ResolveLoadAddress(curr_addr,
266061da546Spatrick                                                                 curr_sec_addr);
267061da546Spatrick             bytes_to_skip = arch->GetBytesToSkip(*sc.symbol, curr_sec_addr);
268061da546Spatrick           }
269061da546Spatrick         }
270061da546Spatrick 
271061da546Spatrick         if (bytes_to_skip != 0) {
272061da546Spatrick           func_start_address.Slide(bytes_to_skip);
273*f6aab3d8Srobert           log = GetLog(LLDBLog::Step);
274061da546Spatrick           LLDB_LOGF(log, "Pushing past prologue ");
275061da546Spatrick 
276dda28197Spatrick           m_sub_plan_sp = thread.QueueThreadPlanForRunToAddress(
277061da546Spatrick               false, func_start_address, true, m_status);
278061da546Spatrick         }
279061da546Spatrick       }
280061da546Spatrick     }
281061da546Spatrick   }
282061da546Spatrick 
283061da546Spatrick   if (!m_sub_plan_sp) {
284061da546Spatrick     m_no_more_plans = true;
285061da546Spatrick     SetPlanComplete();
286061da546Spatrick     return true;
287061da546Spatrick   } else {
288061da546Spatrick     m_no_more_plans = false;
289061da546Spatrick     m_sub_plan_sp->SetPrivate(true);
290061da546Spatrick     return false;
291061da546Spatrick   }
292061da546Spatrick }
293061da546Spatrick 
SetAvoidRegexp(const char * name)294061da546Spatrick void ThreadPlanStepInRange::SetAvoidRegexp(const char *name) {
295061da546Spatrick   if (m_avoid_regexp_up)
296be691f3bSpatrick     *m_avoid_regexp_up = RegularExpression(name);
297061da546Spatrick   else
298be691f3bSpatrick     m_avoid_regexp_up = std::make_unique<RegularExpression>(name);
299061da546Spatrick }
300061da546Spatrick 
SetDefaultFlagValue(uint32_t new_value)301061da546Spatrick void ThreadPlanStepInRange::SetDefaultFlagValue(uint32_t new_value) {
302061da546Spatrick   // TODO: Should we test this for sanity?
303061da546Spatrick   ThreadPlanStepInRange::s_default_flag_values = new_value;
304061da546Spatrick }
305061da546Spatrick 
FrameMatchesAvoidCriteria()306061da546Spatrick bool ThreadPlanStepInRange::FrameMatchesAvoidCriteria() {
307061da546Spatrick   StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
308061da546Spatrick 
309061da546Spatrick   // Check the library list first, as that's cheapest:
310061da546Spatrick   bool libraries_say_avoid = false;
311061da546Spatrick 
312061da546Spatrick   FileSpecList libraries_to_avoid(GetThread().GetLibrariesToAvoid());
313061da546Spatrick   size_t num_libraries = libraries_to_avoid.GetSize();
314061da546Spatrick   if (num_libraries > 0) {
315061da546Spatrick     SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
316061da546Spatrick     FileSpec frame_library(sc.module_sp->GetFileSpec());
317061da546Spatrick 
318061da546Spatrick     if (frame_library) {
319061da546Spatrick       for (size_t i = 0; i < num_libraries; i++) {
320061da546Spatrick         const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
321061da546Spatrick         if (FileSpec::Match(file_spec, frame_library)) {
322061da546Spatrick           libraries_say_avoid = true;
323061da546Spatrick           break;
324061da546Spatrick         }
325061da546Spatrick       }
326061da546Spatrick     }
327061da546Spatrick   }
328061da546Spatrick   if (libraries_say_avoid)
329061da546Spatrick     return true;
330061da546Spatrick 
331061da546Spatrick   const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_up.get();
332061da546Spatrick   if (avoid_regexp_to_use == nullptr)
333061da546Spatrick     avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
334061da546Spatrick 
335061da546Spatrick   if (avoid_regexp_to_use != nullptr) {
336061da546Spatrick     SymbolContext sc = frame->GetSymbolContext(
337061da546Spatrick         eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
338061da546Spatrick     if (sc.symbol != nullptr) {
339061da546Spatrick       const char *frame_function_name =
340061da546Spatrick           sc.GetFunctionName(Mangled::ePreferDemangledWithoutArguments)
341061da546Spatrick               .GetCString();
342061da546Spatrick       if (frame_function_name) {
343*f6aab3d8Srobert         bool return_value = avoid_regexp_to_use->Execute(frame_function_name);
344*f6aab3d8Srobert         if (return_value) {
345*f6aab3d8Srobert           LLDB_LOGF(GetLog(LLDBLog::Step),
346*f6aab3d8Srobert                     "Stepping out of function \"%s\" because it matches the "
347*f6aab3d8Srobert                     "avoid regexp \"%s\".",
348061da546Spatrick                     frame_function_name,
349*f6aab3d8Srobert                     avoid_regexp_to_use->GetText().str().c_str());
350061da546Spatrick         }
351061da546Spatrick         return return_value;
352061da546Spatrick       }
353061da546Spatrick     }
354061da546Spatrick   }
355061da546Spatrick   return false;
356061da546Spatrick }
357061da546Spatrick 
DefaultShouldStopHereCallback(ThreadPlan * current_plan,Flags & flags,FrameComparison operation,Status & status,void * baton)358061da546Spatrick bool ThreadPlanStepInRange::DefaultShouldStopHereCallback(
359061da546Spatrick     ThreadPlan *current_plan, Flags &flags, FrameComparison operation,
360061da546Spatrick     Status &status, void *baton) {
361061da546Spatrick   bool should_stop_here = true;
362061da546Spatrick   StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
363*f6aab3d8Srobert   Log *log = GetLog(LLDBLog::Step);
364061da546Spatrick 
365061da546Spatrick   // First see if the ThreadPlanShouldStopHere default implementation thinks we
366061da546Spatrick   // should get out of here:
367061da546Spatrick   should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback(
368061da546Spatrick       current_plan, flags, operation, status, baton);
369061da546Spatrick   if (!should_stop_here)
370061da546Spatrick     return false;
371061da546Spatrick 
372061da546Spatrick   if (should_stop_here && current_plan->GetKind() == eKindStepInRange &&
373061da546Spatrick       operation == eFrameCompareYounger) {
374061da546Spatrick     ThreadPlanStepInRange *step_in_range_plan =
375061da546Spatrick         static_cast<ThreadPlanStepInRange *>(current_plan);
376061da546Spatrick     if (step_in_range_plan->m_step_into_target) {
377061da546Spatrick       SymbolContext sc = frame->GetSymbolContext(
378061da546Spatrick           eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
379061da546Spatrick       if (sc.symbol != nullptr) {
380061da546Spatrick         // First try an exact match, since that's cheap with ConstStrings.
381061da546Spatrick         // Then do a strstr compare.
382061da546Spatrick         if (step_in_range_plan->m_step_into_target == sc.GetFunctionName()) {
383061da546Spatrick           should_stop_here = true;
384061da546Spatrick         } else {
385061da546Spatrick           const char *target_name =
386061da546Spatrick               step_in_range_plan->m_step_into_target.AsCString();
387061da546Spatrick           const char *function_name = sc.GetFunctionName().AsCString();
388061da546Spatrick 
389061da546Spatrick           if (function_name == nullptr)
390061da546Spatrick             should_stop_here = false;
391061da546Spatrick           else if (strstr(function_name, target_name) == nullptr)
392061da546Spatrick             should_stop_here = false;
393061da546Spatrick         }
394061da546Spatrick         if (log && !should_stop_here)
395061da546Spatrick           LLDB_LOGF(log,
396061da546Spatrick                     "Stepping out of frame %s which did not match step into "
397061da546Spatrick                     "target %s.",
398061da546Spatrick                     sc.GetFunctionName().AsCString(),
399061da546Spatrick                     step_in_range_plan->m_step_into_target.AsCString());
400061da546Spatrick       }
401061da546Spatrick     }
402061da546Spatrick 
403061da546Spatrick     if (should_stop_here) {
404061da546Spatrick       ThreadPlanStepInRange *step_in_range_plan =
405061da546Spatrick           static_cast<ThreadPlanStepInRange *>(current_plan);
406061da546Spatrick       // Don't log the should_step_out here, it's easier to do it in
407061da546Spatrick       // FrameMatchesAvoidCriteria.
408061da546Spatrick       should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria();
409061da546Spatrick     }
410061da546Spatrick   }
411061da546Spatrick 
412061da546Spatrick   return should_stop_here;
413061da546Spatrick }
414061da546Spatrick 
DoPlanExplainsStop(Event * event_ptr)415061da546Spatrick bool ThreadPlanStepInRange::DoPlanExplainsStop(Event *event_ptr) {
416061da546Spatrick   // We always explain a stop.  Either we've just done a single step, in which
417061da546Spatrick   // case we'll do our ordinary processing, or we stopped for some reason that
418061da546Spatrick   // isn't handled by our sub-plans, in which case we want to just stop right
419061da546Spatrick   // away. In general, we don't want to mark the plan as complete for
420061da546Spatrick   // unexplained stops. For instance, if you step in to some code with no debug
421061da546Spatrick   // info, so you step out and in the course of that hit a breakpoint, then you
422061da546Spatrick   // want to stop & show the user the breakpoint, but not unship the step in
423061da546Spatrick   // plan, since you still may want to complete that plan when you continue.
424061da546Spatrick   // This is particularly true when doing "step in to target function."
425061da546Spatrick   // stepping.
426061da546Spatrick   //
427061da546Spatrick   // The only variation is that if we are doing "step by running to next
428061da546Spatrick   // branch" in which case if we hit our branch breakpoint we don't set the
429061da546Spatrick   // plan to complete.
430061da546Spatrick 
431061da546Spatrick   bool return_value = false;
432061da546Spatrick 
433061da546Spatrick   if (m_virtual_step) {
434061da546Spatrick     return_value = true;
435061da546Spatrick   } else {
436061da546Spatrick     StopInfoSP stop_info_sp = GetPrivateStopInfo();
437061da546Spatrick     if (stop_info_sp) {
438061da546Spatrick       StopReason reason = stop_info_sp->GetStopReason();
439061da546Spatrick 
440061da546Spatrick       if (reason == eStopReasonBreakpoint) {
441061da546Spatrick         if (NextRangeBreakpointExplainsStop(stop_info_sp)) {
442061da546Spatrick           return_value = true;
443061da546Spatrick         }
444061da546Spatrick       } else if (IsUsuallyUnexplainedStopReason(reason)) {
445*f6aab3d8Srobert         Log *log = GetLog(LLDBLog::Step);
446061da546Spatrick         if (log)
447061da546Spatrick           log->PutCString("ThreadPlanStepInRange got asked if it explains the "
448061da546Spatrick                           "stop for some reason other than step.");
449061da546Spatrick         return_value = false;
450061da546Spatrick       } else {
451061da546Spatrick         return_value = true;
452061da546Spatrick       }
453061da546Spatrick     } else
454061da546Spatrick       return_value = true;
455061da546Spatrick   }
456061da546Spatrick 
457061da546Spatrick   return return_value;
458061da546Spatrick }
459061da546Spatrick 
DoWillResume(lldb::StateType resume_state,bool current_plan)460061da546Spatrick bool ThreadPlanStepInRange::DoWillResume(lldb::StateType resume_state,
461061da546Spatrick                                          bool current_plan) {
462061da546Spatrick   m_virtual_step = false;
463061da546Spatrick   if (resume_state == eStateStepping && current_plan) {
464dda28197Spatrick     Thread &thread = GetThread();
465061da546Spatrick     // See if we are about to step over a virtual inlined call.
466dda28197Spatrick     bool step_without_resume = thread.DecrementCurrentInlinedDepth();
467061da546Spatrick     if (step_without_resume) {
468*f6aab3d8Srobert       Log *log = GetLog(LLDBLog::Step);
469061da546Spatrick       LLDB_LOGF(log,
470061da546Spatrick                 "ThreadPlanStepInRange::DoWillResume: returning false, "
471061da546Spatrick                 "inline_depth: %d",
472dda28197Spatrick                 thread.GetCurrentInlinedDepth());
473dda28197Spatrick       SetStopInfo(StopInfo::CreateStopReasonToTrace(thread));
474061da546Spatrick 
475061da546Spatrick       // FIXME: Maybe it would be better to create a InlineStep stop reason, but
476061da546Spatrick       // then
477061da546Spatrick       // the whole rest of the world would have to handle that stop reason.
478061da546Spatrick       m_virtual_step = true;
479061da546Spatrick     }
480061da546Spatrick     return !step_without_resume;
481061da546Spatrick   }
482061da546Spatrick   return true;
483061da546Spatrick }
484061da546Spatrick 
IsVirtualStep()485061da546Spatrick bool ThreadPlanStepInRange::IsVirtualStep() { return m_virtual_step; }
486