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 14*e65b2cf2SEugene Zelenko #include "lldb/Target/ThreadPlanStepInRange.h" 1530fdc8d8SChris Lattner #include "lldb/Core/Log.h" 164da6206dSJim Ingham #include "lldb/Core/Module.h" 1730fdc8d8SChris Lattner #include "lldb/Core/Stream.h" 18a56c8006SJim Ingham #include "lldb/Symbol/Symbol.h" 197ce490c6SJim Ingham #include "lldb/Symbol/Function.h" 2030fdc8d8SChris Lattner #include "lldb/Target/Process.h" 2130fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.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" 26a56c8006SJim Ingham #include "lldb/Core/RegularExpression.h" 2730fdc8d8SChris Lattner 2830fdc8d8SChris Lattner using namespace lldb; 2930fdc8d8SChris Lattner using namespace lldb_private; 3030fdc8d8SChris Lattner 314b4b2478SJim Ingham uint32_t ThreadPlanStepInRange::s_default_flag_values = ThreadPlanShouldStopHere::eStepInAvoidNoDebug; 3230fdc8d8SChris Lattner 3330fdc8d8SChris Lattner //---------------------------------------------------------------------- 3430fdc8d8SChris Lattner // ThreadPlanStepInRange: Step through a stack range, either stepping over or into 3530fdc8d8SChris Lattner // based on the value of \a type. 3630fdc8d8SChris Lattner //---------------------------------------------------------------------- 3730fdc8d8SChris Lattner 3830fdc8d8SChris Lattner ThreadPlanStepInRange::ThreadPlanStepInRange 3930fdc8d8SChris Lattner ( 4030fdc8d8SChris Lattner Thread &thread, 4130fdc8d8SChris Lattner const AddressRange &range, 4230fdc8d8SChris Lattner const SymbolContext &addr_context, 434b4b2478SJim Ingham lldb::RunMode stop_others, 444b4b2478SJim Ingham LazyBool step_in_avoids_code_without_debug_info, 454b4b2478SJim Ingham LazyBool step_out_avoids_code_without_debug_info 4630fdc8d8SChris Lattner ) : 47b01e742aSJim Ingham ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others), 484b4b2478SJim Ingham ThreadPlanShouldStopHere (this), 49f02a2e96SJim Ingham m_step_past_prologue (true), 50f02a2e96SJim Ingham m_virtual_step (false) 5130fdc8d8SChris Lattner { 524b4b2478SJim Ingham SetCallbacks(); 5330fdc8d8SChris Lattner SetFlagsToDefault (); 544b4b2478SJim Ingham SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info); 5530fdc8d8SChris Lattner } 5630fdc8d8SChris Lattner 57c627682eSJim Ingham ThreadPlanStepInRange::ThreadPlanStepInRange 58c627682eSJim Ingham ( 59c627682eSJim Ingham Thread &thread, 60c627682eSJim Ingham const AddressRange &range, 61c627682eSJim Ingham const SymbolContext &addr_context, 62c627682eSJim Ingham const char *step_into_target, 634b4b2478SJim Ingham lldb::RunMode stop_others, 644b4b2478SJim Ingham LazyBool step_in_avoids_code_without_debug_info, 654b4b2478SJim Ingham LazyBool step_out_avoids_code_without_debug_info 66c627682eSJim Ingham ) : 67c627682eSJim Ingham ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others), 684b4b2478SJim Ingham ThreadPlanShouldStopHere (this), 69c627682eSJim Ingham m_step_past_prologue (true), 70c627682eSJim Ingham m_virtual_step (false), 71c627682eSJim Ingham m_step_into_target (step_into_target) 72c627682eSJim Ingham { 734b4b2478SJim Ingham SetCallbacks(); 74c627682eSJim Ingham SetFlagsToDefault (); 754b4b2478SJim Ingham SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info); 76c627682eSJim Ingham } 77c627682eSJim Ingham 78*e65b2cf2SEugene Zelenko ThreadPlanStepInRange::~ThreadPlanStepInRange() = default; 7930fdc8d8SChris Lattner 8030fdc8d8SChris Lattner void 814b4b2478SJim Ingham ThreadPlanStepInRange::SetupAvoidNoDebug(LazyBool step_in_avoids_code_without_debug_info, 824b4b2478SJim Ingham LazyBool step_out_avoids_code_without_debug_info) 834b4b2478SJim Ingham { 844b4b2478SJim Ingham bool avoid_nodebug = true; 854b4b2478SJim Ingham 864b4b2478SJim Ingham switch (step_in_avoids_code_without_debug_info) 874b4b2478SJim Ingham { 884b4b2478SJim Ingham case eLazyBoolYes: 894b4b2478SJim Ingham avoid_nodebug = true; 904b4b2478SJim Ingham break; 914b4b2478SJim Ingham case eLazyBoolNo: 924b4b2478SJim Ingham avoid_nodebug = false; 934b4b2478SJim Ingham break; 944b4b2478SJim Ingham case eLazyBoolCalculate: 954b4b2478SJim Ingham avoid_nodebug = m_thread.GetStepInAvoidsNoDebug(); 964b4b2478SJim Ingham break; 974b4b2478SJim Ingham } 984b4b2478SJim Ingham if (avoid_nodebug) 994b4b2478SJim Ingham GetFlags().Set (ThreadPlanShouldStopHere::eStepInAvoidNoDebug); 1004b4b2478SJim Ingham else 1014b4b2478SJim Ingham GetFlags().Clear (ThreadPlanShouldStopHere::eStepInAvoidNoDebug); 1024b4b2478SJim Ingham 1034b4b2478SJim Ingham switch (step_out_avoids_code_without_debug_info) 1044b4b2478SJim Ingham { 1054b4b2478SJim Ingham case eLazyBoolYes: 1064b4b2478SJim Ingham avoid_nodebug = true; 1074b4b2478SJim Ingham break; 1084b4b2478SJim Ingham case eLazyBoolNo: 1094b4b2478SJim Ingham avoid_nodebug = false; 1104b4b2478SJim Ingham break; 1114b4b2478SJim Ingham case eLazyBoolCalculate: 1124b4b2478SJim Ingham avoid_nodebug = m_thread.GetStepOutAvoidsNoDebug(); 1134b4b2478SJim Ingham break; 1144b4b2478SJim Ingham } 1154b4b2478SJim Ingham if (avoid_nodebug) 1164b4b2478SJim Ingham GetFlags().Set (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug); 1174b4b2478SJim Ingham else 1184b4b2478SJim Ingham GetFlags().Clear (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug); 1194b4b2478SJim Ingham } 1204b4b2478SJim Ingham 1214b4b2478SJim Ingham void 12230fdc8d8SChris Lattner ThreadPlanStepInRange::GetDescription (Stream *s, lldb::DescriptionLevel level) 12330fdc8d8SChris Lattner { 12430fdc8d8SChris Lattner if (level == lldb::eDescriptionLevelBrief) 12530fdc8d8SChris Lattner { 1262bdbfd50SJim Ingham s->Printf("step in"); 1272bdbfd50SJim Ingham return; 1282bdbfd50SJim Ingham } 1292bdbfd50SJim Ingham 1302bdbfd50SJim Ingham s->Printf ("Stepping in"); 1312bdbfd50SJim Ingham bool printed_line_info = false; 1322bdbfd50SJim Ingham if (m_addr_context.line_entry.IsValid()) 1332bdbfd50SJim Ingham { 1342bdbfd50SJim Ingham s->Printf (" through line "); 1352bdbfd50SJim Ingham m_addr_context.line_entry.DumpStopContext (s, false); 1362bdbfd50SJim Ingham printed_line_info = true; 1372bdbfd50SJim Ingham } 1382bdbfd50SJim Ingham 1394d56e9c1SJim Ingham const char *step_into_target = m_step_into_target.AsCString(); 1404d56e9c1SJim Ingham if (step_into_target && step_into_target[0] != '\0') 1412bdbfd50SJim Ingham s->Printf (" targeting %s", m_step_into_target.AsCString()); 1422bdbfd50SJim Ingham 1432bdbfd50SJim Ingham if (!printed_line_info || level == eDescriptionLevelVerbose) 1442bdbfd50SJim Ingham { 1452bdbfd50SJim Ingham s->Printf (" using ranges:"); 1462bdbfd50SJim Ingham DumpRanges(s); 14730fdc8d8SChris Lattner } 1482bdbfd50SJim Ingham 1492bdbfd50SJim Ingham s->PutChar('.'); 15030fdc8d8SChris Lattner } 15130fdc8d8SChris Lattner 15230fdc8d8SChris Lattner bool 15330fdc8d8SChris Lattner ThreadPlanStepInRange::ShouldStop (Event *event_ptr) 15430fdc8d8SChris Lattner { 1555160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 15630fdc8d8SChris Lattner 15730fdc8d8SChris Lattner if (log) 15830fdc8d8SChris Lattner { 15930fdc8d8SChris Lattner StreamString s; 160514487e8SGreg Clayton s.Address (m_thread.GetRegisterContext()->GetPC(), 1611ac04c30SGreg Clayton m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize()); 16230fdc8d8SChris Lattner log->Printf("ThreadPlanStepInRange reached %s.", s.GetData()); 16330fdc8d8SChris Lattner } 16430fdc8d8SChris Lattner 16525f66700SJim Ingham if (IsPlanComplete()) 16625f66700SJim Ingham return true; 16725f66700SJim Ingham 1684d56e9c1SJim Ingham m_no_more_plans = false; 1694d56e9c1SJim Ingham if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete()) 1704d56e9c1SJim Ingham { 1714d56e9c1SJim Ingham if (!m_sub_plan_sp->PlanSucceeded()) 1724d56e9c1SJim Ingham { 1734d56e9c1SJim Ingham SetPlanComplete(); 1744d56e9c1SJim Ingham m_no_more_plans = true; 1754d56e9c1SJim Ingham return true; 1764d56e9c1SJim Ingham } 1774d56e9c1SJim Ingham else 1784d56e9c1SJim Ingham m_sub_plan_sp.reset(); 1794d56e9c1SJim Ingham } 18030fdc8d8SChris Lattner 181f02a2e96SJim Ingham if (m_virtual_step) 182f02a2e96SJim Ingham { 183f02a2e96SJim Ingham // If we've just completed a virtual step, all we need to do is check for a ShouldStopHere plan, and otherwise 184f02a2e96SJim Ingham // we're done. 1854b4b2478SJim Ingham // FIXME - This can be both a step in and a step out. Probably should record which in the m_virtual_step. 1864b4b2478SJim Ingham m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger); 187f02a2e96SJim Ingham } 188f02a2e96SJim Ingham else 189f02a2e96SJim Ingham { 1904a58e968SJim Ingham // Stepping through should be done running other threads in general, since we're setting a breakpoint and 1914a58e968SJim Ingham // continuing. So only stop others if we are explicitly told to do so. 1929d790c5dSJim Ingham 193*e65b2cf2SEugene Zelenko bool stop_others = (m_stop_others == lldb::eOnlyThisThread); 19430fdc8d8SChris Lattner 195b5c0d1ccSJim Ingham FrameComparison frame_order = CompareCurrentFrameToStartFrame(); 196b5c0d1ccSJim Ingham 197862d1bbdSJim Ingham if (frame_order == eFrameCompareOlder || frame_order == eFrameCompareSameParent) 1985822173bSJim Ingham { 1995822173bSJim Ingham // If we're in an older frame then we should stop. 2005822173bSJim Ingham // 2015822173bSJim Ingham // A caveat to this is if we think the frame is older but we're actually in a trampoline. 2025822173bSJim Ingham // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are 2035822173bSJim Ingham // in a trampoline we think the frame is older because the trampoline confused the backtracer. 2044d56e9c1SJim Ingham m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others); 2054d56e9c1SJim Ingham if (!m_sub_plan_sp) 2064b4b2478SJim Ingham { 2074b4b2478SJim Ingham // Otherwise check the ShouldStopHere for step out: 208862d1bbdSJim Ingham m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order); 2094b4b2478SJim Ingham if (log) 2104b4b2478SJim Ingham log->Printf ("ShouldStopHere says we should step out of this frame."); 2114b4b2478SJim Ingham } 2125822173bSJim Ingham else if (log) 2135822173bSJim Ingham { 2145822173bSJim Ingham log->Printf("Thought I stepped out, but in fact arrived at a trampoline."); 2155822173bSJim Ingham } 2165822173bSJim Ingham } 217564d8bc2SJim Ingham else if (frame_order == eFrameCompareEqual && InSymbol()) 2185822173bSJim Ingham { 2195822173bSJim Ingham // If we are not in a place we should step through, we're done. 2205822173bSJim Ingham // One tricky bit here is that some stubs don't push a frame, so we have to check 2215822173bSJim Ingham // both the case of a frame that is younger, or the same as this frame. 2225822173bSJim Ingham // However, if the frame is the same, and we are still in the symbol we started 2235822173bSJim Ingham // in, the we don't need to do this. This first check isn't strictly necessary, 2245822173bSJim Ingham // but it is more efficient. 2255822173bSJim Ingham 226564d8bc2SJim Ingham // If we're still in the range, keep going, either by running to the next branch breakpoint, or by 227564d8bc2SJim Ingham // stepping. 228564d8bc2SJim Ingham if (InRange()) 229564d8bc2SJim Ingham { 230564d8bc2SJim Ingham SetNextBranchBreakpoint(); 231564d8bc2SJim Ingham return false; 232564d8bc2SJim Ingham } 233564d8bc2SJim Ingham 2345822173bSJim Ingham SetPlanComplete(); 235c627682eSJim Ingham m_no_more_plans = true; 2365822173bSJim Ingham return true; 2375822173bSJim Ingham } 2385822173bSJim Ingham 239564d8bc2SJim Ingham // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it: 240564d8bc2SJim Ingham ClearNextBranchBreakpoint(); 241564d8bc2SJim Ingham 2425822173bSJim Ingham // We may have set the plan up above in the FrameIsOlder section: 2435822173bSJim Ingham 2444d56e9c1SJim Ingham if (!m_sub_plan_sp) 2454d56e9c1SJim Ingham m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others); 24608b87e0dSJim Ingham 24708b87e0dSJim Ingham if (log) 24808b87e0dSJim Ingham { 2494d56e9c1SJim Ingham if (m_sub_plan_sp) 2504d56e9c1SJim Ingham log->Printf ("Found a step through plan: %s", m_sub_plan_sp->GetName()); 25108b87e0dSJim Ingham else 25208b87e0dSJim Ingham log->Printf ("No step through plan found."); 25308b87e0dSJim Ingham } 25408b87e0dSJim Ingham 25530fdc8d8SChris Lattner // If not, give the "should_stop" callback a chance to push a plan to get us out of here. 25630fdc8d8SChris Lattner // But only do that if we actually have stepped in. 2574d56e9c1SJim Ingham if (!m_sub_plan_sp && frame_order == eFrameCompareYounger) 2584b4b2478SJim Ingham m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order); 25930fdc8d8SChris Lattner 2607ce490c6SJim Ingham // If we've stepped in and we are going to stop here, check to see if we were asked to 2617ce490c6SJim Ingham // run past the prologue, and if so do that. 2627ce490c6SJim Ingham 2634d56e9c1SJim Ingham if (!m_sub_plan_sp && frame_order == eFrameCompareYounger && m_step_past_prologue) 2647ce490c6SJim Ingham { 265b57e4a1bSJason Molenda lldb::StackFrameSP curr_frame = m_thread.GetStackFrameAtIndex(0); 2667ce490c6SJim Ingham if (curr_frame) 2677ce490c6SJim Ingham { 2687ce490c6SJim Ingham size_t bytes_to_skip = 0; 2697ce490c6SJim Ingham lldb::addr_t curr_addr = m_thread.GetRegisterContext()->GetPC(); 2707ce490c6SJim Ingham Address func_start_address; 2717ce490c6SJim Ingham 2727ce490c6SJim Ingham SymbolContext sc = curr_frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextSymbol); 2737ce490c6SJim Ingham 2747ce490c6SJim Ingham if (sc.function) 2757ce490c6SJim Ingham { 2767ce490c6SJim Ingham func_start_address = sc.function->GetAddressRange().GetBaseAddress(); 277d9e416c0SGreg Clayton if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get())) 2787ce490c6SJim Ingham bytes_to_skip = sc.function->GetPrologueByteSize(); 2797ce490c6SJim Ingham } 2807ce490c6SJim Ingham else if (sc.symbol) 2817ce490c6SJim Ingham { 282e7612134SGreg Clayton func_start_address = sc.symbol->GetAddress(); 283d9e416c0SGreg Clayton if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get())) 2847ce490c6SJim Ingham bytes_to_skip = sc.symbol->GetPrologueByteSize(); 2857ce490c6SJim Ingham } 2867ce490c6SJim Ingham 2877ce490c6SJim Ingham if (bytes_to_skip != 0) 2887ce490c6SJim Ingham { 2897ce490c6SJim Ingham func_start_address.Slide (bytes_to_skip); 29020ad3c40SCaroline Tice log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP); 2917ce490c6SJim Ingham if (log) 2927ce490c6SJim Ingham log->Printf ("Pushing past prologue "); 2937ce490c6SJim Ingham 2944d56e9c1SJim Ingham m_sub_plan_sp = m_thread.QueueThreadPlanForRunToAddress(false, func_start_address,true); 2957ce490c6SJim Ingham } 2967ce490c6SJim Ingham } 2977ce490c6SJim Ingham } 298f02a2e96SJim Ingham } 2997ce490c6SJim Ingham 3004d56e9c1SJim Ingham if (!m_sub_plan_sp) 30130fdc8d8SChris Lattner { 30230fdc8d8SChris Lattner m_no_more_plans = true; 30330fdc8d8SChris Lattner SetPlanComplete(); 30430fdc8d8SChris Lattner return true; 30530fdc8d8SChris Lattner } 30630fdc8d8SChris Lattner else 30730fdc8d8SChris Lattner { 30830fdc8d8SChris Lattner m_no_more_plans = false; 3092bdbfd50SJim Ingham m_sub_plan_sp->SetPrivate(true); 31030fdc8d8SChris Lattner return false; 31130fdc8d8SChris Lattner } 31230fdc8d8SChris Lattner } 31330fdc8d8SChris Lattner 31430fdc8d8SChris Lattner void 315a56c8006SJim Ingham ThreadPlanStepInRange::SetAvoidRegexp(const char *name) 316a56c8006SJim Ingham { 317*e65b2cf2SEugene Zelenko if (!m_avoid_regexp_ap) 318a56c8006SJim Ingham m_avoid_regexp_ap.reset (new RegularExpression(name)); 319a56c8006SJim Ingham 320a56c8006SJim Ingham m_avoid_regexp_ap->Compile (name); 321a56c8006SJim Ingham } 322a56c8006SJim Ingham 323a56c8006SJim Ingham void 32430fdc8d8SChris Lattner ThreadPlanStepInRange::SetDefaultFlagValue (uint32_t new_value) 32530fdc8d8SChris Lattner { 32630fdc8d8SChris Lattner // TODO: Should we test this for sanity? 32730fdc8d8SChris Lattner ThreadPlanStepInRange::s_default_flag_values = new_value; 32830fdc8d8SChris Lattner } 32930fdc8d8SChris Lattner 330a56c8006SJim Ingham bool 3314da6206dSJim Ingham ThreadPlanStepInRange::FrameMatchesAvoidCriteria () 332a56c8006SJim Ingham { 333b57e4a1bSJason Molenda StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get(); 334a56c8006SJim Ingham 3354da6206dSJim Ingham // Check the library list first, as that's cheapest: 336a786e539SJim Ingham bool libraries_say_avoid = false; 337a786e539SJim Ingham 3384da6206dSJim Ingham FileSpecList libraries_to_avoid (GetThread().GetLibrariesToAvoid()); 3394da6206dSJim Ingham size_t num_libraries = libraries_to_avoid.GetSize(); 340a786e539SJim Ingham if (num_libraries > 0) 341a786e539SJim Ingham { 3424da6206dSJim Ingham SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule)); 3434da6206dSJim Ingham FileSpec frame_library(sc.module_sp->GetFileSpec()); 3444da6206dSJim Ingham 3454da6206dSJim Ingham if (frame_library) 3464da6206dSJim Ingham { 3474da6206dSJim Ingham for (size_t i = 0; i < num_libraries; i++) 3484da6206dSJim Ingham { 3494da6206dSJim Ingham const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i)); 3504da6206dSJim Ingham if (FileSpec::Equal (file_spec, frame_library, false)) 3514da6206dSJim Ingham { 3524da6206dSJim Ingham libraries_say_avoid = true; 3534da6206dSJim Ingham break; 3544da6206dSJim Ingham } 3554da6206dSJim Ingham } 3564da6206dSJim Ingham } 357a786e539SJim Ingham } 3584da6206dSJim Ingham if (libraries_say_avoid) 3594da6206dSJim Ingham return true; 3604da6206dSJim Ingham 36167cc0636SGreg Clayton const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get(); 362*e65b2cf2SEugene Zelenko if (avoid_regexp_to_use == nullptr) 363ee8aea10SJim Ingham avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp(); 364ee8aea10SJim Ingham 365*e65b2cf2SEugene Zelenko if (avoid_regexp_to_use != nullptr) 366a56c8006SJim Ingham { 3674592cbc4SGreg Clayton SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol); 368*e65b2cf2SEugene Zelenko if (sc.symbol != nullptr) 369a56c8006SJim Ingham { 3705aa27e1aSTamas Berghammer const char *frame_function_name = sc.GetFunctionName(Mangled::ePreferDemangledWithoutArguments).GetCString(); 3714592cbc4SGreg Clayton if (frame_function_name) 3723101ba33SJim Ingham { 373cf2667c4SJim Ingham size_t num_matches = 0; 3745160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 3753101ba33SJim Ingham if (log) 376cf2667c4SJim Ingham num_matches = 1; 377bc43cab5SGreg Clayton 378bc43cab5SGreg Clayton RegularExpression::Match regex_match(num_matches); 379bc43cab5SGreg Clayton 380bc43cab5SGreg Clayton bool return_value = avoid_regexp_to_use->Execute(frame_function_name, ®ex_match); 381cf2667c4SJim Ingham if (return_value) 382cf2667c4SJim Ingham { 383cf2667c4SJim Ingham if (log) 384cf2667c4SJim Ingham { 385cf2667c4SJim Ingham std::string match; 386bc43cab5SGreg Clayton regex_match.GetMatchAtIndex(frame_function_name,0, match); 387cf2667c4SJim Ingham log->Printf ("Stepping out of function \"%s\" because it matches the avoid regexp \"%s\" - match substring: \"%s\".", 3883101ba33SJim Ingham frame_function_name, 389cf2667c4SJim Ingham avoid_regexp_to_use->GetText(), 390cf2667c4SJim Ingham match.c_str()); 391cf2667c4SJim Ingham } 3923101ba33SJim Ingham 3933101ba33SJim Ingham } 3943101ba33SJim Ingham return return_value; 3953101ba33SJim Ingham } 396a56c8006SJim Ingham } 397a56c8006SJim Ingham } 398a56c8006SJim Ingham return false; 399a56c8006SJim Ingham } 400a56c8006SJim Ingham 4014b4b2478SJim Ingham bool 4024b4b2478SJim Ingham ThreadPlanStepInRange::DefaultShouldStopHereCallback (ThreadPlan *current_plan, Flags &flags, FrameComparison operation, void *baton) 40330fdc8d8SChris Lattner { 4044b4b2478SJim Ingham bool should_stop_here = true; 405b57e4a1bSJason Molenda StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get(); 4065160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 40730fdc8d8SChris Lattner 4080c2b9d2aSJim Ingham // First see if the ThreadPlanShouldStopHere default implementation thinks we should get out of here: 4090c2b9d2aSJim Ingham should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback (current_plan, flags, operation, baton); 4100c2b9d2aSJim Ingham if (!should_stop_here) 4110c2b9d2aSJim Ingham return should_stop_here; 412a56c8006SJim Ingham 4134b4b2478SJim Ingham if (should_stop_here && current_plan->GetKind() == eKindStepInRange && operation == eFrameCompareYounger) 414a56c8006SJim Ingham { 415a56c8006SJim Ingham ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan); 416c627682eSJim Ingham if (step_in_range_plan->m_step_into_target) 417c627682eSJim Ingham { 418c627682eSJim Ingham SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol); 419*e65b2cf2SEugene Zelenko if (sc.symbol != nullptr) 420c627682eSJim Ingham { 421c627682eSJim Ingham // First try an exact match, since that's cheap with ConstStrings. Then do a strstr compare. 422c627682eSJim Ingham if (step_in_range_plan->m_step_into_target == sc.GetFunctionName()) 423c627682eSJim Ingham { 4244b4b2478SJim Ingham should_stop_here = true; 425c627682eSJim Ingham } 426c627682eSJim Ingham else 427c627682eSJim Ingham { 428c627682eSJim Ingham const char *target_name = step_in_range_plan->m_step_into_target.AsCString(); 429c627682eSJim Ingham const char *function_name = sc.GetFunctionName().AsCString(); 430c627682eSJim Ingham 431*e65b2cf2SEugene Zelenko if (function_name == nullptr) 4324b4b2478SJim Ingham should_stop_here = false; 433*e65b2cf2SEugene Zelenko else if (strstr(function_name, target_name) == nullptr) 4344b4b2478SJim Ingham should_stop_here = false; 435c627682eSJim Ingham } 4364b4b2478SJim Ingham if (log && !should_stop_here) 4373101ba33SJim Ingham log->Printf("Stepping out of frame %s which did not match step into target %s.", 4383101ba33SJim Ingham sc.GetFunctionName().AsCString(), 4393101ba33SJim Ingham step_in_range_plan->m_step_into_target.AsCString()); 440c627682eSJim Ingham } 441c627682eSJim Ingham } 442c627682eSJim Ingham 4434b4b2478SJim Ingham if (should_stop_here) 444c627682eSJim Ingham { 445c627682eSJim Ingham ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan); 4464da6206dSJim Ingham // Don't log the should_step_out here, it's easier to do it in FrameMatchesAvoidCriteria. 4474b4b2478SJim Ingham should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria (); 448a56c8006SJim Ingham } 449a56c8006SJim Ingham } 450a56c8006SJim Ingham 4514b4b2478SJim Ingham return should_stop_here; 45230fdc8d8SChris Lattner } 453fbbfe6ecSJim Ingham 454fbbfe6ecSJim Ingham bool 455221d51cfSJim Ingham ThreadPlanStepInRange::DoPlanExplainsStop (Event *event_ptr) 456fbbfe6ecSJim Ingham { 457fbbfe6ecSJim Ingham // We always explain a stop. Either we've just done a single step, in which 458fbbfe6ecSJim Ingham // case we'll do our ordinary processing, or we stopped for some 459fbbfe6ecSJim Ingham // reason that isn't handled by our sub-plans, in which case we want to just stop right 460fbbfe6ecSJim Ingham // away. 461c627682eSJim Ingham // In general, we don't want to mark the plan as complete for unexplained stops. 462c627682eSJim Ingham // For instance, if you step in to some code with no debug info, so you step out 463c627682eSJim Ingham // and in the course of that hit a breakpoint, then you want to stop & show the user 464c627682eSJim Ingham // the breakpoint, but not unship the step in plan, since you still may want to complete that 465c627682eSJim Ingham // plan when you continue. This is particularly true when doing "step in to target function." 466c627682eSJim Ingham // stepping. 467fbbfe6ecSJim Ingham // 468fbbfe6ecSJim Ingham // The only variation is that if we are doing "step by running to next branch" in which case 469fbbfe6ecSJim Ingham // if we hit our branch breakpoint we don't set the plan to complete. 470fbbfe6ecSJim Ingham 4719b03fa0cSJim Ingham bool return_value = false; 472f02a2e96SJim Ingham 473221d51cfSJim Ingham if (m_virtual_step) 474221d51cfSJim Ingham { 475221d51cfSJim Ingham return_value = true; 476221d51cfSJim Ingham } 477221d51cfSJim Ingham else 478221d51cfSJim Ingham { 47960c4118cSJim Ingham StopInfoSP stop_info_sp = GetPrivateStopInfo (); 480fbbfe6ecSJim Ingham if (stop_info_sp) 481fbbfe6ecSJim Ingham { 482fbbfe6ecSJim Ingham StopReason reason = stop_info_sp->GetStopReason(); 483fbbfe6ecSJim Ingham 4849b03fa0cSJim Ingham if (reason == eStopReasonBreakpoint) 485fbbfe6ecSJim Ingham { 486fbbfe6ecSJim Ingham if (NextRangeBreakpointExplainsStop(stop_info_sp)) 487221d51cfSJim Ingham { 488221d51cfSJim Ingham return_value = true; 489221d51cfSJim Ingham } 4909b03fa0cSJim Ingham } 4919b03fa0cSJim Ingham else if (IsUsuallyUnexplainedStopReason(reason)) 492513c6bb8SJim Ingham { 4935160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 494fbbfe6ecSJim Ingham if (log) 495fbbfe6ecSJim Ingham log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step."); 496221d51cfSJim Ingham return_value = false; 4979b03fa0cSJim Ingham } 4989b03fa0cSJim Ingham else 4999b03fa0cSJim Ingham { 500221d51cfSJim Ingham return_value = true; 501fbbfe6ecSJim Ingham } 502fbbfe6ecSJim Ingham } 503221d51cfSJim Ingham else 504221d51cfSJim Ingham return_value = true; 505221d51cfSJim Ingham } 506221d51cfSJim Ingham 507221d51cfSJim Ingham return return_value; 508fbbfe6ecSJim Ingham } 509513c6bb8SJim Ingham 510513c6bb8SJim Ingham bool 511221d51cfSJim Ingham ThreadPlanStepInRange::DoWillResume (lldb::StateType resume_state, bool current_plan) 512513c6bb8SJim Ingham { 51369fc298aSTamas Berghammer m_virtual_step = false; 514513c6bb8SJim Ingham if (resume_state == eStateStepping && current_plan) 515513c6bb8SJim Ingham { 516513c6bb8SJim Ingham // See if we are about to step over a virtual inlined call. 517513c6bb8SJim Ingham bool step_without_resume = m_thread.DecrementCurrentInlinedDepth(); 518513c6bb8SJim Ingham if (step_without_resume) 519513c6bb8SJim Ingham { 5205160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 521513c6bb8SJim Ingham if (log) 522221d51cfSJim Ingham log->Printf ("ThreadPlanStepInRange::DoWillResume: returning false, inline_depth: %d", 523513c6bb8SJim Ingham m_thread.GetCurrentInlinedDepth()); 524513c6bb8SJim Ingham SetStopInfo(StopInfo::CreateStopReasonToTrace(m_thread)); 525f02a2e96SJim Ingham 526f02a2e96SJim Ingham // FIXME: Maybe it would be better to create a InlineStep stop reason, but then 527f02a2e96SJim Ingham // the whole rest of the world would have to handle that stop reason. 528f02a2e96SJim Ingham m_virtual_step = true; 529513c6bb8SJim Ingham } 530513c6bb8SJim Ingham return !step_without_resume; 531513c6bb8SJim Ingham } 532221d51cfSJim Ingham return true; 533513c6bb8SJim Ingham } 534246cb611SDaniel Malea 535246cb611SDaniel Malea bool 536246cb611SDaniel Malea ThreadPlanStepInRange::IsVirtualStep() 537246cb611SDaniel Malea { 538246cb611SDaniel Malea return m_virtual_step; 539246cb611SDaniel Malea } 540