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 #include "lldb/Target/ThreadPlanStepInRange.h"
1130fdc8d8SChris Lattner 
1230fdc8d8SChris Lattner // C Includes
1330fdc8d8SChris Lattner // C++ Includes
1430fdc8d8SChris Lattner // Other libraries and framework includes
1530fdc8d8SChris Lattner // Project includes
1630fdc8d8SChris Lattner 
1730fdc8d8SChris Lattner #include "lldb/lldb-private-log.h"
1830fdc8d8SChris Lattner #include "lldb/Core/Log.h"
194da6206dSJim Ingham #include "lldb/Core/Module.h"
2030fdc8d8SChris Lattner #include "lldb/Core/Stream.h"
21a56c8006SJim Ingham #include "lldb/Symbol/Symbol.h"
227ce490c6SJim Ingham #include "lldb/Symbol/Function.h"
2330fdc8d8SChris Lattner #include "lldb/Target/Process.h"
2430fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.h"
25514487e8SGreg Clayton #include "lldb/Target/Target.h"
2630fdc8d8SChris Lattner #include "lldb/Target/Thread.h"
2730fdc8d8SChris Lattner #include "lldb/Target/ThreadPlanStepOut.h"
2830fdc8d8SChris Lattner #include "lldb/Target/ThreadPlanStepThrough.h"
29a56c8006SJim Ingham #include "lldb/Core/RegularExpression.h"
3030fdc8d8SChris Lattner 
3130fdc8d8SChris Lattner using namespace lldb;
3230fdc8d8SChris Lattner using namespace lldb_private;
3330fdc8d8SChris Lattner 
344b4b2478SJim Ingham uint32_t ThreadPlanStepInRange::s_default_flag_values = ThreadPlanShouldStopHere::eStepInAvoidNoDebug;
3530fdc8d8SChris Lattner 
3630fdc8d8SChris Lattner //----------------------------------------------------------------------
3730fdc8d8SChris Lattner // ThreadPlanStepInRange: Step through a stack range, either stepping over or into
3830fdc8d8SChris Lattner // based on the value of \a type.
3930fdc8d8SChris Lattner //----------------------------------------------------------------------
4030fdc8d8SChris Lattner 
4130fdc8d8SChris Lattner ThreadPlanStepInRange::ThreadPlanStepInRange
4230fdc8d8SChris Lattner (
4330fdc8d8SChris Lattner     Thread &thread,
4430fdc8d8SChris Lattner     const AddressRange &range,
4530fdc8d8SChris Lattner     const SymbolContext &addr_context,
464b4b2478SJim Ingham     lldb::RunMode stop_others,
474b4b2478SJim Ingham     LazyBool step_in_avoids_code_without_debug_info,
484b4b2478SJim Ingham     LazyBool step_out_avoids_code_without_debug_info
4930fdc8d8SChris Lattner ) :
50b01e742aSJim Ingham     ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others),
514b4b2478SJim Ingham     ThreadPlanShouldStopHere (this),
52f02a2e96SJim Ingham     m_step_past_prologue (true),
53f02a2e96SJim Ingham     m_virtual_step (false)
5430fdc8d8SChris Lattner {
554b4b2478SJim Ingham     SetCallbacks();
5630fdc8d8SChris Lattner     SetFlagsToDefault ();
574b4b2478SJim Ingham     SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info);
5830fdc8d8SChris Lattner }
5930fdc8d8SChris Lattner 
60c627682eSJim Ingham ThreadPlanStepInRange::ThreadPlanStepInRange
61c627682eSJim Ingham (
62c627682eSJim Ingham     Thread &thread,
63c627682eSJim Ingham     const AddressRange &range,
64c627682eSJim Ingham     const SymbolContext &addr_context,
65c627682eSJim Ingham     const char *step_into_target,
664b4b2478SJim Ingham     lldb::RunMode stop_others,
674b4b2478SJim Ingham     LazyBool step_in_avoids_code_without_debug_info,
684b4b2478SJim Ingham     LazyBool step_out_avoids_code_without_debug_info
69c627682eSJim Ingham ) :
70c627682eSJim Ingham     ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others),
714b4b2478SJim Ingham     ThreadPlanShouldStopHere (this),
72c627682eSJim Ingham     m_step_past_prologue (true),
73c627682eSJim Ingham     m_virtual_step (false),
74c627682eSJim Ingham     m_step_into_target (step_into_target)
75c627682eSJim Ingham {
764b4b2478SJim Ingham     SetCallbacks();
77c627682eSJim Ingham     SetFlagsToDefault ();
784b4b2478SJim Ingham     SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info);
79c627682eSJim Ingham }
80c627682eSJim Ingham 
8130fdc8d8SChris Lattner ThreadPlanStepInRange::~ThreadPlanStepInRange ()
8230fdc8d8SChris Lattner {
8330fdc8d8SChris Lattner }
8430fdc8d8SChris Lattner 
8530fdc8d8SChris Lattner void
864b4b2478SJim Ingham ThreadPlanStepInRange::SetupAvoidNoDebug(LazyBool step_in_avoids_code_without_debug_info,
874b4b2478SJim Ingham                                          LazyBool step_out_avoids_code_without_debug_info)
884b4b2478SJim Ingham {
894b4b2478SJim Ingham     bool avoid_nodebug = true;
904b4b2478SJim Ingham 
914b4b2478SJim Ingham     switch (step_in_avoids_code_without_debug_info)
924b4b2478SJim Ingham     {
934b4b2478SJim Ingham         case eLazyBoolYes:
944b4b2478SJim Ingham             avoid_nodebug = true;
954b4b2478SJim Ingham             break;
964b4b2478SJim Ingham         case eLazyBoolNo:
974b4b2478SJim Ingham             avoid_nodebug = false;
984b4b2478SJim Ingham             break;
994b4b2478SJim Ingham         case eLazyBoolCalculate:
1004b4b2478SJim Ingham             avoid_nodebug = m_thread.GetStepInAvoidsNoDebug();
1014b4b2478SJim Ingham             break;
1024b4b2478SJim Ingham     }
1034b4b2478SJim Ingham     if (avoid_nodebug)
1044b4b2478SJim Ingham         GetFlags().Set (ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
1054b4b2478SJim Ingham     else
1064b4b2478SJim Ingham         GetFlags().Clear (ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
1074b4b2478SJim Ingham 
1084b4b2478SJim Ingham     avoid_nodebug = true;
1094b4b2478SJim Ingham     switch (step_out_avoids_code_without_debug_info)
1104b4b2478SJim Ingham     {
1114b4b2478SJim Ingham         case eLazyBoolYes:
1124b4b2478SJim Ingham             avoid_nodebug = true;
1134b4b2478SJim Ingham             break;
1144b4b2478SJim Ingham         case eLazyBoolNo:
1154b4b2478SJim Ingham             avoid_nodebug = false;
1164b4b2478SJim Ingham             break;
1174b4b2478SJim Ingham         case eLazyBoolCalculate:
1184b4b2478SJim Ingham             avoid_nodebug = m_thread.GetStepOutAvoidsNoDebug();
1194b4b2478SJim Ingham             break;
1204b4b2478SJim Ingham     }
1214b4b2478SJim Ingham     if (avoid_nodebug)
1224b4b2478SJim Ingham         GetFlags().Set (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
1234b4b2478SJim Ingham     else
1244b4b2478SJim Ingham         GetFlags().Clear (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
1254b4b2478SJim Ingham }
1264b4b2478SJim Ingham 
1274b4b2478SJim Ingham void
12830fdc8d8SChris Lattner ThreadPlanStepInRange::GetDescription (Stream *s, lldb::DescriptionLevel level)
12930fdc8d8SChris Lattner {
13030fdc8d8SChris Lattner     if (level == lldb::eDescriptionLevelBrief)
13130fdc8d8SChris Lattner     {
132*2bdbfd50SJim Ingham         s->Printf("step in");
133*2bdbfd50SJim Ingham         return;
134*2bdbfd50SJim Ingham     }
135*2bdbfd50SJim Ingham 
136*2bdbfd50SJim Ingham     s->Printf ("Stepping in");
137*2bdbfd50SJim Ingham     bool printed_line_info = false;
138*2bdbfd50SJim Ingham     if (m_addr_context.line_entry.IsValid())
139*2bdbfd50SJim Ingham     {
140*2bdbfd50SJim Ingham         s->Printf (" through line ");
141*2bdbfd50SJim Ingham         m_addr_context.line_entry.DumpStopContext (s, false);
142*2bdbfd50SJim Ingham         printed_line_info = true;
143*2bdbfd50SJim Ingham     }
144*2bdbfd50SJim Ingham 
1454d56e9c1SJim Ingham     const char *step_into_target = m_step_into_target.AsCString();
1464d56e9c1SJim Ingham     if (step_into_target && step_into_target[0] != '\0')
147*2bdbfd50SJim Ingham         s->Printf (" targeting %s", m_step_into_target.AsCString());
148*2bdbfd50SJim Ingham 
149*2bdbfd50SJim Ingham     if (!printed_line_info || level == eDescriptionLevelVerbose)
150*2bdbfd50SJim Ingham     {
151*2bdbfd50SJim Ingham         s->Printf (" using ranges:");
152*2bdbfd50SJim Ingham         DumpRanges(s);
15330fdc8d8SChris Lattner     }
154*2bdbfd50SJim Ingham 
155*2bdbfd50SJim Ingham     s->PutChar('.');
15630fdc8d8SChris Lattner }
15730fdc8d8SChris Lattner 
15830fdc8d8SChris Lattner bool
15930fdc8d8SChris Lattner ThreadPlanStepInRange::ShouldStop (Event *event_ptr)
16030fdc8d8SChris Lattner {
1615160ce5cSGreg Clayton     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
16230fdc8d8SChris Lattner 
16330fdc8d8SChris Lattner     if (log)
16430fdc8d8SChris Lattner     {
16530fdc8d8SChris Lattner         StreamString s;
166514487e8SGreg Clayton         s.Address (m_thread.GetRegisterContext()->GetPC(),
1671ac04c30SGreg Clayton                    m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
16830fdc8d8SChris Lattner         log->Printf("ThreadPlanStepInRange reached %s.", s.GetData());
16930fdc8d8SChris Lattner     }
17030fdc8d8SChris Lattner 
17125f66700SJim Ingham     if (IsPlanComplete())
17225f66700SJim Ingham         return true;
17325f66700SJim Ingham 
1744d56e9c1SJim Ingham     m_no_more_plans = false;
1754d56e9c1SJim Ingham     if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete())
1764d56e9c1SJim Ingham     {
1774d56e9c1SJim Ingham         if (!m_sub_plan_sp->PlanSucceeded())
1784d56e9c1SJim Ingham         {
1794d56e9c1SJim Ingham             SetPlanComplete();
1804d56e9c1SJim Ingham             m_no_more_plans = true;
1814d56e9c1SJim Ingham             return true;
1824d56e9c1SJim Ingham         }
1834d56e9c1SJim Ingham         else
1844d56e9c1SJim Ingham             m_sub_plan_sp.reset();
1854d56e9c1SJim Ingham     }
18630fdc8d8SChris Lattner 
187f02a2e96SJim Ingham     if (m_virtual_step)
188f02a2e96SJim Ingham     {
189f02a2e96SJim Ingham         // If we've just completed a virtual step, all we need to do is check for a ShouldStopHere plan, and otherwise
190f02a2e96SJim Ingham         // we're done.
1914b4b2478SJim Ingham         // FIXME - This can be both a step in and a step out.  Probably should record which in the m_virtual_step.
1924b4b2478SJim Ingham         m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger);
193f02a2e96SJim Ingham     }
194f02a2e96SJim Ingham     else
195f02a2e96SJim Ingham     {
1964a58e968SJim Ingham         // Stepping through should be done running other threads in general, since we're setting a breakpoint and
1974a58e968SJim Ingham         // continuing.  So only stop others if we are explicitly told to do so.
1989d790c5dSJim Ingham 
19930fdc8d8SChris Lattner         bool stop_others;
2004a58e968SJim Ingham         if (m_stop_others == lldb::eOnlyThisThread)
2014a58e968SJim Ingham             stop_others = true;
2026cf5b8f1SEd Maste         else
2036cf5b8f1SEd Maste             stop_others = false;
20430fdc8d8SChris Lattner 
205b5c0d1ccSJim Ingham         FrameComparison frame_order = CompareCurrentFrameToStartFrame();
206b5c0d1ccSJim Ingham 
207862d1bbdSJim Ingham         if (frame_order == eFrameCompareOlder || frame_order == eFrameCompareSameParent)
2085822173bSJim Ingham         {
2095822173bSJim Ingham             // If we're in an older frame then we should stop.
2105822173bSJim Ingham             //
2115822173bSJim Ingham             // A caveat to this is if we think the frame is older but we're actually in a trampoline.
2125822173bSJim Ingham             // I'm going to make the assumption that you wouldn't RETURN to a trampoline.  So if we are
2135822173bSJim Ingham             // in a trampoline we think the frame is older because the trampoline confused the backtracer.
2144d56e9c1SJim Ingham             m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
2154d56e9c1SJim Ingham             if (!m_sub_plan_sp)
2164b4b2478SJim Ingham             {
2174b4b2478SJim Ingham                 // Otherwise check the ShouldStopHere for step out:
218862d1bbdSJim Ingham                 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
2194b4b2478SJim Ingham                 if (log)
2204b4b2478SJim Ingham                     log->Printf ("ShouldStopHere says we should step out of this frame.");
2214b4b2478SJim Ingham             }
2225822173bSJim Ingham             else if (log)
2235822173bSJim Ingham             {
2245822173bSJim Ingham                 log->Printf("Thought I stepped out, but in fact arrived at a trampoline.");
2255822173bSJim Ingham             }
2265822173bSJim Ingham 
2275822173bSJim Ingham         }
228564d8bc2SJim Ingham         else if (frame_order == eFrameCompareEqual && InSymbol())
2295822173bSJim Ingham         {
2305822173bSJim Ingham             // If we are not in a place we should step through, we're done.
2315822173bSJim Ingham             // One tricky bit here is that some stubs don't push a frame, so we have to check
2325822173bSJim Ingham             // both the case of a frame that is younger, or the same as this frame.
2335822173bSJim Ingham             // However, if the frame is the same, and we are still in the symbol we started
2345822173bSJim Ingham             // in, the we don't need to do this.  This first check isn't strictly necessary,
2355822173bSJim Ingham             // but it is more efficient.
2365822173bSJim Ingham 
237564d8bc2SJim Ingham             // If we're still in the range, keep going, either by running to the next branch breakpoint, or by
238564d8bc2SJim Ingham             // stepping.
239564d8bc2SJim Ingham             if (InRange())
240564d8bc2SJim Ingham             {
241564d8bc2SJim Ingham                 SetNextBranchBreakpoint();
242564d8bc2SJim Ingham                 return false;
243564d8bc2SJim Ingham             }
244564d8bc2SJim Ingham 
2455822173bSJim Ingham             SetPlanComplete();
246c627682eSJim Ingham             m_no_more_plans = true;
2475822173bSJim Ingham             return true;
2485822173bSJim Ingham         }
2495822173bSJim Ingham 
250564d8bc2SJim Ingham         // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it:
251564d8bc2SJim Ingham         ClearNextBranchBreakpoint();
252564d8bc2SJim Ingham 
2535822173bSJim Ingham         // We may have set the plan up above in the FrameIsOlder section:
2545822173bSJim Ingham 
2554d56e9c1SJim Ingham         if (!m_sub_plan_sp)
2564d56e9c1SJim Ingham             m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
25708b87e0dSJim Ingham 
25808b87e0dSJim Ingham         if (log)
25908b87e0dSJim Ingham         {
2604d56e9c1SJim Ingham             if (m_sub_plan_sp)
2614d56e9c1SJim Ingham                 log->Printf ("Found a step through plan: %s", m_sub_plan_sp->GetName());
26208b87e0dSJim Ingham             else
26308b87e0dSJim Ingham                 log->Printf ("No step through plan found.");
26408b87e0dSJim Ingham         }
26508b87e0dSJim Ingham 
26630fdc8d8SChris Lattner         // If not, give the "should_stop" callback a chance to push a plan to get us out of here.
26730fdc8d8SChris Lattner         // But only do that if we actually have stepped in.
2684d56e9c1SJim Ingham         if (!m_sub_plan_sp && frame_order == eFrameCompareYounger)
2694b4b2478SJim Ingham             m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
27030fdc8d8SChris Lattner 
2717ce490c6SJim Ingham         // If we've stepped in and we are going to stop here, check to see if we were asked to
2727ce490c6SJim Ingham         // run past the prologue, and if so do that.
2737ce490c6SJim Ingham 
2744d56e9c1SJim Ingham         if (!m_sub_plan_sp && frame_order == eFrameCompareYounger && m_step_past_prologue)
2757ce490c6SJim Ingham         {
276b57e4a1bSJason Molenda             lldb::StackFrameSP curr_frame = m_thread.GetStackFrameAtIndex(0);
2777ce490c6SJim Ingham             if (curr_frame)
2787ce490c6SJim Ingham             {
2797ce490c6SJim Ingham                 size_t bytes_to_skip = 0;
2807ce490c6SJim Ingham                 lldb::addr_t curr_addr = m_thread.GetRegisterContext()->GetPC();
2817ce490c6SJim Ingham                 Address func_start_address;
2827ce490c6SJim Ingham 
2837ce490c6SJim Ingham                 SymbolContext sc = curr_frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextSymbol);
2847ce490c6SJim Ingham 
2857ce490c6SJim Ingham                 if (sc.function)
2867ce490c6SJim Ingham                 {
2877ce490c6SJim Ingham                     func_start_address = sc.function->GetAddressRange().GetBaseAddress();
288d9e416c0SGreg Clayton                     if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
2897ce490c6SJim Ingham                         bytes_to_skip = sc.function->GetPrologueByteSize();
2907ce490c6SJim Ingham                 }
2917ce490c6SJim Ingham                 else if (sc.symbol)
2927ce490c6SJim Ingham                 {
293e7612134SGreg Clayton                     func_start_address = sc.symbol->GetAddress();
294d9e416c0SGreg Clayton                     if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
2957ce490c6SJim Ingham                         bytes_to_skip = sc.symbol->GetPrologueByteSize();
2967ce490c6SJim Ingham                 }
2977ce490c6SJim Ingham 
2987ce490c6SJim Ingham                 if (bytes_to_skip != 0)
2997ce490c6SJim Ingham                 {
3007ce490c6SJim Ingham                     func_start_address.Slide (bytes_to_skip);
30120ad3c40SCaroline Tice                     log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
3027ce490c6SJim Ingham                     if (log)
3037ce490c6SJim Ingham                         log->Printf ("Pushing past prologue ");
3047ce490c6SJim Ingham 
3054d56e9c1SJim Ingham                     m_sub_plan_sp = m_thread.QueueThreadPlanForRunToAddress(false, func_start_address,true);
3067ce490c6SJim Ingham                 }
3077ce490c6SJim Ingham             }
3087ce490c6SJim Ingham         }
309f02a2e96SJim Ingham      }
3107ce490c6SJim Ingham 
3114d56e9c1SJim Ingham      if (!m_sub_plan_sp)
31230fdc8d8SChris Lattner      {
31330fdc8d8SChris Lattner         m_no_more_plans = true;
31430fdc8d8SChris Lattner         SetPlanComplete();
31530fdc8d8SChris Lattner         return true;
31630fdc8d8SChris Lattner     }
31730fdc8d8SChris Lattner     else
31830fdc8d8SChris Lattner     {
31930fdc8d8SChris Lattner         m_no_more_plans = false;
320*2bdbfd50SJim Ingham         m_sub_plan_sp->SetPrivate(true);
32130fdc8d8SChris Lattner         return false;
32230fdc8d8SChris Lattner     }
32330fdc8d8SChris Lattner }
32430fdc8d8SChris Lattner 
32530fdc8d8SChris Lattner void
326a56c8006SJim Ingham ThreadPlanStepInRange::SetAvoidRegexp(const char *name)
327a56c8006SJim Ingham {
328a56c8006SJim Ingham     if (m_avoid_regexp_ap.get() == NULL)
329a56c8006SJim Ingham         m_avoid_regexp_ap.reset (new RegularExpression(name));
330a56c8006SJim Ingham 
331a56c8006SJim Ingham     m_avoid_regexp_ap->Compile (name);
332a56c8006SJim Ingham }
333a56c8006SJim Ingham 
334a56c8006SJim Ingham void
33530fdc8d8SChris Lattner ThreadPlanStepInRange::SetDefaultFlagValue (uint32_t new_value)
33630fdc8d8SChris Lattner {
33730fdc8d8SChris Lattner     // TODO: Should we test this for sanity?
33830fdc8d8SChris Lattner     ThreadPlanStepInRange::s_default_flag_values = new_value;
33930fdc8d8SChris Lattner }
34030fdc8d8SChris Lattner 
341a56c8006SJim Ingham bool
3424da6206dSJim Ingham ThreadPlanStepInRange::FrameMatchesAvoidCriteria ()
343a56c8006SJim Ingham {
344b57e4a1bSJason Molenda     StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
345a56c8006SJim Ingham 
3464da6206dSJim Ingham     // Check the library list first, as that's cheapest:
347a786e539SJim Ingham     bool libraries_say_avoid = false;
348a786e539SJim Ingham 
3494da6206dSJim Ingham     FileSpecList libraries_to_avoid (GetThread().GetLibrariesToAvoid());
3504da6206dSJim Ingham     size_t num_libraries = libraries_to_avoid.GetSize();
351a786e539SJim Ingham     if (num_libraries > 0)
352a786e539SJim Ingham     {
3534da6206dSJim Ingham         SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
3544da6206dSJim Ingham         FileSpec frame_library(sc.module_sp->GetFileSpec());
3554da6206dSJim Ingham 
3564da6206dSJim Ingham         if (frame_library)
3574da6206dSJim Ingham         {
3584da6206dSJim Ingham             for (size_t i = 0; i < num_libraries; i++)
3594da6206dSJim Ingham             {
3604da6206dSJim Ingham                 const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
3614da6206dSJim Ingham                 if (FileSpec::Equal (file_spec, frame_library, false))
3624da6206dSJim Ingham                 {
3634da6206dSJim Ingham                     libraries_say_avoid = true;
3644da6206dSJim Ingham                     break;
3654da6206dSJim Ingham                 }
3664da6206dSJim Ingham             }
3674da6206dSJim Ingham         }
368a786e539SJim Ingham     }
3694da6206dSJim Ingham     if (libraries_say_avoid)
3704da6206dSJim Ingham         return true;
3714da6206dSJim Ingham 
37267cc0636SGreg Clayton     const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get();
373ee8aea10SJim Ingham     if (avoid_regexp_to_use == NULL)
374ee8aea10SJim Ingham         avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
375ee8aea10SJim Ingham 
376ee8aea10SJim Ingham     if (avoid_regexp_to_use != NULL)
377a56c8006SJim Ingham     {
3784592cbc4SGreg Clayton         SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
379a56c8006SJim Ingham         if (sc.symbol != NULL)
380a56c8006SJim Ingham         {
3814592cbc4SGreg Clayton             const char *frame_function_name = sc.GetFunctionName().GetCString();
3824592cbc4SGreg Clayton             if (frame_function_name)
3833101ba33SJim Ingham             {
384cf2667c4SJim Ingham                 size_t num_matches = 0;
3855160ce5cSGreg Clayton                 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
3863101ba33SJim Ingham                 if (log)
387cf2667c4SJim Ingham                     num_matches = 1;
388bc43cab5SGreg Clayton 
389bc43cab5SGreg Clayton                 RegularExpression::Match regex_match(num_matches);
390bc43cab5SGreg Clayton 
391bc43cab5SGreg Clayton                 bool return_value = avoid_regexp_to_use->Execute(frame_function_name, &regex_match);
392cf2667c4SJim Ingham                 if (return_value)
393cf2667c4SJim Ingham                 {
394cf2667c4SJim Ingham                     if (log)
395cf2667c4SJim Ingham                     {
396cf2667c4SJim Ingham                         std::string match;
397bc43cab5SGreg Clayton                         regex_match.GetMatchAtIndex(frame_function_name,0, match);
398cf2667c4SJim Ingham                         log->Printf ("Stepping out of function \"%s\" because it matches the avoid regexp \"%s\" - match substring: \"%s\".",
3993101ba33SJim Ingham                                      frame_function_name,
400cf2667c4SJim Ingham                                      avoid_regexp_to_use->GetText(),
401cf2667c4SJim Ingham                                      match.c_str());
402cf2667c4SJim Ingham                     }
4033101ba33SJim Ingham 
4043101ba33SJim Ingham                 }
4053101ba33SJim Ingham                 return return_value;
4063101ba33SJim Ingham             }
407a56c8006SJim Ingham         }
408a56c8006SJim Ingham     }
409a56c8006SJim Ingham     return false;
410a56c8006SJim Ingham }
411a56c8006SJim Ingham 
4124b4b2478SJim Ingham bool
4134b4b2478SJim Ingham ThreadPlanStepInRange::DefaultShouldStopHereCallback (ThreadPlan *current_plan, Flags &flags, FrameComparison operation, void *baton)
41430fdc8d8SChris Lattner {
4154b4b2478SJim Ingham     bool should_stop_here = true;
416b57e4a1bSJason Molenda     StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
4175160ce5cSGreg Clayton     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
41830fdc8d8SChris Lattner 
4190c2b9d2aSJim Ingham     // First see if the ThreadPlanShouldStopHere default implementation thinks we should get out of here:
4200c2b9d2aSJim Ingham     should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback (current_plan, flags, operation, baton);
4210c2b9d2aSJim Ingham     if (!should_stop_here)
4220c2b9d2aSJim Ingham         return should_stop_here;
423a56c8006SJim Ingham 
4244b4b2478SJim Ingham     if (should_stop_here && current_plan->GetKind() == eKindStepInRange && operation == eFrameCompareYounger)
425a56c8006SJim Ingham     {
426a56c8006SJim Ingham         ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
427c627682eSJim Ingham         if (step_in_range_plan->m_step_into_target)
428c627682eSJim Ingham         {
429c627682eSJim Ingham             SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
430c627682eSJim Ingham             if (sc.symbol != NULL)
431c627682eSJim Ingham             {
432c627682eSJim Ingham                 // First try an exact match, since that's cheap with ConstStrings.  Then do a strstr compare.
433c627682eSJim Ingham                 if (step_in_range_plan->m_step_into_target == sc.GetFunctionName())
434c627682eSJim Ingham                 {
4354b4b2478SJim Ingham                     should_stop_here = true;
436c627682eSJim Ingham                 }
437c627682eSJim Ingham                 else
438c627682eSJim Ingham                 {
439c627682eSJim Ingham                     const char *target_name = step_in_range_plan->m_step_into_target.AsCString();
440c627682eSJim Ingham                     const char *function_name = sc.GetFunctionName().AsCString();
441c627682eSJim Ingham 
442c627682eSJim Ingham                     if (function_name == NULL)
4434b4b2478SJim Ingham                         should_stop_here = false;
444c627682eSJim Ingham                     else if (strstr (function_name, target_name) == NULL)
4454b4b2478SJim Ingham                         should_stop_here = false;
446c627682eSJim Ingham                 }
4474b4b2478SJim Ingham                 if (log && !should_stop_here)
4483101ba33SJim Ingham                     log->Printf("Stepping out of frame %s which did not match step into target %s.",
4493101ba33SJim Ingham                                 sc.GetFunctionName().AsCString(),
4503101ba33SJim Ingham                                 step_in_range_plan->m_step_into_target.AsCString());
451c627682eSJim Ingham             }
452c627682eSJim Ingham         }
453c627682eSJim Ingham 
4544b4b2478SJim Ingham         if (should_stop_here)
455c627682eSJim Ingham         {
456c627682eSJim Ingham             ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
4574da6206dSJim Ingham             // Don't log the should_step_out here, it's easier to do it in FrameMatchesAvoidCriteria.
4584b4b2478SJim Ingham             should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria ();
459a56c8006SJim Ingham         }
460a56c8006SJim Ingham     }
461a56c8006SJim Ingham 
4624b4b2478SJim Ingham     return should_stop_here;
46330fdc8d8SChris Lattner }
464fbbfe6ecSJim Ingham 
465fbbfe6ecSJim Ingham bool
466221d51cfSJim Ingham ThreadPlanStepInRange::DoPlanExplainsStop (Event *event_ptr)
467fbbfe6ecSJim Ingham {
468fbbfe6ecSJim Ingham     // We always explain a stop.  Either we've just done a single step, in which
469fbbfe6ecSJim Ingham     // case we'll do our ordinary processing, or we stopped for some
470fbbfe6ecSJim Ingham     // reason that isn't handled by our sub-plans, in which case we want to just stop right
471fbbfe6ecSJim Ingham     // away.
472c627682eSJim Ingham     // In general, we don't want to mark the plan as complete for unexplained stops.
473c627682eSJim Ingham     // For instance, if you step in to some code with no debug info, so you step out
474c627682eSJim Ingham     // and in the course of that hit a breakpoint, then you want to stop & show the user
475c627682eSJim Ingham     // the breakpoint, but not unship the step in plan, since you still may want to complete that
476c627682eSJim Ingham     // plan when you continue.  This is particularly true when doing "step in to target function."
477c627682eSJim Ingham     // stepping.
478fbbfe6ecSJim Ingham     //
479fbbfe6ecSJim Ingham     // The only variation is that if we are doing "step by running to next branch" in which case
480fbbfe6ecSJim Ingham     // if we hit our branch breakpoint we don't set the plan to complete.
481fbbfe6ecSJim Ingham 
482221d51cfSJim Ingham     bool return_value;
483f02a2e96SJim Ingham 
484221d51cfSJim Ingham     if (m_virtual_step)
485221d51cfSJim Ingham     {
486221d51cfSJim Ingham         return_value = true;
487221d51cfSJim Ingham     }
488221d51cfSJim Ingham     else
489221d51cfSJim Ingham     {
49060c4118cSJim Ingham         StopInfoSP stop_info_sp = GetPrivateStopInfo ();
491fbbfe6ecSJim Ingham         if (stop_info_sp)
492fbbfe6ecSJim Ingham         {
493fbbfe6ecSJim Ingham             StopReason reason = stop_info_sp->GetStopReason();
494fbbfe6ecSJim Ingham 
495fbbfe6ecSJim Ingham             switch (reason)
496fbbfe6ecSJim Ingham             {
497fbbfe6ecSJim Ingham             case eStopReasonBreakpoint:
498fbbfe6ecSJim Ingham                 if (NextRangeBreakpointExplainsStop(stop_info_sp))
499221d51cfSJim Ingham                 {
500221d51cfSJim Ingham                     return_value = true;
501221d51cfSJim Ingham                     break;
502221d51cfSJim Ingham                 }
503fbbfe6ecSJim Ingham             case eStopReasonWatchpoint:
504fbbfe6ecSJim Ingham             case eStopReasonSignal:
505fbbfe6ecSJim Ingham             case eStopReasonException:
50690ba8115SGreg Clayton             case eStopReasonExec:
507f85defaeSAndrew Kaylor             case eStopReasonThreadExiting:
508513c6bb8SJim Ingham                 {
5095160ce5cSGreg Clayton                     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
510fbbfe6ecSJim Ingham                     if (log)
511fbbfe6ecSJim Ingham                         log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step.");
512513c6bb8SJim Ingham                 }
513221d51cfSJim Ingham                 return_value = false;
514fbbfe6ecSJim Ingham                 break;
515fbbfe6ecSJim Ingham             default:
516221d51cfSJim Ingham                 return_value = true;
517fbbfe6ecSJim Ingham                 break;
518fbbfe6ecSJim Ingham             }
519fbbfe6ecSJim Ingham         }
520221d51cfSJim Ingham         else
521221d51cfSJim Ingham             return_value = true;
522221d51cfSJim Ingham     }
523221d51cfSJim Ingham 
524221d51cfSJim Ingham     return return_value;
525fbbfe6ecSJim Ingham }
526513c6bb8SJim Ingham 
527513c6bb8SJim Ingham bool
528221d51cfSJim Ingham ThreadPlanStepInRange::DoWillResume (lldb::StateType resume_state, bool current_plan)
529513c6bb8SJim Ingham {
530513c6bb8SJim Ingham     if (resume_state == eStateStepping && current_plan)
531513c6bb8SJim Ingham     {
532513c6bb8SJim Ingham         // See if we are about to step over a virtual inlined call.
533513c6bb8SJim Ingham         bool step_without_resume = m_thread.DecrementCurrentInlinedDepth();
534513c6bb8SJim Ingham         if (step_without_resume)
535513c6bb8SJim Ingham         {
5365160ce5cSGreg Clayton             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
537513c6bb8SJim Ingham             if (log)
538221d51cfSJim Ingham                 log->Printf ("ThreadPlanStepInRange::DoWillResume: returning false, inline_depth: %d",
539513c6bb8SJim Ingham                              m_thread.GetCurrentInlinedDepth());
540513c6bb8SJim Ingham             SetStopInfo(StopInfo::CreateStopReasonToTrace(m_thread));
541f02a2e96SJim Ingham 
542f02a2e96SJim Ingham             // FIXME: Maybe it would be better to create a InlineStep stop reason, but then
543f02a2e96SJim Ingham             // the whole rest of the world would have to handle that stop reason.
544f02a2e96SJim Ingham             m_virtual_step = true;
545513c6bb8SJim Ingham         }
546513c6bb8SJim Ingham         return !step_without_resume;
547513c6bb8SJim Ingham     }
548221d51cfSJim Ingham     return true;
549513c6bb8SJim Ingham }
550246cb611SDaniel Malea 
551246cb611SDaniel Malea bool
552246cb611SDaniel Malea ThreadPlanStepInRange::IsVirtualStep()
553246cb611SDaniel Malea {
554246cb611SDaniel Malea   return m_virtual_step;
555246cb611SDaniel Malea }
556