130fdc8d8SChris Lattner //===-- ThreadPlanStepInRange.cpp -------------------------------*- C++ -*-===//
230fdc8d8SChris Lattner //
330fdc8d8SChris Lattner //                     The LLVM Compiler Infrastructure
430fdc8d8SChris Lattner //
530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source
630fdc8d8SChris Lattner // License. See LICENSE.TXT for details.
730fdc8d8SChris Lattner //
830fdc8d8SChris Lattner //===----------------------------------------------------------------------===//
930fdc8d8SChris Lattner 
1030fdc8d8SChris Lattner // C Includes
1130fdc8d8SChris Lattner // C++ Includes
1230fdc8d8SChris Lattner // Other libraries and framework includes
1330fdc8d8SChris Lattner // Project includes
14e65b2cf2SEugene Zelenko #include "lldb/Target/ThreadPlanStepInRange.h"
1508581263SJim Ingham #include "lldb/Core/Architecture.h"
164da6206dSJim Ingham #include "lldb/Core/Module.h"
177ce490c6SJim Ingham #include "lldb/Symbol/Function.h"
18b9c1b51eSKate Stone #include "lldb/Symbol/Symbol.h"
1930fdc8d8SChris Lattner #include "lldb/Target/Process.h"
2030fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.h"
2108581263SJim Ingham #include "lldb/Target/SectionLoadList.h"
22514487e8SGreg Clayton #include "lldb/Target/Target.h"
2330fdc8d8SChris Lattner #include "lldb/Target/Thread.h"
2430fdc8d8SChris Lattner #include "lldb/Target/ThreadPlanStepOut.h"
2530fdc8d8SChris Lattner #include "lldb/Target/ThreadPlanStepThrough.h"
266f9e6901SZachary Turner #include "lldb/Utility/Log.h"
27bf9a7730SZachary Turner #include "lldb/Utility/RegularExpression.h"
28bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
2930fdc8d8SChris Lattner 
3030fdc8d8SChris Lattner using namespace lldb;
3130fdc8d8SChris Lattner using namespace lldb_private;
3230fdc8d8SChris Lattner 
33b9c1b51eSKate Stone uint32_t ThreadPlanStepInRange::s_default_flag_values =
34b9c1b51eSKate Stone     ThreadPlanShouldStopHere::eStepInAvoidNoDebug;
3530fdc8d8SChris Lattner 
3630fdc8d8SChris Lattner //----------------------------------------------------------------------
37b9c1b51eSKate Stone // ThreadPlanStepInRange: Step through a stack range, either stepping over or
3805097246SAdrian Prantl // into based on the value of \a type.
3930fdc8d8SChris Lattner //----------------------------------------------------------------------
4030fdc8d8SChris Lattner 
41b9c1b51eSKate Stone ThreadPlanStepInRange::ThreadPlanStepInRange(
42b9c1b51eSKate Stone     Thread &thread, const AddressRange &range,
43b9c1b51eSKate Stone     const SymbolContext &addr_context, lldb::RunMode stop_others,
444b4b2478SJim Ingham     LazyBool step_in_avoids_code_without_debug_info,
45b9c1b51eSKate Stone     LazyBool step_out_avoids_code_without_debug_info)
46b9c1b51eSKate Stone     : ThreadPlanStepRange(ThreadPlan::eKindStepInRange,
47b9c1b51eSKate Stone                           "Step Range stepping in", thread, range, addr_context,
48b9c1b51eSKate Stone                           stop_others),
49b9c1b51eSKate Stone       ThreadPlanShouldStopHere(this), m_step_past_prologue(true),
50b9c1b51eSKate Stone       m_virtual_step(false) {
514b4b2478SJim Ingham   SetCallbacks();
5230fdc8d8SChris Lattner   SetFlagsToDefault();
53b9c1b51eSKate Stone   SetupAvoidNoDebug(step_in_avoids_code_without_debug_info,
54b9c1b51eSKate Stone                     step_out_avoids_code_without_debug_info);
5530fdc8d8SChris Lattner }
5630fdc8d8SChris Lattner 
57b9c1b51eSKate Stone ThreadPlanStepInRange::ThreadPlanStepInRange(
58b9c1b51eSKate Stone     Thread &thread, const AddressRange &range,
59b9c1b51eSKate Stone     const SymbolContext &addr_context, const char *step_into_target,
60b9c1b51eSKate Stone     lldb::RunMode stop_others, LazyBool step_in_avoids_code_without_debug_info,
61b9c1b51eSKate Stone     LazyBool step_out_avoids_code_without_debug_info)
62b9c1b51eSKate Stone     : ThreadPlanStepRange(ThreadPlan::eKindStepInRange,
63b9c1b51eSKate Stone                           "Step Range stepping in", thread, range, addr_context,
64b9c1b51eSKate Stone                           stop_others),
65b9c1b51eSKate Stone       ThreadPlanShouldStopHere(this), m_step_past_prologue(true),
66b9c1b51eSKate Stone       m_virtual_step(false), m_step_into_target(step_into_target) {
674b4b2478SJim Ingham   SetCallbacks();
68c627682eSJim Ingham   SetFlagsToDefault();
69b9c1b51eSKate Stone   SetupAvoidNoDebug(step_in_avoids_code_without_debug_info,
70b9c1b51eSKate Stone                     step_out_avoids_code_without_debug_info);
71c627682eSJim Ingham }
72c627682eSJim Ingham 
73e65b2cf2SEugene Zelenko ThreadPlanStepInRange::~ThreadPlanStepInRange() = default;
7430fdc8d8SChris Lattner 
75b9c1b51eSKate Stone void ThreadPlanStepInRange::SetupAvoidNoDebug(
76b9c1b51eSKate Stone     LazyBool step_in_avoids_code_without_debug_info,
77b9c1b51eSKate Stone     LazyBool step_out_avoids_code_without_debug_info) {
784b4b2478SJim Ingham   bool avoid_nodebug = true;
794b4b2478SJim Ingham 
80b9c1b51eSKate Stone   switch (step_in_avoids_code_without_debug_info) {
814b4b2478SJim Ingham   case eLazyBoolYes:
824b4b2478SJim Ingham     avoid_nodebug = true;
834b4b2478SJim Ingham     break;
844b4b2478SJim Ingham   case eLazyBoolNo:
854b4b2478SJim Ingham     avoid_nodebug = false;
864b4b2478SJim Ingham     break;
874b4b2478SJim Ingham   case eLazyBoolCalculate:
884b4b2478SJim Ingham     avoid_nodebug = m_thread.GetStepInAvoidsNoDebug();
894b4b2478SJim Ingham     break;
904b4b2478SJim Ingham   }
914b4b2478SJim Ingham   if (avoid_nodebug)
924b4b2478SJim Ingham     GetFlags().Set(ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
934b4b2478SJim Ingham   else
944b4b2478SJim Ingham     GetFlags().Clear(ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
954b4b2478SJim Ingham 
96b9c1b51eSKate Stone   switch (step_out_avoids_code_without_debug_info) {
974b4b2478SJim Ingham   case eLazyBoolYes:
984b4b2478SJim Ingham     avoid_nodebug = true;
994b4b2478SJim Ingham     break;
1004b4b2478SJim Ingham   case eLazyBoolNo:
1014b4b2478SJim Ingham     avoid_nodebug = false;
1024b4b2478SJim Ingham     break;
1034b4b2478SJim Ingham   case eLazyBoolCalculate:
1044b4b2478SJim Ingham     avoid_nodebug = m_thread.GetStepOutAvoidsNoDebug();
1054b4b2478SJim Ingham     break;
1064b4b2478SJim Ingham   }
1074b4b2478SJim Ingham   if (avoid_nodebug)
1084b4b2478SJim Ingham     GetFlags().Set(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
1094b4b2478SJim Ingham   else
1104b4b2478SJim Ingham     GetFlags().Clear(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
1114b4b2478SJim Ingham }
1124b4b2478SJim Ingham 
113b9c1b51eSKate Stone void ThreadPlanStepInRange::GetDescription(Stream *s,
114b9c1b51eSKate Stone                                            lldb::DescriptionLevel level) {
115b9c1b51eSKate Stone   if (level == lldb::eDescriptionLevelBrief) {
1162bdbfd50SJim Ingham     s->Printf("step in");
1172bdbfd50SJim Ingham     return;
1182bdbfd50SJim Ingham   }
1192bdbfd50SJim Ingham 
1202bdbfd50SJim Ingham   s->Printf("Stepping in");
1212bdbfd50SJim Ingham   bool printed_line_info = false;
122b9c1b51eSKate Stone   if (m_addr_context.line_entry.IsValid()) {
1232bdbfd50SJim Ingham     s->Printf(" through line ");
1242bdbfd50SJim Ingham     m_addr_context.line_entry.DumpStopContext(s, false);
1252bdbfd50SJim Ingham     printed_line_info = true;
1262bdbfd50SJim Ingham   }
1272bdbfd50SJim Ingham 
1284d56e9c1SJim Ingham   const char *step_into_target = m_step_into_target.AsCString();
1294d56e9c1SJim Ingham   if (step_into_target && step_into_target[0] != '\0')
1302bdbfd50SJim Ingham     s->Printf(" targeting %s", m_step_into_target.AsCString());
1312bdbfd50SJim Ingham 
132b9c1b51eSKate Stone   if (!printed_line_info || level == eDescriptionLevelVerbose) {
1332bdbfd50SJim Ingham     s->Printf(" using ranges:");
1342bdbfd50SJim Ingham     DumpRanges(s);
13530fdc8d8SChris Lattner   }
1362bdbfd50SJim Ingham 
1372bdbfd50SJim Ingham   s->PutChar('.');
13830fdc8d8SChris Lattner }
13930fdc8d8SChris Lattner 
140b9c1b51eSKate Stone bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) {
1415160ce5cSGreg Clayton   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
14230fdc8d8SChris Lattner 
143b9c1b51eSKate Stone   if (log) {
14430fdc8d8SChris Lattner     StreamString s;
145b9c1b51eSKate Stone     s.Address(
146b9c1b51eSKate Stone         m_thread.GetRegisterContext()->GetPC(),
1471ac04c30SGreg Clayton         m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
14830fdc8d8SChris Lattner     log->Printf("ThreadPlanStepInRange reached %s.", s.GetData());
14930fdc8d8SChris Lattner   }
15030fdc8d8SChris Lattner 
15125f66700SJim Ingham   if (IsPlanComplete())
15225f66700SJim Ingham     return true;
15325f66700SJim Ingham 
1544d56e9c1SJim Ingham   m_no_more_plans = false;
155b9c1b51eSKate Stone   if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete()) {
156b9c1b51eSKate Stone     if (!m_sub_plan_sp->PlanSucceeded()) {
1574d56e9c1SJim Ingham       SetPlanComplete();
1584d56e9c1SJim Ingham       m_no_more_plans = true;
1594d56e9c1SJim Ingham       return true;
160b9c1b51eSKate Stone     } else
1614d56e9c1SJim Ingham       m_sub_plan_sp.reset();
1624d56e9c1SJim Ingham   }
16330fdc8d8SChris Lattner 
164b9c1b51eSKate Stone   if (m_virtual_step) {
165b9c1b51eSKate Stone     // If we've just completed a virtual step, all we need to do is check for a
16605097246SAdrian Prantl     // ShouldStopHere plan, and otherwise we're done.
167b9c1b51eSKate Stone     // FIXME - This can be both a step in and a step out.  Probably should
168b9c1b51eSKate Stone     // record which in the m_virtual_step.
1694b4b2478SJim Ingham     m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger);
170b9c1b51eSKate Stone   } else {
171b9c1b51eSKate Stone     // Stepping through should be done running other threads in general, since
17205097246SAdrian Prantl     // we're setting a breakpoint and continuing.  So only stop others if we
17305097246SAdrian Prantl     // are explicitly told to do so.
1749d790c5dSJim Ingham 
175e65b2cf2SEugene Zelenko     bool stop_others = (m_stop_others == lldb::eOnlyThisThread);
17630fdc8d8SChris Lattner 
177b5c0d1ccSJim Ingham     FrameComparison frame_order = CompareCurrentFrameToStartFrame();
178b5c0d1ccSJim Ingham 
179b9c1b51eSKate Stone     if (frame_order == eFrameCompareOlder ||
180b9c1b51eSKate Stone         frame_order == eFrameCompareSameParent) {
1815822173bSJim Ingham       // If we're in an older frame then we should stop.
1825822173bSJim Ingham       //
183b9c1b51eSKate Stone       // A caveat to this is if we think the frame is older but we're actually
184b9c1b51eSKate Stone       // in a trampoline.
185b9c1b51eSKate Stone       // I'm going to make the assumption that you wouldn't RETURN to a
18605097246SAdrian Prantl       // trampoline.  So if we are in a trampoline we think the frame is older
18705097246SAdrian Prantl       // because the trampoline confused the backtracer.
188b9c1b51eSKate Stone       m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough(m_stack_id, false,
189b9c1b51eSKate Stone                                                              stop_others);
190b9c1b51eSKate Stone       if (!m_sub_plan_sp) {
1914b4b2478SJim Ingham         // Otherwise check the ShouldStopHere for step out:
192862d1bbdSJim Ingham         m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
193a4bb80b2SJim Ingham         if (log) {
194a4bb80b2SJim Ingham           if (m_sub_plan_sp)
195a4bb80b2SJim Ingham             log->Printf("ShouldStopHere found plan to step out of this frame.");
196a4bb80b2SJim Ingham           else
197a4bb80b2SJim Ingham             log->Printf("ShouldStopHere no plan to step out of this frame.");
198a4bb80b2SJim Ingham         }
199b9c1b51eSKate Stone       } else if (log) {
200b9c1b51eSKate Stone         log->Printf(
201b9c1b51eSKate Stone             "Thought I stepped out, but in fact arrived at a trampoline.");
2024b4b2478SJim Ingham       }
203b9c1b51eSKate Stone     } else if (frame_order == eFrameCompareEqual && InSymbol()) {
20405097246SAdrian Prantl       // If we are not in a place we should step through, we're done. One
20505097246SAdrian Prantl       // tricky bit here is that some stubs don't push a frame, so we have to
20605097246SAdrian Prantl       // check both the case of a frame that is younger, or the same as this
20705097246SAdrian Prantl       // frame. However, if the frame is the same, and we are still in the
20805097246SAdrian Prantl       // symbol we started in, the we don't need to do this.  This first check
20905097246SAdrian Prantl       // isn't strictly necessary, but it is more efficient.
2105822173bSJim Ingham 
211b9c1b51eSKate Stone       // If we're still in the range, keep going, either by running to the next
21205097246SAdrian Prantl       // branch breakpoint, or by stepping.
213b9c1b51eSKate Stone       if (InRange()) {
214564d8bc2SJim Ingham         SetNextBranchBreakpoint();
215564d8bc2SJim Ingham         return false;
216564d8bc2SJim Ingham       }
217564d8bc2SJim Ingham 
2185822173bSJim Ingham       SetPlanComplete();
219c627682eSJim Ingham       m_no_more_plans = true;
2205822173bSJim Ingham       return true;
2215822173bSJim Ingham     }
2225822173bSJim Ingham 
223b9c1b51eSKate Stone     // If we get to this point, we're not going to use a previously set "next
224b9c1b51eSKate Stone     // branch" breakpoint, so delete it:
225564d8bc2SJim Ingham     ClearNextBranchBreakpoint();
226564d8bc2SJim Ingham 
2275822173bSJim Ingham     // We may have set the plan up above in the FrameIsOlder section:
2285822173bSJim Ingham 
2294d56e9c1SJim Ingham     if (!m_sub_plan_sp)
230b9c1b51eSKate Stone       m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough(m_stack_id, false,
231b9c1b51eSKate Stone                                                              stop_others);
23208b87e0dSJim Ingham 
233b9c1b51eSKate Stone     if (log) {
2344d56e9c1SJim Ingham       if (m_sub_plan_sp)
2354d56e9c1SJim Ingham         log->Printf("Found a step through plan: %s", m_sub_plan_sp->GetName());
23608b87e0dSJim Ingham       else
23708b87e0dSJim Ingham         log->Printf("No step through plan found.");
23808b87e0dSJim Ingham     }
23908b87e0dSJim Ingham 
24005097246SAdrian Prantl     // If not, give the "should_stop" callback a chance to push a plan to get
24105097246SAdrian Prantl     // us out of here. But only do that if we actually have stepped in.
2424d56e9c1SJim Ingham     if (!m_sub_plan_sp && frame_order == eFrameCompareYounger)
2434b4b2478SJim Ingham       m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
24430fdc8d8SChris Lattner 
245b9c1b51eSKate Stone     // If we've stepped in and we are going to stop here, check to see if we
24605097246SAdrian Prantl     // were asked to run past the prologue, and if so do that.
2477ce490c6SJim Ingham 
248b9c1b51eSKate Stone     if (!m_sub_plan_sp && frame_order == eFrameCompareYounger &&
249b9c1b51eSKate Stone         m_step_past_prologue) {
250b57e4a1bSJason Molenda       lldb::StackFrameSP curr_frame = m_thread.GetStackFrameAtIndex(0);
251b9c1b51eSKate Stone       if (curr_frame) {
2527ce490c6SJim Ingham         size_t bytes_to_skip = 0;
2537ce490c6SJim Ingham         lldb::addr_t curr_addr = m_thread.GetRegisterContext()->GetPC();
2547ce490c6SJim Ingham         Address func_start_address;
2557ce490c6SJim Ingham 
256b9c1b51eSKate Stone         SymbolContext sc = curr_frame->GetSymbolContext(eSymbolContextFunction |
257b9c1b51eSKate Stone                                                         eSymbolContextSymbol);
2587ce490c6SJim Ingham 
259b9c1b51eSKate Stone         if (sc.function) {
2607ce490c6SJim Ingham           func_start_address = sc.function->GetAddressRange().GetBaseAddress();
261b9c1b51eSKate Stone           if (curr_addr ==
262b9c1b51eSKate Stone               func_start_address.GetLoadAddress(
263b9c1b51eSKate Stone                   m_thread.CalculateTarget().get()))
2647ce490c6SJim Ingham             bytes_to_skip = sc.function->GetPrologueByteSize();
265b9c1b51eSKate Stone         } else if (sc.symbol) {
266e7612134SGreg Clayton           func_start_address = sc.symbol->GetAddress();
267b9c1b51eSKate Stone           if (curr_addr ==
268b9c1b51eSKate Stone               func_start_address.GetLoadAddress(
269b9c1b51eSKate Stone                   m_thread.CalculateTarget().get()))
2707ce490c6SJim Ingham             bytes_to_skip = sc.symbol->GetPrologueByteSize();
2717ce490c6SJim Ingham         }
2727ce490c6SJim Ingham 
27308581263SJim Ingham         if (bytes_to_skip == 0 && sc.symbol) {
27408581263SJim Ingham           TargetSP target = m_thread.CalculateTarget();
275*3da0f218STatyana Krasnukha           const Architecture *arch = target->GetArchitecturePlugin();
27608581263SJim Ingham           if (arch) {
27708581263SJim Ingham             Address curr_sec_addr;
27808581263SJim Ingham             target->GetSectionLoadList().ResolveLoadAddress(curr_addr,
27908581263SJim Ingham                                                             curr_sec_addr);
28008581263SJim Ingham             bytes_to_skip = arch->GetBytesToSkip(*sc.symbol, curr_sec_addr);
28108581263SJim Ingham           }
28208581263SJim Ingham         }
28308581263SJim Ingham 
284b9c1b51eSKate Stone         if (bytes_to_skip != 0) {
2857ce490c6SJim Ingham           func_start_address.Slide(bytes_to_skip);
28620ad3c40SCaroline Tice           log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP);
2877ce490c6SJim Ingham           if (log)
2887ce490c6SJim Ingham             log->Printf("Pushing past prologue ");
2897ce490c6SJim Ingham 
290b9c1b51eSKate Stone           m_sub_plan_sp = m_thread.QueueThreadPlanForRunToAddress(
291b9c1b51eSKate Stone               false, func_start_address, true);
2927ce490c6SJim Ingham         }
2937ce490c6SJim Ingham       }
2947ce490c6SJim Ingham     }
295f02a2e96SJim Ingham   }
2967ce490c6SJim Ingham 
297b9c1b51eSKate Stone   if (!m_sub_plan_sp) {
29830fdc8d8SChris Lattner     m_no_more_plans = true;
29930fdc8d8SChris Lattner     SetPlanComplete();
30030fdc8d8SChris Lattner     return true;
301b9c1b51eSKate Stone   } else {
30230fdc8d8SChris Lattner     m_no_more_plans = false;
3032bdbfd50SJim Ingham     m_sub_plan_sp->SetPrivate(true);
30430fdc8d8SChris Lattner     return false;
30530fdc8d8SChris Lattner   }
30630fdc8d8SChris Lattner }
30730fdc8d8SChris Lattner 
308b9c1b51eSKate Stone void ThreadPlanStepInRange::SetAvoidRegexp(const char *name) {
30995eae423SZachary Turner   auto name_ref = llvm::StringRef::withNullAsEmpty(name);
310e65b2cf2SEugene Zelenko   if (!m_avoid_regexp_ap)
31195eae423SZachary Turner     m_avoid_regexp_ap.reset(new RegularExpression(name_ref));
312a56c8006SJim Ingham 
31395eae423SZachary Turner   m_avoid_regexp_ap->Compile(name_ref);
314a56c8006SJim Ingham }
315a56c8006SJim Ingham 
316b9c1b51eSKate Stone void ThreadPlanStepInRange::SetDefaultFlagValue(uint32_t new_value) {
31730fdc8d8SChris Lattner   // TODO: Should we test this for sanity?
31830fdc8d8SChris Lattner   ThreadPlanStepInRange::s_default_flag_values = new_value;
31930fdc8d8SChris Lattner }
32030fdc8d8SChris Lattner 
321b9c1b51eSKate Stone bool ThreadPlanStepInRange::FrameMatchesAvoidCriteria() {
322b57e4a1bSJason Molenda   StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
323a56c8006SJim Ingham 
3244da6206dSJim Ingham   // Check the library list first, as that's cheapest:
325a786e539SJim Ingham   bool libraries_say_avoid = false;
326a786e539SJim Ingham 
3274da6206dSJim Ingham   FileSpecList libraries_to_avoid(GetThread().GetLibrariesToAvoid());
3284da6206dSJim Ingham   size_t num_libraries = libraries_to_avoid.GetSize();
329b9c1b51eSKate Stone   if (num_libraries > 0) {
3304da6206dSJim Ingham     SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
3314da6206dSJim Ingham     FileSpec frame_library(sc.module_sp->GetFileSpec());
3324da6206dSJim Ingham 
333b9c1b51eSKate Stone     if (frame_library) {
334b9c1b51eSKate Stone       for (size_t i = 0; i < num_libraries; i++) {
3354da6206dSJim Ingham         const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
336b9c1b51eSKate Stone         if (FileSpec::Equal(file_spec, frame_library, false)) {
3374da6206dSJim Ingham           libraries_say_avoid = true;
3384da6206dSJim Ingham           break;
3394da6206dSJim Ingham         }
3404da6206dSJim Ingham       }
3414da6206dSJim Ingham     }
342a786e539SJim Ingham   }
3434da6206dSJim Ingham   if (libraries_say_avoid)
3444da6206dSJim Ingham     return true;
3454da6206dSJim Ingham 
34667cc0636SGreg Clayton   const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get();
347e65b2cf2SEugene Zelenko   if (avoid_regexp_to_use == nullptr)
348ee8aea10SJim Ingham     avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
349ee8aea10SJim Ingham 
350b9c1b51eSKate Stone   if (avoid_regexp_to_use != nullptr) {
351b9c1b51eSKate Stone     SymbolContext sc = frame->GetSymbolContext(
352b9c1b51eSKate Stone         eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
353b9c1b51eSKate Stone     if (sc.symbol != nullptr) {
354b9c1b51eSKate Stone       const char *frame_function_name =
355b9c1b51eSKate Stone           sc.GetFunctionName(Mangled::ePreferDemangledWithoutArguments)
356b9c1b51eSKate Stone               .GetCString();
357b9c1b51eSKate Stone       if (frame_function_name) {
358cf2667c4SJim Ingham         size_t num_matches = 0;
3595160ce5cSGreg Clayton         Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
3603101ba33SJim Ingham         if (log)
361cf2667c4SJim Ingham           num_matches = 1;
362bc43cab5SGreg Clayton 
363bc43cab5SGreg Clayton         RegularExpression::Match regex_match(num_matches);
364bc43cab5SGreg Clayton 
365b9c1b51eSKate Stone         bool return_value =
366b9c1b51eSKate Stone             avoid_regexp_to_use->Execute(frame_function_name, &regex_match);
367b9c1b51eSKate Stone         if (return_value) {
368b9c1b51eSKate Stone           if (log) {
369cf2667c4SJim Ingham             std::string match;
370bc43cab5SGreg Clayton             regex_match.GetMatchAtIndex(frame_function_name, 0, match);
371b9c1b51eSKate Stone             log->Printf("Stepping out of function \"%s\" because it matches "
372b9c1b51eSKate Stone                         "the avoid regexp \"%s\" - match substring: \"%s\".",
37395eae423SZachary Turner                         frame_function_name,
37495eae423SZachary Turner                         avoid_regexp_to_use->GetText().str().c_str(),
375cf2667c4SJim Ingham                         match.c_str());
376cf2667c4SJim Ingham           }
3773101ba33SJim Ingham         }
3783101ba33SJim Ingham         return return_value;
3793101ba33SJim Ingham       }
380a56c8006SJim Ingham     }
381a56c8006SJim Ingham   }
382a56c8006SJim Ingham   return false;
383a56c8006SJim Ingham }
384a56c8006SJim Ingham 
385b9c1b51eSKate Stone bool ThreadPlanStepInRange::DefaultShouldStopHereCallback(
386b9c1b51eSKate Stone     ThreadPlan *current_plan, Flags &flags, FrameComparison operation,
387b9c1b51eSKate Stone     void *baton) {
3884b4b2478SJim Ingham   bool should_stop_here = true;
389b57e4a1bSJason Molenda   StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
3905160ce5cSGreg Clayton   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
39130fdc8d8SChris Lattner 
392b9c1b51eSKate Stone   // First see if the ThreadPlanShouldStopHere default implementation thinks we
393b9c1b51eSKate Stone   // should get out of here:
394b9c1b51eSKate Stone   should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback(
395b9c1b51eSKate Stone       current_plan, flags, operation, baton);
3960c2b9d2aSJim Ingham   if (!should_stop_here)
3970c2b9d2aSJim Ingham     return should_stop_here;
398a56c8006SJim Ingham 
399b9c1b51eSKate Stone   if (should_stop_here && current_plan->GetKind() == eKindStepInRange &&
400b9c1b51eSKate Stone       operation == eFrameCompareYounger) {
401b9c1b51eSKate Stone     ThreadPlanStepInRange *step_in_range_plan =
402b9c1b51eSKate Stone         static_cast<ThreadPlanStepInRange *>(current_plan);
403b9c1b51eSKate Stone     if (step_in_range_plan->m_step_into_target) {
404b9c1b51eSKate Stone       SymbolContext sc = frame->GetSymbolContext(
405b9c1b51eSKate Stone           eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
406b9c1b51eSKate Stone       if (sc.symbol != nullptr) {
40705097246SAdrian Prantl         // First try an exact match, since that's cheap with ConstStrings.
40805097246SAdrian Prantl         // Then do a strstr compare.
409b9c1b51eSKate Stone         if (step_in_range_plan->m_step_into_target == sc.GetFunctionName()) {
4104b4b2478SJim Ingham           should_stop_here = true;
411b9c1b51eSKate Stone         } else {
412b9c1b51eSKate Stone           const char *target_name =
413b9c1b51eSKate Stone               step_in_range_plan->m_step_into_target.AsCString();
414c627682eSJim Ingham           const char *function_name = sc.GetFunctionName().AsCString();
415c627682eSJim Ingham 
416e65b2cf2SEugene Zelenko           if (function_name == nullptr)
4174b4b2478SJim Ingham             should_stop_here = false;
418e65b2cf2SEugene Zelenko           else if (strstr(function_name, target_name) == nullptr)
4194b4b2478SJim Ingham             should_stop_here = false;
420c627682eSJim Ingham         }
4214b4b2478SJim Ingham         if (log && !should_stop_here)
422b9c1b51eSKate Stone           log->Printf("Stepping out of frame %s which did not match step into "
423b9c1b51eSKate Stone                       "target %s.",
4243101ba33SJim Ingham                       sc.GetFunctionName().AsCString(),
4253101ba33SJim Ingham                       step_in_range_plan->m_step_into_target.AsCString());
426c627682eSJim Ingham       }
427c627682eSJim Ingham     }
428c627682eSJim Ingham 
429b9c1b51eSKate Stone     if (should_stop_here) {
430b9c1b51eSKate Stone       ThreadPlanStepInRange *step_in_range_plan =
431b9c1b51eSKate Stone           static_cast<ThreadPlanStepInRange *>(current_plan);
432b9c1b51eSKate Stone       // Don't log the should_step_out here, it's easier to do it in
433b9c1b51eSKate Stone       // FrameMatchesAvoidCriteria.
4344b4b2478SJim Ingham       should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria();
435a56c8006SJim Ingham     }
436a56c8006SJim Ingham   }
437a56c8006SJim Ingham 
4384b4b2478SJim Ingham   return should_stop_here;
43930fdc8d8SChris Lattner }
440fbbfe6ecSJim Ingham 
441b9c1b51eSKate Stone bool ThreadPlanStepInRange::DoPlanExplainsStop(Event *event_ptr) {
442fbbfe6ecSJim Ingham   // We always explain a stop.  Either we've just done a single step, in which
44305097246SAdrian Prantl   // case we'll do our ordinary processing, or we stopped for some reason that
44405097246SAdrian Prantl   // isn't handled by our sub-plans, in which case we want to just stop right
44505097246SAdrian Prantl   // away. In general, we don't want to mark the plan as complete for
44605097246SAdrian Prantl   // unexplained stops. For instance, if you step in to some code with no debug
44705097246SAdrian Prantl   // info, so you step out and in the course of that hit a breakpoint, then you
44805097246SAdrian Prantl   // want to stop & show the user the breakpoint, but not unship the step in
44905097246SAdrian Prantl   // plan, since you still may want to complete that plan when you continue.
45005097246SAdrian Prantl   // This is particularly true when doing "step in to target function."
451c627682eSJim Ingham   // stepping.
452fbbfe6ecSJim Ingham   //
45305097246SAdrian Prantl   // The only variation is that if we are doing "step by running to next
45405097246SAdrian Prantl   // branch" in which case if we hit our branch breakpoint we don't set the
45505097246SAdrian Prantl   // plan to complete.
456fbbfe6ecSJim Ingham 
4579b03fa0cSJim Ingham   bool return_value = false;
458f02a2e96SJim Ingham 
459b9c1b51eSKate Stone   if (m_virtual_step) {
460221d51cfSJim Ingham     return_value = true;
461b9c1b51eSKate Stone   } else {
46260c4118cSJim Ingham     StopInfoSP stop_info_sp = GetPrivateStopInfo();
463b9c1b51eSKate Stone     if (stop_info_sp) {
464fbbfe6ecSJim Ingham       StopReason reason = stop_info_sp->GetStopReason();
465fbbfe6ecSJim Ingham 
466b9c1b51eSKate Stone       if (reason == eStopReasonBreakpoint) {
467b9c1b51eSKate Stone         if (NextRangeBreakpointExplainsStop(stop_info_sp)) {
468221d51cfSJim Ingham           return_value = true;
469221d51cfSJim Ingham         }
470b9c1b51eSKate Stone       } else if (IsUsuallyUnexplainedStopReason(reason)) {
4715160ce5cSGreg Clayton         Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
472fbbfe6ecSJim Ingham         if (log)
473b9c1b51eSKate Stone           log->PutCString("ThreadPlanStepInRange got asked if it explains the "
474b9c1b51eSKate Stone                           "stop for some reason other than step.");
475221d51cfSJim Ingham         return_value = false;
476b9c1b51eSKate Stone       } else {
477221d51cfSJim Ingham         return_value = true;
478fbbfe6ecSJim Ingham       }
479b9c1b51eSKate Stone     } else
480221d51cfSJim Ingham       return_value = true;
481221d51cfSJim Ingham   }
482221d51cfSJim Ingham 
483221d51cfSJim Ingham   return return_value;
484fbbfe6ecSJim Ingham }
485513c6bb8SJim Ingham 
486b9c1b51eSKate Stone bool ThreadPlanStepInRange::DoWillResume(lldb::StateType resume_state,
487b9c1b51eSKate Stone                                          bool current_plan) {
48869fc298aSTamas Berghammer   m_virtual_step = false;
489b9c1b51eSKate Stone   if (resume_state == eStateStepping && current_plan) {
490513c6bb8SJim Ingham     // See if we are about to step over a virtual inlined call.
491513c6bb8SJim Ingham     bool step_without_resume = m_thread.DecrementCurrentInlinedDepth();
492b9c1b51eSKate Stone     if (step_without_resume) {
4935160ce5cSGreg Clayton       Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
494513c6bb8SJim Ingham       if (log)
495b9c1b51eSKate Stone         log->Printf("ThreadPlanStepInRange::DoWillResume: returning false, "
496b9c1b51eSKate Stone                     "inline_depth: %d",
497513c6bb8SJim Ingham                     m_thread.GetCurrentInlinedDepth());
498513c6bb8SJim Ingham       SetStopInfo(StopInfo::CreateStopReasonToTrace(m_thread));
499f02a2e96SJim Ingham 
500b9c1b51eSKate Stone       // FIXME: Maybe it would be better to create a InlineStep stop reason, but
501b9c1b51eSKate Stone       // then
502f02a2e96SJim Ingham       // the whole rest of the world would have to handle that stop reason.
503f02a2e96SJim Ingham       m_virtual_step = true;
504513c6bb8SJim Ingham     }
505513c6bb8SJim Ingham     return !step_without_resume;
506513c6bb8SJim Ingham   }
507221d51cfSJim Ingham   return true;
508513c6bb8SJim Ingham }
509246cb611SDaniel Malea 
510b9c1b51eSKate Stone bool ThreadPlanStepInRange::IsVirtualStep() { return m_virtual_step; }
511