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         s->Printf("step in");
13230fdc8d8SChris Lattner     else
13330fdc8d8SChris Lattner     {
13430fdc8d8SChris Lattner         s->Printf ("Stepping through range (stepping into functions): ");
135c4c9fedcSJim Ingham         DumpRanges(s);
1364d56e9c1SJim Ingham         const char *step_into_target = m_step_into_target.AsCString();
1374d56e9c1SJim Ingham         if (step_into_target && step_into_target[0] != '\0')
138c627682eSJim Ingham             s->Printf (" targeting %s.", m_step_into_target.AsCString());
1394d56e9c1SJim Ingham         else
1404d56e9c1SJim Ingham             s->PutChar('.');
14130fdc8d8SChris Lattner     }
14230fdc8d8SChris Lattner }
14330fdc8d8SChris Lattner 
14430fdc8d8SChris Lattner bool
14530fdc8d8SChris Lattner ThreadPlanStepInRange::ShouldStop (Event *event_ptr)
14630fdc8d8SChris Lattner {
1475160ce5cSGreg Clayton     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
14830fdc8d8SChris Lattner 
14930fdc8d8SChris Lattner     if (log)
15030fdc8d8SChris Lattner     {
15130fdc8d8SChris Lattner         StreamString s;
152514487e8SGreg Clayton         s.Address (m_thread.GetRegisterContext()->GetPC(),
1531ac04c30SGreg Clayton                    m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
15430fdc8d8SChris Lattner         log->Printf("ThreadPlanStepInRange reached %s.", s.GetData());
15530fdc8d8SChris Lattner     }
15630fdc8d8SChris Lattner 
15725f66700SJim Ingham     if (IsPlanComplete())
15825f66700SJim Ingham         return true;
15925f66700SJim Ingham 
1604d56e9c1SJim Ingham     m_no_more_plans = false;
1614d56e9c1SJim Ingham     if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete())
1624d56e9c1SJim Ingham     {
1634d56e9c1SJim Ingham         if (!m_sub_plan_sp->PlanSucceeded())
1644d56e9c1SJim Ingham         {
1654d56e9c1SJim Ingham             SetPlanComplete();
1664d56e9c1SJim Ingham             m_no_more_plans = true;
1674d56e9c1SJim Ingham             return true;
1684d56e9c1SJim Ingham         }
1694d56e9c1SJim Ingham         else
1704d56e9c1SJim Ingham             m_sub_plan_sp.reset();
1714d56e9c1SJim Ingham     }
17230fdc8d8SChris Lattner 
173f02a2e96SJim Ingham     if (m_virtual_step)
174f02a2e96SJim Ingham     {
175f02a2e96SJim Ingham         // If we've just completed a virtual step, all we need to do is check for a ShouldStopHere plan, and otherwise
176f02a2e96SJim Ingham         // we're done.
1774b4b2478SJim Ingham         // FIXME - This can be both a step in and a step out.  Probably should record which in the m_virtual_step.
1784b4b2478SJim Ingham         m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger);
179f02a2e96SJim Ingham     }
180f02a2e96SJim Ingham     else
181f02a2e96SJim Ingham     {
1824a58e968SJim Ingham         // Stepping through should be done running other threads in general, since we're setting a breakpoint and
1834a58e968SJim Ingham         // continuing.  So only stop others if we are explicitly told to do so.
1849d790c5dSJim Ingham 
18530fdc8d8SChris Lattner         bool stop_others;
1864a58e968SJim Ingham         if (m_stop_others == lldb::eOnlyThisThread)
1874a58e968SJim Ingham             stop_others = true;
1886cf5b8f1SEd Maste         else
1896cf5b8f1SEd Maste             stop_others = false;
19030fdc8d8SChris Lattner 
191b5c0d1ccSJim Ingham         FrameComparison frame_order = CompareCurrentFrameToStartFrame();
192b5c0d1ccSJim Ingham 
193*862d1bbdSJim Ingham         if (frame_order == eFrameCompareOlder || frame_order == eFrameCompareSameParent)
1945822173bSJim Ingham         {
1955822173bSJim Ingham             // If we're in an older frame then we should stop.
1965822173bSJim Ingham             //
1975822173bSJim Ingham             // A caveat to this is if we think the frame is older but we're actually in a trampoline.
1985822173bSJim Ingham             // I'm going to make the assumption that you wouldn't RETURN to a trampoline.  So if we are
1995822173bSJim Ingham             // in a trampoline we think the frame is older because the trampoline confused the backtracer.
2004d56e9c1SJim Ingham             m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
2014d56e9c1SJim Ingham             if (!m_sub_plan_sp)
2024b4b2478SJim Ingham             {
2034b4b2478SJim Ingham                 // Otherwise check the ShouldStopHere for step out:
204*862d1bbdSJim Ingham                 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
2054b4b2478SJim Ingham                 if (log)
2064b4b2478SJim Ingham                     log->Printf ("ShouldStopHere says we should step out of this frame.");
2074b4b2478SJim Ingham             }
2085822173bSJim Ingham             else if (log)
2095822173bSJim Ingham             {
2105822173bSJim Ingham                 log->Printf("Thought I stepped out, but in fact arrived at a trampoline.");
2115822173bSJim Ingham             }
2125822173bSJim Ingham 
2135822173bSJim Ingham         }
214564d8bc2SJim Ingham         else if (frame_order == eFrameCompareEqual && InSymbol())
2155822173bSJim Ingham         {
2165822173bSJim Ingham             // If we are not in a place we should step through, we're done.
2175822173bSJim Ingham             // One tricky bit here is that some stubs don't push a frame, so we have to check
2185822173bSJim Ingham             // both the case of a frame that is younger, or the same as this frame.
2195822173bSJim Ingham             // However, if the frame is the same, and we are still in the symbol we started
2205822173bSJim Ingham             // in, the we don't need to do this.  This first check isn't strictly necessary,
2215822173bSJim Ingham             // but it is more efficient.
2225822173bSJim Ingham 
223564d8bc2SJim Ingham             // If we're still in the range, keep going, either by running to the next branch breakpoint, or by
224564d8bc2SJim Ingham             // stepping.
225564d8bc2SJim Ingham             if (InRange())
226564d8bc2SJim Ingham             {
227564d8bc2SJim Ingham                 SetNextBranchBreakpoint();
228564d8bc2SJim Ingham                 return false;
229564d8bc2SJim Ingham             }
230564d8bc2SJim Ingham 
2315822173bSJim Ingham             SetPlanComplete();
232c627682eSJim Ingham             m_no_more_plans = true;
2335822173bSJim Ingham             return true;
2345822173bSJim Ingham         }
2355822173bSJim Ingham 
236564d8bc2SJim Ingham         // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it:
237564d8bc2SJim Ingham         ClearNextBranchBreakpoint();
238564d8bc2SJim Ingham 
2395822173bSJim Ingham         // We may have set the plan up above in the FrameIsOlder section:
2405822173bSJim Ingham 
2414d56e9c1SJim Ingham         if (!m_sub_plan_sp)
2424d56e9c1SJim Ingham             m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
24308b87e0dSJim Ingham 
24408b87e0dSJim Ingham         if (log)
24508b87e0dSJim Ingham         {
2464d56e9c1SJim Ingham             if (m_sub_plan_sp)
2474d56e9c1SJim Ingham                 log->Printf ("Found a step through plan: %s", m_sub_plan_sp->GetName());
24808b87e0dSJim Ingham             else
24908b87e0dSJim Ingham                 log->Printf ("No step through plan found.");
25008b87e0dSJim Ingham         }
25108b87e0dSJim Ingham 
25230fdc8d8SChris Lattner         // If not, give the "should_stop" callback a chance to push a plan to get us out of here.
25330fdc8d8SChris Lattner         // But only do that if we actually have stepped in.
2544d56e9c1SJim Ingham         if (!m_sub_plan_sp && frame_order == eFrameCompareYounger)
2554b4b2478SJim Ingham             m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
25630fdc8d8SChris Lattner 
2577ce490c6SJim Ingham         // If we've stepped in and we are going to stop here, check to see if we were asked to
2587ce490c6SJim Ingham         // run past the prologue, and if so do that.
2597ce490c6SJim Ingham 
2604d56e9c1SJim Ingham         if (!m_sub_plan_sp && frame_order == eFrameCompareYounger && m_step_past_prologue)
2617ce490c6SJim Ingham         {
262b57e4a1bSJason Molenda             lldb::StackFrameSP curr_frame = m_thread.GetStackFrameAtIndex(0);
2637ce490c6SJim Ingham             if (curr_frame)
2647ce490c6SJim Ingham             {
2657ce490c6SJim Ingham                 size_t bytes_to_skip = 0;
2667ce490c6SJim Ingham                 lldb::addr_t curr_addr = m_thread.GetRegisterContext()->GetPC();
2677ce490c6SJim Ingham                 Address func_start_address;
2687ce490c6SJim Ingham 
2697ce490c6SJim Ingham                 SymbolContext sc = curr_frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextSymbol);
2707ce490c6SJim Ingham 
2717ce490c6SJim Ingham                 if (sc.function)
2727ce490c6SJim Ingham                 {
2737ce490c6SJim Ingham                     func_start_address = sc.function->GetAddressRange().GetBaseAddress();
274d9e416c0SGreg Clayton                     if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
2757ce490c6SJim Ingham                         bytes_to_skip = sc.function->GetPrologueByteSize();
2767ce490c6SJim Ingham                 }
2777ce490c6SJim Ingham                 else if (sc.symbol)
2787ce490c6SJim Ingham                 {
279e7612134SGreg Clayton                     func_start_address = sc.symbol->GetAddress();
280d9e416c0SGreg Clayton                     if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
2817ce490c6SJim Ingham                         bytes_to_skip = sc.symbol->GetPrologueByteSize();
2827ce490c6SJim Ingham                 }
2837ce490c6SJim Ingham 
2847ce490c6SJim Ingham                 if (bytes_to_skip != 0)
2857ce490c6SJim Ingham                 {
2867ce490c6SJim Ingham                     func_start_address.Slide (bytes_to_skip);
28720ad3c40SCaroline Tice                     log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
2887ce490c6SJim Ingham                     if (log)
2897ce490c6SJim Ingham                         log->Printf ("Pushing past prologue ");
2907ce490c6SJim Ingham 
2914d56e9c1SJim Ingham                     m_sub_plan_sp = m_thread.QueueThreadPlanForRunToAddress(false, func_start_address,true);
2927ce490c6SJim Ingham                 }
2937ce490c6SJim Ingham             }
2947ce490c6SJim Ingham         }
295f02a2e96SJim Ingham      }
2967ce490c6SJim Ingham 
2974d56e9c1SJim Ingham      if (!m_sub_plan_sp)
29830fdc8d8SChris Lattner      {
29930fdc8d8SChris Lattner         m_no_more_plans = true;
30030fdc8d8SChris Lattner         SetPlanComplete();
30130fdc8d8SChris Lattner         return true;
30230fdc8d8SChris Lattner     }
30330fdc8d8SChris Lattner     else
30430fdc8d8SChris Lattner     {
30530fdc8d8SChris Lattner         m_no_more_plans = false;
30630fdc8d8SChris Lattner         return false;
30730fdc8d8SChris Lattner     }
30830fdc8d8SChris Lattner }
30930fdc8d8SChris Lattner 
31030fdc8d8SChris Lattner void
311a56c8006SJim Ingham ThreadPlanStepInRange::SetAvoidRegexp(const char *name)
312a56c8006SJim Ingham {
313a56c8006SJim Ingham     if (m_avoid_regexp_ap.get() == NULL)
314a56c8006SJim Ingham         m_avoid_regexp_ap.reset (new RegularExpression(name));
315a56c8006SJim Ingham 
316a56c8006SJim Ingham     m_avoid_regexp_ap->Compile (name);
317a56c8006SJim Ingham }
318a56c8006SJim Ingham 
319a56c8006SJim Ingham void
32030fdc8d8SChris Lattner ThreadPlanStepInRange::SetDefaultFlagValue (uint32_t new_value)
32130fdc8d8SChris Lattner {
32230fdc8d8SChris Lattner     // TODO: Should we test this for sanity?
32330fdc8d8SChris Lattner     ThreadPlanStepInRange::s_default_flag_values = new_value;
32430fdc8d8SChris Lattner }
32530fdc8d8SChris Lattner 
326a56c8006SJim Ingham bool
3274da6206dSJim Ingham ThreadPlanStepInRange::FrameMatchesAvoidCriteria ()
328a56c8006SJim Ingham {
329b57e4a1bSJason Molenda     StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
330a56c8006SJim Ingham 
3314da6206dSJim Ingham     // Check the library list first, as that's cheapest:
332a786e539SJim Ingham     bool libraries_say_avoid = false;
333a786e539SJim Ingham 
3344da6206dSJim Ingham     FileSpecList libraries_to_avoid (GetThread().GetLibrariesToAvoid());
3354da6206dSJim Ingham     size_t num_libraries = libraries_to_avoid.GetSize();
336a786e539SJim Ingham     if (num_libraries > 0)
337a786e539SJim Ingham     {
3384da6206dSJim Ingham         SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
3394da6206dSJim Ingham         FileSpec frame_library(sc.module_sp->GetFileSpec());
3404da6206dSJim Ingham 
3414da6206dSJim Ingham         if (frame_library)
3424da6206dSJim Ingham         {
3434da6206dSJim Ingham             for (size_t i = 0; i < num_libraries; i++)
3444da6206dSJim Ingham             {
3454da6206dSJim Ingham                 const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
3464da6206dSJim Ingham                 if (FileSpec::Equal (file_spec, frame_library, false))
3474da6206dSJim Ingham                 {
3484da6206dSJim Ingham                     libraries_say_avoid = true;
3494da6206dSJim Ingham                     break;
3504da6206dSJim Ingham                 }
3514da6206dSJim Ingham             }
3524da6206dSJim Ingham         }
353a786e539SJim Ingham     }
3544da6206dSJim Ingham     if (libraries_say_avoid)
3554da6206dSJim Ingham         return true;
3564da6206dSJim Ingham 
35767cc0636SGreg Clayton     const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get();
358ee8aea10SJim Ingham     if (avoid_regexp_to_use == NULL)
359ee8aea10SJim Ingham         avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
360ee8aea10SJim Ingham 
361ee8aea10SJim Ingham     if (avoid_regexp_to_use != NULL)
362a56c8006SJim Ingham     {
3634592cbc4SGreg Clayton         SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
364a56c8006SJim Ingham         if (sc.symbol != NULL)
365a56c8006SJim Ingham         {
3664592cbc4SGreg Clayton             const char *frame_function_name = sc.GetFunctionName().GetCString();
3674592cbc4SGreg Clayton             if (frame_function_name)
3683101ba33SJim Ingham             {
369cf2667c4SJim Ingham                 size_t num_matches = 0;
3705160ce5cSGreg Clayton                 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
3713101ba33SJim Ingham                 if (log)
372cf2667c4SJim Ingham                     num_matches = 1;
373bc43cab5SGreg Clayton 
374bc43cab5SGreg Clayton                 RegularExpression::Match regex_match(num_matches);
375bc43cab5SGreg Clayton 
376bc43cab5SGreg Clayton                 bool return_value = avoid_regexp_to_use->Execute(frame_function_name, &regex_match);
377cf2667c4SJim Ingham                 if (return_value)
378cf2667c4SJim Ingham                 {
379cf2667c4SJim Ingham                     if (log)
380cf2667c4SJim Ingham                     {
381cf2667c4SJim Ingham                         std::string match;
382bc43cab5SGreg Clayton                         regex_match.GetMatchAtIndex(frame_function_name,0, match);
383cf2667c4SJim Ingham                         log->Printf ("Stepping out of function \"%s\" because it matches the avoid regexp \"%s\" - match substring: \"%s\".",
3843101ba33SJim Ingham                                      frame_function_name,
385cf2667c4SJim Ingham                                      avoid_regexp_to_use->GetText(),
386cf2667c4SJim Ingham                                      match.c_str());
387cf2667c4SJim Ingham                     }
3883101ba33SJim Ingham 
3893101ba33SJim Ingham                 }
3903101ba33SJim Ingham                 return return_value;
3913101ba33SJim Ingham             }
392a56c8006SJim Ingham         }
393a56c8006SJim Ingham     }
394a56c8006SJim Ingham     return false;
395a56c8006SJim Ingham }
396a56c8006SJim Ingham 
3974b4b2478SJim Ingham bool
3984b4b2478SJim Ingham ThreadPlanStepInRange::DefaultShouldStopHereCallback (ThreadPlan *current_plan, Flags &flags, FrameComparison operation, void *baton)
39930fdc8d8SChris Lattner {
4004b4b2478SJim Ingham     bool should_stop_here = true;
401b57e4a1bSJason Molenda     StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
4025160ce5cSGreg Clayton     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
40330fdc8d8SChris Lattner 
4044b4b2478SJim Ingham     if ((operation == eFrameCompareYounger && flags.Test(eStepInAvoidNoDebug))
405*862d1bbdSJim Ingham         || (operation == eFrameCompareSameParent && flags.Test(eStepOutAvoidNoDebug))
4064b4b2478SJim Ingham         || (operation == eFrameCompareOlder && flags.Test(eStepOutAvoidNoDebug)))
407a56c8006SJim Ingham     {
40830fdc8d8SChris Lattner         if (!frame->HasDebugInformation())
409af0f1759SJim Ingham         {
410af0f1759SJim Ingham             if (log)
411af0f1759SJim Ingham                 log->Printf ("Stepping out of frame with no debug info");
412af0f1759SJim Ingham 
4134b4b2478SJim Ingham             should_stop_here = false;
414a56c8006SJim Ingham         }
415af0f1759SJim Ingham     }
416a56c8006SJim Ingham 
4174b4b2478SJim Ingham     if (should_stop_here && current_plan->GetKind() == eKindStepInRange && operation == eFrameCompareYounger)
418a56c8006SJim Ingham     {
419a56c8006SJim Ingham         ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
420c627682eSJim Ingham         if (step_in_range_plan->m_step_into_target)
421c627682eSJim Ingham         {
422c627682eSJim Ingham             SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
423c627682eSJim Ingham             if (sc.symbol != NULL)
424c627682eSJim Ingham             {
425c627682eSJim Ingham                 // First try an exact match, since that's cheap with ConstStrings.  Then do a strstr compare.
426c627682eSJim Ingham                 if (step_in_range_plan->m_step_into_target == sc.GetFunctionName())
427c627682eSJim Ingham                 {
4284b4b2478SJim Ingham                     should_stop_here = true;
429c627682eSJim Ingham                 }
430c627682eSJim Ingham                 else
431c627682eSJim Ingham                 {
432c627682eSJim Ingham                     const char *target_name = step_in_range_plan->m_step_into_target.AsCString();
433c627682eSJim Ingham                     const char *function_name = sc.GetFunctionName().AsCString();
434c627682eSJim Ingham 
435c627682eSJim Ingham                     if (function_name == NULL)
4364b4b2478SJim Ingham                         should_stop_here = false;
437c627682eSJim Ingham                     else if (strstr (function_name, target_name) == NULL)
4384b4b2478SJim Ingham                         should_stop_here = false;
439c627682eSJim Ingham                 }
4404b4b2478SJim Ingham                 if (log && !should_stop_here)
4413101ba33SJim Ingham                     log->Printf("Stepping out of frame %s which did not match step into target %s.",
4423101ba33SJim Ingham                                 sc.GetFunctionName().AsCString(),
4433101ba33SJim Ingham                                 step_in_range_plan->m_step_into_target.AsCString());
444c627682eSJim Ingham             }
445c627682eSJim Ingham         }
446c627682eSJim Ingham 
4474b4b2478SJim Ingham         if (should_stop_here)
448c627682eSJim Ingham         {
449c627682eSJim Ingham             ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
4504da6206dSJim Ingham             // Don't log the should_step_out here, it's easier to do it in FrameMatchesAvoidCriteria.
4514b4b2478SJim Ingham             should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria ();
452a56c8006SJim Ingham         }
453a56c8006SJim Ingham     }
454a56c8006SJim Ingham 
4554b4b2478SJim Ingham     return should_stop_here;
45630fdc8d8SChris Lattner }
457fbbfe6ecSJim Ingham 
458fbbfe6ecSJim Ingham bool
459221d51cfSJim Ingham ThreadPlanStepInRange::DoPlanExplainsStop (Event *event_ptr)
460fbbfe6ecSJim Ingham {
461fbbfe6ecSJim Ingham     // We always explain a stop.  Either we've just done a single step, in which
462fbbfe6ecSJim Ingham     // case we'll do our ordinary processing, or we stopped for some
463fbbfe6ecSJim Ingham     // reason that isn't handled by our sub-plans, in which case we want to just stop right
464fbbfe6ecSJim Ingham     // away.
465c627682eSJim Ingham     // In general, we don't want to mark the plan as complete for unexplained stops.
466c627682eSJim Ingham     // For instance, if you step in to some code with no debug info, so you step out
467c627682eSJim Ingham     // and in the course of that hit a breakpoint, then you want to stop & show the user
468c627682eSJim Ingham     // the breakpoint, but not unship the step in plan, since you still may want to complete that
469c627682eSJim Ingham     // plan when you continue.  This is particularly true when doing "step in to target function."
470c627682eSJim Ingham     // stepping.
471fbbfe6ecSJim Ingham     //
472fbbfe6ecSJim Ingham     // The only variation is that if we are doing "step by running to next branch" in which case
473fbbfe6ecSJim Ingham     // if we hit our branch breakpoint we don't set the plan to complete.
474fbbfe6ecSJim Ingham 
475221d51cfSJim Ingham     bool return_value;
476f02a2e96SJim Ingham 
477221d51cfSJim Ingham     if (m_virtual_step)
478221d51cfSJim Ingham     {
479221d51cfSJim Ingham         return_value = true;
480221d51cfSJim Ingham     }
481221d51cfSJim Ingham     else
482221d51cfSJim Ingham     {
48360c4118cSJim Ingham         StopInfoSP stop_info_sp = GetPrivateStopInfo ();
484fbbfe6ecSJim Ingham         if (stop_info_sp)
485fbbfe6ecSJim Ingham         {
486fbbfe6ecSJim Ingham             StopReason reason = stop_info_sp->GetStopReason();
487fbbfe6ecSJim Ingham 
488fbbfe6ecSJim Ingham             switch (reason)
489fbbfe6ecSJim Ingham             {
490fbbfe6ecSJim Ingham             case eStopReasonBreakpoint:
491fbbfe6ecSJim Ingham                 if (NextRangeBreakpointExplainsStop(stop_info_sp))
492221d51cfSJim Ingham                 {
493221d51cfSJim Ingham                     return_value = true;
494221d51cfSJim Ingham                     break;
495221d51cfSJim Ingham                 }
496fbbfe6ecSJim Ingham             case eStopReasonWatchpoint:
497fbbfe6ecSJim Ingham             case eStopReasonSignal:
498fbbfe6ecSJim Ingham             case eStopReasonException:
49990ba8115SGreg Clayton             case eStopReasonExec:
500f85defaeSAndrew Kaylor             case eStopReasonThreadExiting:
501513c6bb8SJim Ingham                 {
5025160ce5cSGreg Clayton                     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
503fbbfe6ecSJim Ingham                     if (log)
504fbbfe6ecSJim Ingham                         log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step.");
505513c6bb8SJim Ingham                 }
506221d51cfSJim Ingham                 return_value = false;
507fbbfe6ecSJim Ingham                 break;
508fbbfe6ecSJim Ingham             default:
509221d51cfSJim Ingham                 return_value = true;
510fbbfe6ecSJim Ingham                 break;
511fbbfe6ecSJim Ingham             }
512fbbfe6ecSJim Ingham         }
513221d51cfSJim Ingham         else
514221d51cfSJim Ingham             return_value = true;
515221d51cfSJim Ingham     }
516221d51cfSJim Ingham 
517221d51cfSJim Ingham     return return_value;
518fbbfe6ecSJim Ingham }
519513c6bb8SJim Ingham 
520513c6bb8SJim Ingham bool
521221d51cfSJim Ingham ThreadPlanStepInRange::DoWillResume (lldb::StateType resume_state, bool current_plan)
522513c6bb8SJim Ingham {
523513c6bb8SJim Ingham     if (resume_state == eStateStepping && current_plan)
524513c6bb8SJim Ingham     {
525513c6bb8SJim Ingham         // See if we are about to step over a virtual inlined call.
526513c6bb8SJim Ingham         bool step_without_resume = m_thread.DecrementCurrentInlinedDepth();
527513c6bb8SJim Ingham         if (step_without_resume)
528513c6bb8SJim Ingham         {
5295160ce5cSGreg Clayton             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
530513c6bb8SJim Ingham             if (log)
531221d51cfSJim Ingham                 log->Printf ("ThreadPlanStepInRange::DoWillResume: returning false, inline_depth: %d",
532513c6bb8SJim Ingham                              m_thread.GetCurrentInlinedDepth());
533513c6bb8SJim Ingham             SetStopInfo(StopInfo::CreateStopReasonToTrace(m_thread));
534f02a2e96SJim Ingham 
535f02a2e96SJim Ingham             // FIXME: Maybe it would be better to create a InlineStep stop reason, but then
536f02a2e96SJim Ingham             // the whole rest of the world would have to handle that stop reason.
537f02a2e96SJim Ingham             m_virtual_step = true;
538513c6bb8SJim Ingham         }
539513c6bb8SJim Ingham         return !step_without_resume;
540513c6bb8SJim Ingham     }
541221d51cfSJim Ingham     return true;
542513c6bb8SJim Ingham }
543246cb611SDaniel Malea 
544246cb611SDaniel Malea bool
545246cb611SDaniel Malea ThreadPlanStepInRange::IsVirtualStep()
546246cb611SDaniel Malea {
547246cb611SDaniel Malea   return m_virtual_step;
548246cb611SDaniel Malea }
549