180814287SRaphael Isemann //===-- ThreadPlanStepInRange.cpp -----------------------------------------===// 230fdc8d8SChris Lattner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 630fdc8d8SChris Lattner // 730fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 830fdc8d8SChris Lattner 9e65b2cf2SEugene Zelenko #include "lldb/Target/ThreadPlanStepInRange.h" 1008581263SJim Ingham #include "lldb/Core/Architecture.h" 114da6206dSJim Ingham #include "lldb/Core/Module.h" 127ce490c6SJim Ingham #include "lldb/Symbol/Function.h" 13b9c1b51eSKate Stone #include "lldb/Symbol/Symbol.h" 1430fdc8d8SChris Lattner #include "lldb/Target/Process.h" 1530fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.h" 1608581263SJim Ingham #include "lldb/Target/SectionLoadList.h" 17514487e8SGreg Clayton #include "lldb/Target/Target.h" 1830fdc8d8SChris Lattner #include "lldb/Target/Thread.h" 1930fdc8d8SChris Lattner #include "lldb/Target/ThreadPlanStepOut.h" 2030fdc8d8SChris Lattner #include "lldb/Target/ThreadPlanStepThrough.h" 216f9e6901SZachary Turner #include "lldb/Utility/Log.h" 22bf9a7730SZachary Turner #include "lldb/Utility/RegularExpression.h" 23bf9a7730SZachary Turner #include "lldb/Utility/Stream.h" 2430fdc8d8SChris Lattner 2530fdc8d8SChris Lattner using namespace lldb; 2630fdc8d8SChris Lattner using namespace lldb_private; 2730fdc8d8SChris Lattner 28b9c1b51eSKate Stone uint32_t ThreadPlanStepInRange::s_default_flag_values = 29b9c1b51eSKate Stone ThreadPlanShouldStopHere::eStepInAvoidNoDebug; 3030fdc8d8SChris Lattner 31b9c1b51eSKate Stone // ThreadPlanStepInRange: Step through a stack range, either stepping over or 3205097246SAdrian Prantl // into based on the value of \a type. 3330fdc8d8SChris Lattner 34b9c1b51eSKate Stone ThreadPlanStepInRange::ThreadPlanStepInRange( 35b9c1b51eSKate Stone Thread &thread, const AddressRange &range, 36b9c1b51eSKate Stone const SymbolContext &addr_context, lldb::RunMode stop_others, 374b4b2478SJim Ingham LazyBool step_in_avoids_code_without_debug_info, 38b9c1b51eSKate Stone LazyBool step_out_avoids_code_without_debug_info) 39b9c1b51eSKate Stone : ThreadPlanStepRange(ThreadPlan::eKindStepInRange, 40b9c1b51eSKate Stone "Step Range stepping in", thread, range, addr_context, 41b9c1b51eSKate Stone stop_others), 42b9c1b51eSKate Stone ThreadPlanShouldStopHere(this), m_step_past_prologue(true), 43b9c1b51eSKate Stone m_virtual_step(false) { 444b4b2478SJim Ingham SetCallbacks(); 4530fdc8d8SChris Lattner SetFlagsToDefault(); 46b9c1b51eSKate Stone SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, 47b9c1b51eSKate Stone step_out_avoids_code_without_debug_info); 4830fdc8d8SChris Lattner } 4930fdc8d8SChris Lattner 50b9c1b51eSKate Stone ThreadPlanStepInRange::ThreadPlanStepInRange( 51b9c1b51eSKate Stone Thread &thread, const AddressRange &range, 52b9c1b51eSKate Stone const SymbolContext &addr_context, const char *step_into_target, 53b9c1b51eSKate Stone lldb::RunMode stop_others, LazyBool step_in_avoids_code_without_debug_info, 54b9c1b51eSKate Stone LazyBool step_out_avoids_code_without_debug_info) 55b9c1b51eSKate Stone : ThreadPlanStepRange(ThreadPlan::eKindStepInRange, 56b9c1b51eSKate Stone "Step Range stepping in", thread, range, addr_context, 57b9c1b51eSKate Stone stop_others), 58b9c1b51eSKate Stone ThreadPlanShouldStopHere(this), m_step_past_prologue(true), 59b9c1b51eSKate Stone m_virtual_step(false), m_step_into_target(step_into_target) { 604b4b2478SJim Ingham SetCallbacks(); 61c627682eSJim Ingham SetFlagsToDefault(); 62b9c1b51eSKate Stone SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, 63b9c1b51eSKate Stone step_out_avoids_code_without_debug_info); 64c627682eSJim Ingham } 65c627682eSJim Ingham 66e65b2cf2SEugene Zelenko ThreadPlanStepInRange::~ThreadPlanStepInRange() = default; 6730fdc8d8SChris Lattner 68b9c1b51eSKate Stone void ThreadPlanStepInRange::SetupAvoidNoDebug( 69b9c1b51eSKate Stone LazyBool step_in_avoids_code_without_debug_info, 70b9c1b51eSKate Stone LazyBool step_out_avoids_code_without_debug_info) { 714b4b2478SJim Ingham bool avoid_nodebug = true; 72*e4598dc0SJim Ingham Thread &thread = GetThread(); 73b9c1b51eSKate Stone switch (step_in_avoids_code_without_debug_info) { 744b4b2478SJim Ingham case eLazyBoolYes: 754b4b2478SJim Ingham avoid_nodebug = true; 764b4b2478SJim Ingham break; 774b4b2478SJim Ingham case eLazyBoolNo: 784b4b2478SJim Ingham avoid_nodebug = false; 794b4b2478SJim Ingham break; 804b4b2478SJim Ingham case eLazyBoolCalculate: 81*e4598dc0SJim Ingham avoid_nodebug = thread.GetStepInAvoidsNoDebug(); 824b4b2478SJim Ingham break; 834b4b2478SJim Ingham } 844b4b2478SJim Ingham if (avoid_nodebug) 854b4b2478SJim Ingham GetFlags().Set(ThreadPlanShouldStopHere::eStepInAvoidNoDebug); 864b4b2478SJim Ingham else 874b4b2478SJim Ingham GetFlags().Clear(ThreadPlanShouldStopHere::eStepInAvoidNoDebug); 884b4b2478SJim Ingham 89b9c1b51eSKate Stone switch (step_out_avoids_code_without_debug_info) { 904b4b2478SJim Ingham case eLazyBoolYes: 914b4b2478SJim Ingham avoid_nodebug = true; 924b4b2478SJim Ingham break; 934b4b2478SJim Ingham case eLazyBoolNo: 944b4b2478SJim Ingham avoid_nodebug = false; 954b4b2478SJim Ingham break; 964b4b2478SJim Ingham case eLazyBoolCalculate: 97*e4598dc0SJim Ingham avoid_nodebug = thread.GetStepOutAvoidsNoDebug(); 984b4b2478SJim Ingham break; 994b4b2478SJim Ingham } 1004b4b2478SJim Ingham if (avoid_nodebug) 1014b4b2478SJim Ingham GetFlags().Set(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug); 1024b4b2478SJim Ingham else 1034b4b2478SJim Ingham GetFlags().Clear(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug); 1044b4b2478SJim Ingham } 1054b4b2478SJim Ingham 106b9c1b51eSKate Stone void ThreadPlanStepInRange::GetDescription(Stream *s, 107b9c1b51eSKate Stone lldb::DescriptionLevel level) { 108e103ae92SJonas Devlieghere 109e103ae92SJonas Devlieghere auto PrintFailureIfAny = [&]() { 110e103ae92SJonas Devlieghere if (m_status.Success()) 111e103ae92SJonas Devlieghere return; 112e103ae92SJonas Devlieghere s->Printf(" failed (%s)", m_status.AsCString()); 113e103ae92SJonas Devlieghere }; 114e103ae92SJonas Devlieghere 115b9c1b51eSKate Stone if (level == lldb::eDescriptionLevelBrief) { 1162bdbfd50SJim Ingham s->Printf("step in"); 117e103ae92SJonas Devlieghere PrintFailureIfAny(); 1182bdbfd50SJim Ingham return; 1192bdbfd50SJim Ingham } 1202bdbfd50SJim Ingham 1212bdbfd50SJim Ingham s->Printf("Stepping in"); 1222bdbfd50SJim Ingham bool printed_line_info = false; 123b9c1b51eSKate Stone if (m_addr_context.line_entry.IsValid()) { 1242bdbfd50SJim Ingham s->Printf(" through line "); 1252bdbfd50SJim Ingham m_addr_context.line_entry.DumpStopContext(s, false); 1262bdbfd50SJim Ingham printed_line_info = true; 1272bdbfd50SJim Ingham } 1282bdbfd50SJim Ingham 1294d56e9c1SJim Ingham const char *step_into_target = m_step_into_target.AsCString(); 1304d56e9c1SJim Ingham if (step_into_target && step_into_target[0] != '\0') 1312bdbfd50SJim Ingham s->Printf(" targeting %s", m_step_into_target.AsCString()); 1322bdbfd50SJim Ingham 133b9c1b51eSKate Stone if (!printed_line_info || level == eDescriptionLevelVerbose) { 1342bdbfd50SJim Ingham s->Printf(" using ranges:"); 1352bdbfd50SJim Ingham DumpRanges(s); 13630fdc8d8SChris Lattner } 1372bdbfd50SJim Ingham 138e103ae92SJonas Devlieghere PrintFailureIfAny(); 139e103ae92SJonas Devlieghere 1402bdbfd50SJim Ingham s->PutChar('.'); 14130fdc8d8SChris Lattner } 14230fdc8d8SChris Lattner 143b9c1b51eSKate Stone bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) { 1445160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); 14530fdc8d8SChris Lattner 146b9c1b51eSKate Stone if (log) { 14730fdc8d8SChris Lattner StreamString s; 148*e4598dc0SJim Ingham DumpAddress(s.AsRawOstream(), GetThread().GetRegisterContext()->GetPC(), 149*e4598dc0SJim Ingham GetTarget().GetArchitecture().GetAddressByteSize()); 15063e5fb76SJonas Devlieghere LLDB_LOGF(log, "ThreadPlanStepInRange reached %s.", s.GetData()); 15130fdc8d8SChris Lattner } 15230fdc8d8SChris Lattner 15325f66700SJim Ingham if (IsPlanComplete()) 15425f66700SJim Ingham return true; 15525f66700SJim Ingham 1564d56e9c1SJim Ingham m_no_more_plans = false; 157b9c1b51eSKate Stone if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete()) { 158b9c1b51eSKate Stone if (!m_sub_plan_sp->PlanSucceeded()) { 1594d56e9c1SJim Ingham SetPlanComplete(); 1604d56e9c1SJim Ingham m_no_more_plans = true; 1614d56e9c1SJim Ingham return true; 162b9c1b51eSKate Stone } else 1634d56e9c1SJim Ingham m_sub_plan_sp.reset(); 1644d56e9c1SJim Ingham } 16530fdc8d8SChris Lattner 166b9c1b51eSKate Stone if (m_virtual_step) { 167b9c1b51eSKate Stone // If we've just completed a virtual step, all we need to do is check for a 16805097246SAdrian Prantl // ShouldStopHere plan, and otherwise we're done. 169b9c1b51eSKate Stone // FIXME - This can be both a step in and a step out. Probably should 170b9c1b51eSKate Stone // record which in the m_virtual_step. 171e103ae92SJonas Devlieghere m_sub_plan_sp = 172e103ae92SJonas Devlieghere CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger, m_status); 173b9c1b51eSKate Stone } else { 174b9c1b51eSKate Stone // Stepping through should be done running other threads in general, since 17505097246SAdrian Prantl // we're setting a breakpoint and continuing. So only stop others if we 17605097246SAdrian Prantl // are explicitly told to do so. 1779d790c5dSJim Ingham 178e65b2cf2SEugene Zelenko bool stop_others = (m_stop_others == lldb::eOnlyThisThread); 17930fdc8d8SChris Lattner 180b5c0d1ccSJim Ingham FrameComparison frame_order = CompareCurrentFrameToStartFrame(); 181b5c0d1ccSJim Ingham 182*e4598dc0SJim Ingham Thread &thread = GetThread(); 183b9c1b51eSKate Stone if (frame_order == eFrameCompareOlder || 184b9c1b51eSKate Stone frame_order == eFrameCompareSameParent) { 1855822173bSJim Ingham // If we're in an older frame then we should stop. 1865822173bSJim Ingham // 187b9c1b51eSKate Stone // A caveat to this is if we think the frame is older but we're actually 188b9c1b51eSKate Stone // in a trampoline. 189b9c1b51eSKate Stone // I'm going to make the assumption that you wouldn't RETURN to a 19005097246SAdrian Prantl // trampoline. So if we are in a trampoline we think the frame is older 19105097246SAdrian Prantl // because the trampoline confused the backtracer. 192*e4598dc0SJim Ingham m_sub_plan_sp = thread.QueueThreadPlanForStepThrough( 193e103ae92SJonas Devlieghere m_stack_id, false, stop_others, m_status); 194b9c1b51eSKate Stone if (!m_sub_plan_sp) { 1954b4b2478SJim Ingham // Otherwise check the ShouldStopHere for step out: 196e103ae92SJonas Devlieghere m_sub_plan_sp = 197e103ae92SJonas Devlieghere CheckShouldStopHereAndQueueStepOut(frame_order, m_status); 198a4bb80b2SJim Ingham if (log) { 199a4bb80b2SJim Ingham if (m_sub_plan_sp) 20063e5fb76SJonas Devlieghere LLDB_LOGF(log, 20163e5fb76SJonas Devlieghere "ShouldStopHere found plan to step out of this frame."); 202a4bb80b2SJim Ingham else 20363e5fb76SJonas Devlieghere LLDB_LOGF(log, "ShouldStopHere no plan to step out of this frame."); 204a4bb80b2SJim Ingham } 205b9c1b51eSKate Stone } else if (log) { 20663e5fb76SJonas Devlieghere LLDB_LOGF( 20763e5fb76SJonas Devlieghere log, "Thought I stepped out, but in fact arrived at a trampoline."); 2084b4b2478SJim Ingham } 209b9c1b51eSKate Stone } else if (frame_order == eFrameCompareEqual && InSymbol()) { 21005097246SAdrian Prantl // If we are not in a place we should step through, we're done. One 21105097246SAdrian Prantl // tricky bit here is that some stubs don't push a frame, so we have to 21205097246SAdrian Prantl // check both the case of a frame that is younger, or the same as this 21305097246SAdrian Prantl // frame. However, if the frame is the same, and we are still in the 21405097246SAdrian Prantl // symbol we started in, the we don't need to do this. This first check 21505097246SAdrian Prantl // isn't strictly necessary, but it is more efficient. 2165822173bSJim Ingham 217b9c1b51eSKate Stone // If we're still in the range, keep going, either by running to the next 21805097246SAdrian Prantl // branch breakpoint, or by stepping. 219b9c1b51eSKate Stone if (InRange()) { 220564d8bc2SJim Ingham SetNextBranchBreakpoint(); 221564d8bc2SJim Ingham return false; 222564d8bc2SJim Ingham } 223564d8bc2SJim Ingham 2245822173bSJim Ingham SetPlanComplete(); 225c627682eSJim Ingham m_no_more_plans = true; 2265822173bSJim Ingham return true; 2275822173bSJim Ingham } 2285822173bSJim Ingham 229b9c1b51eSKate Stone // If we get to this point, we're not going to use a previously set "next 230b9c1b51eSKate Stone // branch" breakpoint, so delete it: 231564d8bc2SJim Ingham ClearNextBranchBreakpoint(); 232564d8bc2SJim Ingham 2335822173bSJim Ingham // We may have set the plan up above in the FrameIsOlder section: 2345822173bSJim Ingham 2354d56e9c1SJim Ingham if (!m_sub_plan_sp) 236*e4598dc0SJim Ingham m_sub_plan_sp = thread.QueueThreadPlanForStepThrough( 237e103ae92SJonas Devlieghere m_stack_id, false, stop_others, m_status); 23808b87e0dSJim Ingham 239b9c1b51eSKate Stone if (log) { 2404d56e9c1SJim Ingham if (m_sub_plan_sp) 24163e5fb76SJonas Devlieghere LLDB_LOGF(log, "Found a step through plan: %s", 24263e5fb76SJonas Devlieghere m_sub_plan_sp->GetName()); 24308b87e0dSJim Ingham else 24463e5fb76SJonas Devlieghere LLDB_LOGF(log, "No step through plan found."); 24508b87e0dSJim Ingham } 24608b87e0dSJim Ingham 24705097246SAdrian Prantl // If not, give the "should_stop" callback a chance to push a plan to get 24805097246SAdrian Prantl // us out of here. But only do that if we actually have stepped in. 2494d56e9c1SJim Ingham if (!m_sub_plan_sp && frame_order == eFrameCompareYounger) 250e103ae92SJonas Devlieghere m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order, m_status); 25130fdc8d8SChris Lattner 252b9c1b51eSKate Stone // If we've stepped in and we are going to stop here, check to see if we 25305097246SAdrian Prantl // were asked to run past the prologue, and if so do that. 2547ce490c6SJim Ingham 255b9c1b51eSKate Stone if (!m_sub_plan_sp && frame_order == eFrameCompareYounger && 256b9c1b51eSKate Stone m_step_past_prologue) { 257*e4598dc0SJim Ingham lldb::StackFrameSP curr_frame = thread.GetStackFrameAtIndex(0); 258b9c1b51eSKate Stone if (curr_frame) { 2597ce490c6SJim Ingham size_t bytes_to_skip = 0; 260*e4598dc0SJim Ingham lldb::addr_t curr_addr = thread.GetRegisterContext()->GetPC(); 2617ce490c6SJim Ingham Address func_start_address; 2627ce490c6SJim Ingham 263b9c1b51eSKate Stone SymbolContext sc = curr_frame->GetSymbolContext(eSymbolContextFunction | 264b9c1b51eSKate Stone eSymbolContextSymbol); 2657ce490c6SJim Ingham 266b9c1b51eSKate Stone if (sc.function) { 2677ce490c6SJim Ingham func_start_address = sc.function->GetAddressRange().GetBaseAddress(); 268*e4598dc0SJim Ingham if (curr_addr == func_start_address.GetLoadAddress(&GetTarget())) 2697ce490c6SJim Ingham bytes_to_skip = sc.function->GetPrologueByteSize(); 270b9c1b51eSKate Stone } else if (sc.symbol) { 271e7612134SGreg Clayton func_start_address = sc.symbol->GetAddress(); 272*e4598dc0SJim Ingham if (curr_addr == func_start_address.GetLoadAddress(&GetTarget())) 2737ce490c6SJim Ingham bytes_to_skip = sc.symbol->GetPrologueByteSize(); 2747ce490c6SJim Ingham } 2757ce490c6SJim Ingham 27608581263SJim Ingham if (bytes_to_skip == 0 && sc.symbol) { 277*e4598dc0SJim Ingham const Architecture *arch = GetTarget().GetArchitecturePlugin(); 27808581263SJim Ingham if (arch) { 27908581263SJim Ingham Address curr_sec_addr; 280*e4598dc0SJim Ingham GetTarget().GetSectionLoadList().ResolveLoadAddress(curr_addr, 28108581263SJim Ingham curr_sec_addr); 28208581263SJim Ingham bytes_to_skip = arch->GetBytesToSkip(*sc.symbol, curr_sec_addr); 28308581263SJim Ingham } 28408581263SJim Ingham } 28508581263SJim Ingham 286b9c1b51eSKate Stone if (bytes_to_skip != 0) { 2877ce490c6SJim Ingham func_start_address.Slide(bytes_to_skip); 28820ad3c40SCaroline Tice log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP); 28963e5fb76SJonas Devlieghere LLDB_LOGF(log, "Pushing past prologue "); 2907ce490c6SJim Ingham 291*e4598dc0SJim Ingham m_sub_plan_sp = thread.QueueThreadPlanForRunToAddress( 292e103ae92SJonas Devlieghere false, func_start_address, true, m_status); 2937ce490c6SJim Ingham } 2947ce490c6SJim Ingham } 2957ce490c6SJim Ingham } 296f02a2e96SJim Ingham } 2977ce490c6SJim Ingham 298b9c1b51eSKate Stone if (!m_sub_plan_sp) { 29930fdc8d8SChris Lattner m_no_more_plans = true; 30030fdc8d8SChris Lattner SetPlanComplete(); 30130fdc8d8SChris Lattner return true; 302b9c1b51eSKate Stone } else { 30330fdc8d8SChris Lattner m_no_more_plans = false; 3042bdbfd50SJim Ingham m_sub_plan_sp->SetPrivate(true); 30530fdc8d8SChris Lattner return false; 30630fdc8d8SChris Lattner } 30730fdc8d8SChris Lattner } 30830fdc8d8SChris Lattner 309b9c1b51eSKate Stone void ThreadPlanStepInRange::SetAvoidRegexp(const char *name) { 31095eae423SZachary Turner auto name_ref = llvm::StringRef::withNullAsEmpty(name); 311f9d90bc5SJan Kratochvil if (m_avoid_regexp_up) 312f9d90bc5SJan Kratochvil *m_avoid_regexp_up = RegularExpression(name_ref); 313f9d90bc5SJan Kratochvil else 314d5b44036SJonas Devlieghere m_avoid_regexp_up.reset(new RegularExpression(name_ref)); 315a56c8006SJim Ingham } 316a56c8006SJim Ingham 317b9c1b51eSKate Stone void ThreadPlanStepInRange::SetDefaultFlagValue(uint32_t new_value) { 31830fdc8d8SChris Lattner // TODO: Should we test this for sanity? 31930fdc8d8SChris Lattner ThreadPlanStepInRange::s_default_flag_values = new_value; 32030fdc8d8SChris Lattner } 32130fdc8d8SChris Lattner 322b9c1b51eSKate Stone bool ThreadPlanStepInRange::FrameMatchesAvoidCriteria() { 323b57e4a1bSJason Molenda StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get(); 324a56c8006SJim Ingham 3254da6206dSJim Ingham // Check the library list first, as that's cheapest: 326a786e539SJim Ingham bool libraries_say_avoid = false; 327a786e539SJim Ingham 3284da6206dSJim Ingham FileSpecList libraries_to_avoid(GetThread().GetLibrariesToAvoid()); 3294da6206dSJim Ingham size_t num_libraries = libraries_to_avoid.GetSize(); 330b9c1b51eSKate Stone if (num_libraries > 0) { 3314da6206dSJim Ingham SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule)); 3324da6206dSJim Ingham FileSpec frame_library(sc.module_sp->GetFileSpec()); 3334da6206dSJim Ingham 334b9c1b51eSKate Stone if (frame_library) { 335b9c1b51eSKate Stone for (size_t i = 0; i < num_libraries; i++) { 3364da6206dSJim Ingham const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i)); 337532290e6SPavel Labath if (FileSpec::Match(file_spec, frame_library)) { 3384da6206dSJim Ingham libraries_say_avoid = true; 3394da6206dSJim Ingham break; 3404da6206dSJim Ingham } 3414da6206dSJim Ingham } 3424da6206dSJim Ingham } 343a786e539SJim Ingham } 3444da6206dSJim Ingham if (libraries_say_avoid) 3454da6206dSJim Ingham return true; 3464da6206dSJim Ingham 347d5b44036SJonas Devlieghere const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_up.get(); 348e65b2cf2SEugene Zelenko if (avoid_regexp_to_use == nullptr) 349ee8aea10SJim Ingham avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp(); 350ee8aea10SJim Ingham 351b9c1b51eSKate Stone if (avoid_regexp_to_use != nullptr) { 352b9c1b51eSKate Stone SymbolContext sc = frame->GetSymbolContext( 353b9c1b51eSKate Stone eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol); 354b9c1b51eSKate Stone if (sc.symbol != nullptr) { 355b9c1b51eSKate Stone const char *frame_function_name = 356b9c1b51eSKate Stone sc.GetFunctionName(Mangled::ePreferDemangledWithoutArguments) 357b9c1b51eSKate Stone .GetCString(); 358b9c1b51eSKate Stone if (frame_function_name) { 3593af3f1e8SJonas Devlieghere llvm::SmallVector<llvm::StringRef, 2> matches; 360b9c1b51eSKate Stone bool return_value = 3613af3f1e8SJonas Devlieghere avoid_regexp_to_use->Execute(frame_function_name, &matches); 3623af3f1e8SJonas Devlieghere if (return_value && matches.size() > 1) { 3633af3f1e8SJonas Devlieghere std::string match = matches[1].str(); 3643af3f1e8SJonas Devlieghere LLDB_LOGF(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP), 36563e5fb76SJonas Devlieghere "Stepping out of function \"%s\" because it matches " 366b9c1b51eSKate Stone "the avoid regexp \"%s\" - match substring: \"%s\".", 36795eae423SZachary Turner frame_function_name, 36895eae423SZachary Turner avoid_regexp_to_use->GetText().str().c_str(), 369cf2667c4SJim Ingham match.c_str()); 370cf2667c4SJim Ingham } 3713101ba33SJim Ingham return return_value; 3723101ba33SJim Ingham } 373a56c8006SJim Ingham } 374a56c8006SJim Ingham } 375a56c8006SJim Ingham return false; 376a56c8006SJim Ingham } 377a56c8006SJim Ingham 378b9c1b51eSKate Stone bool ThreadPlanStepInRange::DefaultShouldStopHereCallback( 379b9c1b51eSKate Stone ThreadPlan *current_plan, Flags &flags, FrameComparison operation, 380e103ae92SJonas Devlieghere Status &status, void *baton) { 3814b4b2478SJim Ingham bool should_stop_here = true; 382b57e4a1bSJason Molenda StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get(); 3835160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); 38430fdc8d8SChris Lattner 385b9c1b51eSKate Stone // First see if the ThreadPlanShouldStopHere default implementation thinks we 386b9c1b51eSKate Stone // should get out of here: 387b9c1b51eSKate Stone should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback( 388e103ae92SJonas Devlieghere current_plan, flags, operation, status, baton); 3890c2b9d2aSJim Ingham if (!should_stop_here) 390ec4c96d6SRaphael Isemann return false; 391a56c8006SJim Ingham 392b9c1b51eSKate Stone if (should_stop_here && current_plan->GetKind() == eKindStepInRange && 393b9c1b51eSKate Stone operation == eFrameCompareYounger) { 394b9c1b51eSKate Stone ThreadPlanStepInRange *step_in_range_plan = 395b9c1b51eSKate Stone static_cast<ThreadPlanStepInRange *>(current_plan); 396b9c1b51eSKate Stone if (step_in_range_plan->m_step_into_target) { 397b9c1b51eSKate Stone SymbolContext sc = frame->GetSymbolContext( 398b9c1b51eSKate Stone eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol); 399b9c1b51eSKate Stone if (sc.symbol != nullptr) { 40005097246SAdrian Prantl // First try an exact match, since that's cheap with ConstStrings. 40105097246SAdrian Prantl // Then do a strstr compare. 402b9c1b51eSKate Stone if (step_in_range_plan->m_step_into_target == sc.GetFunctionName()) { 4034b4b2478SJim Ingham should_stop_here = true; 404b9c1b51eSKate Stone } else { 405b9c1b51eSKate Stone const char *target_name = 406b9c1b51eSKate Stone step_in_range_plan->m_step_into_target.AsCString(); 407c627682eSJim Ingham const char *function_name = sc.GetFunctionName().AsCString(); 408c627682eSJim Ingham 409e65b2cf2SEugene Zelenko if (function_name == nullptr) 4104b4b2478SJim Ingham should_stop_here = false; 411e65b2cf2SEugene Zelenko else if (strstr(function_name, target_name) == nullptr) 4124b4b2478SJim Ingham should_stop_here = false; 413c627682eSJim Ingham } 4144b4b2478SJim Ingham if (log && !should_stop_here) 41563e5fb76SJonas Devlieghere LLDB_LOGF(log, 41663e5fb76SJonas Devlieghere "Stepping out of frame %s which did not match step into " 417b9c1b51eSKate Stone "target %s.", 4183101ba33SJim Ingham sc.GetFunctionName().AsCString(), 4193101ba33SJim Ingham step_in_range_plan->m_step_into_target.AsCString()); 420c627682eSJim Ingham } 421c627682eSJim Ingham } 422c627682eSJim Ingham 423b9c1b51eSKate Stone if (should_stop_here) { 424b9c1b51eSKate Stone ThreadPlanStepInRange *step_in_range_plan = 425b9c1b51eSKate Stone static_cast<ThreadPlanStepInRange *>(current_plan); 426b9c1b51eSKate Stone // Don't log the should_step_out here, it's easier to do it in 427b9c1b51eSKate Stone // FrameMatchesAvoidCriteria. 4284b4b2478SJim Ingham should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria(); 429a56c8006SJim Ingham } 430a56c8006SJim Ingham } 431a56c8006SJim Ingham 4324b4b2478SJim Ingham return should_stop_here; 43330fdc8d8SChris Lattner } 434fbbfe6ecSJim Ingham 435b9c1b51eSKate Stone bool ThreadPlanStepInRange::DoPlanExplainsStop(Event *event_ptr) { 436fbbfe6ecSJim Ingham // We always explain a stop. Either we've just done a single step, in which 43705097246SAdrian Prantl // case we'll do our ordinary processing, or we stopped for some reason that 43805097246SAdrian Prantl // isn't handled by our sub-plans, in which case we want to just stop right 43905097246SAdrian Prantl // away. In general, we don't want to mark the plan as complete for 44005097246SAdrian Prantl // unexplained stops. For instance, if you step in to some code with no debug 44105097246SAdrian Prantl // info, so you step out and in the course of that hit a breakpoint, then you 44205097246SAdrian Prantl // want to stop & show the user the breakpoint, but not unship the step in 44305097246SAdrian Prantl // plan, since you still may want to complete that plan when you continue. 44405097246SAdrian Prantl // This is particularly true when doing "step in to target function." 445c627682eSJim Ingham // stepping. 446fbbfe6ecSJim Ingham // 44705097246SAdrian Prantl // The only variation is that if we are doing "step by running to next 44805097246SAdrian Prantl // branch" in which case if we hit our branch breakpoint we don't set the 44905097246SAdrian Prantl // plan to complete. 450fbbfe6ecSJim Ingham 4519b03fa0cSJim Ingham bool return_value = false; 452f02a2e96SJim Ingham 453b9c1b51eSKate Stone if (m_virtual_step) { 454221d51cfSJim Ingham return_value = true; 455b9c1b51eSKate Stone } else { 45660c4118cSJim Ingham StopInfoSP stop_info_sp = GetPrivateStopInfo(); 457b9c1b51eSKate Stone if (stop_info_sp) { 458fbbfe6ecSJim Ingham StopReason reason = stop_info_sp->GetStopReason(); 459fbbfe6ecSJim Ingham 460b9c1b51eSKate Stone if (reason == eStopReasonBreakpoint) { 461b9c1b51eSKate Stone if (NextRangeBreakpointExplainsStop(stop_info_sp)) { 462221d51cfSJim Ingham return_value = true; 463221d51cfSJim Ingham } 464b9c1b51eSKate Stone } else if (IsUsuallyUnexplainedStopReason(reason)) { 4655160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); 466fbbfe6ecSJim Ingham if (log) 467b9c1b51eSKate Stone log->PutCString("ThreadPlanStepInRange got asked if it explains the " 468b9c1b51eSKate Stone "stop for some reason other than step."); 469221d51cfSJim Ingham return_value = false; 470b9c1b51eSKate Stone } else { 471221d51cfSJim Ingham return_value = true; 472fbbfe6ecSJim Ingham } 473b9c1b51eSKate Stone } else 474221d51cfSJim Ingham return_value = true; 475221d51cfSJim Ingham } 476221d51cfSJim Ingham 477221d51cfSJim Ingham return return_value; 478fbbfe6ecSJim Ingham } 479513c6bb8SJim Ingham 480b9c1b51eSKate Stone bool ThreadPlanStepInRange::DoWillResume(lldb::StateType resume_state, 481b9c1b51eSKate Stone bool current_plan) { 48269fc298aSTamas Berghammer m_virtual_step = false; 483b9c1b51eSKate Stone if (resume_state == eStateStepping && current_plan) { 484*e4598dc0SJim Ingham Thread &thread = GetThread(); 485513c6bb8SJim Ingham // See if we are about to step over a virtual inlined call. 486*e4598dc0SJim Ingham bool step_without_resume = thread.DecrementCurrentInlinedDepth(); 487b9c1b51eSKate Stone if (step_without_resume) { 4885160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); 48963e5fb76SJonas Devlieghere LLDB_LOGF(log, 49063e5fb76SJonas Devlieghere "ThreadPlanStepInRange::DoWillResume: returning false, " 491b9c1b51eSKate Stone "inline_depth: %d", 492*e4598dc0SJim Ingham thread.GetCurrentInlinedDepth()); 493*e4598dc0SJim Ingham SetStopInfo(StopInfo::CreateStopReasonToTrace(thread)); 494f02a2e96SJim Ingham 495b9c1b51eSKate Stone // FIXME: Maybe it would be better to create a InlineStep stop reason, but 496b9c1b51eSKate Stone // then 497f02a2e96SJim Ingham // the whole rest of the world would have to handle that stop reason. 498f02a2e96SJim Ingham m_virtual_step = true; 499513c6bb8SJim Ingham } 500513c6bb8SJim Ingham return !step_without_resume; 501513c6bb8SJim Ingham } 502221d51cfSJim Ingham return true; 503513c6bb8SJim Ingham } 504246cb611SDaniel Malea 505b9c1b51eSKate Stone bool ThreadPlanStepInRange::IsVirtualStep() { return m_virtual_step; } 506