15ffd83dbSDimitry Andric //===-- ThreadPlanStepInRange.cpp -----------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/Target/ThreadPlanStepInRange.h"
100b57cec5SDimitry Andric #include "lldb/Core/Architecture.h"
110b57cec5SDimitry Andric #include "lldb/Core/Module.h"
120b57cec5SDimitry Andric #include "lldb/Symbol/Function.h"
130b57cec5SDimitry Andric #include "lldb/Symbol/Symbol.h"
140b57cec5SDimitry Andric #include "lldb/Target/Process.h"
150b57cec5SDimitry Andric #include "lldb/Target/RegisterContext.h"
160b57cec5SDimitry Andric #include "lldb/Target/SectionLoadList.h"
170b57cec5SDimitry Andric #include "lldb/Target/Target.h"
180b57cec5SDimitry Andric #include "lldb/Target/Thread.h"
190b57cec5SDimitry Andric #include "lldb/Target/ThreadPlanStepOut.h"
200b57cec5SDimitry Andric #include "lldb/Target/ThreadPlanStepThrough.h"
21*81ad6265SDimitry Andric #include "lldb/Utility/LLDBLog.h"
220b57cec5SDimitry Andric #include "lldb/Utility/Log.h"
230b57cec5SDimitry Andric #include "lldb/Utility/RegularExpression.h"
240b57cec5SDimitry Andric #include "lldb/Utility/Stream.h"
250b57cec5SDimitry Andric
260b57cec5SDimitry Andric using namespace lldb;
270b57cec5SDimitry Andric using namespace lldb_private;
280b57cec5SDimitry Andric
290b57cec5SDimitry Andric uint32_t ThreadPlanStepInRange::s_default_flag_values =
300b57cec5SDimitry Andric ThreadPlanShouldStopHere::eStepInAvoidNoDebug;
310b57cec5SDimitry Andric
320b57cec5SDimitry Andric // ThreadPlanStepInRange: Step through a stack range, either stepping over or
330b57cec5SDimitry Andric // into based on the value of \a type.
340b57cec5SDimitry Andric
ThreadPlanStepInRange(Thread & thread,const AddressRange & range,const SymbolContext & addr_context,const char * step_into_target,lldb::RunMode stop_others,LazyBool step_in_avoids_code_without_debug_info,LazyBool step_out_avoids_code_without_debug_info)350b57cec5SDimitry Andric ThreadPlanStepInRange::ThreadPlanStepInRange(
360b57cec5SDimitry Andric Thread &thread, const AddressRange &range,
37fe6060f1SDimitry Andric const SymbolContext &addr_context, const char *step_into_target,
38fe6060f1SDimitry Andric lldb::RunMode stop_others, LazyBool step_in_avoids_code_without_debug_info,
390b57cec5SDimitry Andric LazyBool step_out_avoids_code_without_debug_info)
400b57cec5SDimitry Andric : ThreadPlanStepRange(ThreadPlan::eKindStepInRange,
410b57cec5SDimitry Andric "Step Range stepping in", thread, range, addr_context,
420b57cec5SDimitry Andric stop_others),
430b57cec5SDimitry Andric ThreadPlanShouldStopHere(this), m_step_past_prologue(true),
44fe6060f1SDimitry Andric m_virtual_step(false), m_step_into_target(step_into_target) {
450b57cec5SDimitry Andric SetCallbacks();
460b57cec5SDimitry Andric SetFlagsToDefault();
470b57cec5SDimitry Andric SetupAvoidNoDebug(step_in_avoids_code_without_debug_info,
480b57cec5SDimitry Andric step_out_avoids_code_without_debug_info);
490b57cec5SDimitry Andric }
500b57cec5SDimitry Andric
510b57cec5SDimitry Andric ThreadPlanStepInRange::~ThreadPlanStepInRange() = default;
520b57cec5SDimitry Andric
SetupAvoidNoDebug(LazyBool step_in_avoids_code_without_debug_info,LazyBool step_out_avoids_code_without_debug_info)530b57cec5SDimitry Andric void ThreadPlanStepInRange::SetupAvoidNoDebug(
540b57cec5SDimitry Andric LazyBool step_in_avoids_code_without_debug_info,
550b57cec5SDimitry Andric LazyBool step_out_avoids_code_without_debug_info) {
560b57cec5SDimitry Andric bool avoid_nodebug = true;
575ffd83dbSDimitry Andric Thread &thread = GetThread();
580b57cec5SDimitry Andric switch (step_in_avoids_code_without_debug_info) {
590b57cec5SDimitry Andric case eLazyBoolYes:
600b57cec5SDimitry Andric avoid_nodebug = true;
610b57cec5SDimitry Andric break;
620b57cec5SDimitry Andric case eLazyBoolNo:
630b57cec5SDimitry Andric avoid_nodebug = false;
640b57cec5SDimitry Andric break;
650b57cec5SDimitry Andric case eLazyBoolCalculate:
665ffd83dbSDimitry Andric avoid_nodebug = thread.GetStepInAvoidsNoDebug();
670b57cec5SDimitry Andric break;
680b57cec5SDimitry Andric }
690b57cec5SDimitry Andric if (avoid_nodebug)
700b57cec5SDimitry Andric GetFlags().Set(ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
710b57cec5SDimitry Andric else
720b57cec5SDimitry Andric GetFlags().Clear(ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
730b57cec5SDimitry Andric
740b57cec5SDimitry Andric switch (step_out_avoids_code_without_debug_info) {
750b57cec5SDimitry Andric case eLazyBoolYes:
760b57cec5SDimitry Andric avoid_nodebug = true;
770b57cec5SDimitry Andric break;
780b57cec5SDimitry Andric case eLazyBoolNo:
790b57cec5SDimitry Andric avoid_nodebug = false;
800b57cec5SDimitry Andric break;
810b57cec5SDimitry Andric case eLazyBoolCalculate:
825ffd83dbSDimitry Andric avoid_nodebug = thread.GetStepOutAvoidsNoDebug();
830b57cec5SDimitry Andric break;
840b57cec5SDimitry Andric }
850b57cec5SDimitry Andric if (avoid_nodebug)
860b57cec5SDimitry Andric GetFlags().Set(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
870b57cec5SDimitry Andric else
880b57cec5SDimitry Andric GetFlags().Clear(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
890b57cec5SDimitry Andric }
900b57cec5SDimitry Andric
GetDescription(Stream * s,lldb::DescriptionLevel level)910b57cec5SDimitry Andric void ThreadPlanStepInRange::GetDescription(Stream *s,
920b57cec5SDimitry Andric lldb::DescriptionLevel level) {
930b57cec5SDimitry Andric
940b57cec5SDimitry Andric auto PrintFailureIfAny = [&]() {
950b57cec5SDimitry Andric if (m_status.Success())
960b57cec5SDimitry Andric return;
970b57cec5SDimitry Andric s->Printf(" failed (%s)", m_status.AsCString());
980b57cec5SDimitry Andric };
990b57cec5SDimitry Andric
1000b57cec5SDimitry Andric if (level == lldb::eDescriptionLevelBrief) {
1010b57cec5SDimitry Andric s->Printf("step in");
1020b57cec5SDimitry Andric PrintFailureIfAny();
1030b57cec5SDimitry Andric return;
1040b57cec5SDimitry Andric }
1050b57cec5SDimitry Andric
1060b57cec5SDimitry Andric s->Printf("Stepping in");
1070b57cec5SDimitry Andric bool printed_line_info = false;
1080b57cec5SDimitry Andric if (m_addr_context.line_entry.IsValid()) {
1090b57cec5SDimitry Andric s->Printf(" through line ");
1100b57cec5SDimitry Andric m_addr_context.line_entry.DumpStopContext(s, false);
1110b57cec5SDimitry Andric printed_line_info = true;
1120b57cec5SDimitry Andric }
1130b57cec5SDimitry Andric
1140b57cec5SDimitry Andric const char *step_into_target = m_step_into_target.AsCString();
1150b57cec5SDimitry Andric if (step_into_target && step_into_target[0] != '\0')
1160b57cec5SDimitry Andric s->Printf(" targeting %s", m_step_into_target.AsCString());
1170b57cec5SDimitry Andric
1180b57cec5SDimitry Andric if (!printed_line_info || level == eDescriptionLevelVerbose) {
1190b57cec5SDimitry Andric s->Printf(" using ranges:");
1200b57cec5SDimitry Andric DumpRanges(s);
1210b57cec5SDimitry Andric }
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric PrintFailureIfAny();
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andric s->PutChar('.');
1260b57cec5SDimitry Andric }
1270b57cec5SDimitry Andric
ShouldStop(Event * event_ptr)1280b57cec5SDimitry Andric bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) {
129*81ad6265SDimitry Andric Log *log = GetLog(LLDBLog::Step);
1300b57cec5SDimitry Andric
1310b57cec5SDimitry Andric if (log) {
1320b57cec5SDimitry Andric StreamString s;
1335ffd83dbSDimitry Andric DumpAddress(s.AsRawOstream(), GetThread().GetRegisterContext()->GetPC(),
1345ffd83dbSDimitry Andric GetTarget().GetArchitecture().GetAddressByteSize());
1359dba64beSDimitry Andric LLDB_LOGF(log, "ThreadPlanStepInRange reached %s.", s.GetData());
1360b57cec5SDimitry Andric }
1370b57cec5SDimitry Andric
1380b57cec5SDimitry Andric if (IsPlanComplete())
1390b57cec5SDimitry Andric return true;
1400b57cec5SDimitry Andric
1410b57cec5SDimitry Andric m_no_more_plans = false;
1420b57cec5SDimitry Andric if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete()) {
1430b57cec5SDimitry Andric if (!m_sub_plan_sp->PlanSucceeded()) {
1440b57cec5SDimitry Andric SetPlanComplete();
1450b57cec5SDimitry Andric m_no_more_plans = true;
1460b57cec5SDimitry Andric return true;
1470b57cec5SDimitry Andric } else
1480b57cec5SDimitry Andric m_sub_plan_sp.reset();
1490b57cec5SDimitry Andric }
1500b57cec5SDimitry Andric
1510b57cec5SDimitry Andric if (m_virtual_step) {
1520b57cec5SDimitry Andric // If we've just completed a virtual step, all we need to do is check for a
1530b57cec5SDimitry Andric // ShouldStopHere plan, and otherwise we're done.
1540b57cec5SDimitry Andric // FIXME - This can be both a step in and a step out. Probably should
1550b57cec5SDimitry Andric // record which in the m_virtual_step.
1560b57cec5SDimitry Andric m_sub_plan_sp =
1570b57cec5SDimitry Andric CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger, m_status);
1580b57cec5SDimitry Andric } else {
1590b57cec5SDimitry Andric // Stepping through should be done running other threads in general, since
1600b57cec5SDimitry Andric // we're setting a breakpoint and continuing. So only stop others if we
1610b57cec5SDimitry Andric // are explicitly told to do so.
1620b57cec5SDimitry Andric
1630b57cec5SDimitry Andric bool stop_others = (m_stop_others == lldb::eOnlyThisThread);
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric FrameComparison frame_order = CompareCurrentFrameToStartFrame();
1660b57cec5SDimitry Andric
1675ffd83dbSDimitry Andric Thread &thread = GetThread();
1680b57cec5SDimitry Andric if (frame_order == eFrameCompareOlder ||
1690b57cec5SDimitry Andric frame_order == eFrameCompareSameParent) {
1700b57cec5SDimitry Andric // If we're in an older frame then we should stop.
1710b57cec5SDimitry Andric //
1720b57cec5SDimitry Andric // A caveat to this is if we think the frame is older but we're actually
1730b57cec5SDimitry Andric // in a trampoline.
1740b57cec5SDimitry Andric // I'm going to make the assumption that you wouldn't RETURN to a
1750b57cec5SDimitry Andric // trampoline. So if we are in a trampoline we think the frame is older
1760b57cec5SDimitry Andric // because the trampoline confused the backtracer.
1775ffd83dbSDimitry Andric m_sub_plan_sp = thread.QueueThreadPlanForStepThrough(
1780b57cec5SDimitry Andric m_stack_id, false, stop_others, m_status);
1790b57cec5SDimitry Andric if (!m_sub_plan_sp) {
1800b57cec5SDimitry Andric // Otherwise check the ShouldStopHere for step out:
1810b57cec5SDimitry Andric m_sub_plan_sp =
1820b57cec5SDimitry Andric CheckShouldStopHereAndQueueStepOut(frame_order, m_status);
1830b57cec5SDimitry Andric if (log) {
1840b57cec5SDimitry Andric if (m_sub_plan_sp)
1859dba64beSDimitry Andric LLDB_LOGF(log,
1869dba64beSDimitry Andric "ShouldStopHere found plan to step out of this frame.");
1870b57cec5SDimitry Andric else
1889dba64beSDimitry Andric LLDB_LOGF(log, "ShouldStopHere no plan to step out of this frame.");
1890b57cec5SDimitry Andric }
1900b57cec5SDimitry Andric } else if (log) {
1919dba64beSDimitry Andric LLDB_LOGF(
1929dba64beSDimitry Andric log, "Thought I stepped out, but in fact arrived at a trampoline.");
1930b57cec5SDimitry Andric }
1940b57cec5SDimitry Andric } else if (frame_order == eFrameCompareEqual && InSymbol()) {
1950b57cec5SDimitry Andric // If we are not in a place we should step through, we're done. One
1960b57cec5SDimitry Andric // tricky bit here is that some stubs don't push a frame, so we have to
1970b57cec5SDimitry Andric // check both the case of a frame that is younger, or the same as this
1980b57cec5SDimitry Andric // frame. However, if the frame is the same, and we are still in the
1990b57cec5SDimitry Andric // symbol we started in, the we don't need to do this. This first check
2000b57cec5SDimitry Andric // isn't strictly necessary, but it is more efficient.
2010b57cec5SDimitry Andric
2020b57cec5SDimitry Andric // If we're still in the range, keep going, either by running to the next
2030b57cec5SDimitry Andric // branch breakpoint, or by stepping.
2040b57cec5SDimitry Andric if (InRange()) {
2050b57cec5SDimitry Andric SetNextBranchBreakpoint();
2060b57cec5SDimitry Andric return false;
2070b57cec5SDimitry Andric }
2080b57cec5SDimitry Andric
2090b57cec5SDimitry Andric SetPlanComplete();
2100b57cec5SDimitry Andric m_no_more_plans = true;
2110b57cec5SDimitry Andric return true;
2120b57cec5SDimitry Andric }
2130b57cec5SDimitry Andric
2140b57cec5SDimitry Andric // If we get to this point, we're not going to use a previously set "next
2150b57cec5SDimitry Andric // branch" breakpoint, so delete it:
2160b57cec5SDimitry Andric ClearNextBranchBreakpoint();
2170b57cec5SDimitry Andric
2180b57cec5SDimitry Andric // We may have set the plan up above in the FrameIsOlder section:
2190b57cec5SDimitry Andric
2200b57cec5SDimitry Andric if (!m_sub_plan_sp)
2215ffd83dbSDimitry Andric m_sub_plan_sp = thread.QueueThreadPlanForStepThrough(
2220b57cec5SDimitry Andric m_stack_id, false, stop_others, m_status);
2230b57cec5SDimitry Andric
2240b57cec5SDimitry Andric if (log) {
2250b57cec5SDimitry Andric if (m_sub_plan_sp)
2269dba64beSDimitry Andric LLDB_LOGF(log, "Found a step through plan: %s",
2279dba64beSDimitry Andric m_sub_plan_sp->GetName());
2280b57cec5SDimitry Andric else
2299dba64beSDimitry Andric LLDB_LOGF(log, "No step through plan found.");
2300b57cec5SDimitry Andric }
2310b57cec5SDimitry Andric
2320b57cec5SDimitry Andric // If not, give the "should_stop" callback a chance to push a plan to get
2330b57cec5SDimitry Andric // us out of here. But only do that if we actually have stepped in.
2340b57cec5SDimitry Andric if (!m_sub_plan_sp && frame_order == eFrameCompareYounger)
2350b57cec5SDimitry Andric m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order, m_status);
2360b57cec5SDimitry Andric
2370b57cec5SDimitry Andric // If we've stepped in and we are going to stop here, check to see if we
2380b57cec5SDimitry Andric // were asked to run past the prologue, and if so do that.
2390b57cec5SDimitry Andric
2400b57cec5SDimitry Andric if (!m_sub_plan_sp && frame_order == eFrameCompareYounger &&
2410b57cec5SDimitry Andric m_step_past_prologue) {
2425ffd83dbSDimitry Andric lldb::StackFrameSP curr_frame = thread.GetStackFrameAtIndex(0);
2430b57cec5SDimitry Andric if (curr_frame) {
2440b57cec5SDimitry Andric size_t bytes_to_skip = 0;
2455ffd83dbSDimitry Andric lldb::addr_t curr_addr = thread.GetRegisterContext()->GetPC();
2460b57cec5SDimitry Andric Address func_start_address;
2470b57cec5SDimitry Andric
2480b57cec5SDimitry Andric SymbolContext sc = curr_frame->GetSymbolContext(eSymbolContextFunction |
2490b57cec5SDimitry Andric eSymbolContextSymbol);
2500b57cec5SDimitry Andric
2510b57cec5SDimitry Andric if (sc.function) {
2520b57cec5SDimitry Andric func_start_address = sc.function->GetAddressRange().GetBaseAddress();
2535ffd83dbSDimitry Andric if (curr_addr == func_start_address.GetLoadAddress(&GetTarget()))
2540b57cec5SDimitry Andric bytes_to_skip = sc.function->GetPrologueByteSize();
2550b57cec5SDimitry Andric } else if (sc.symbol) {
2560b57cec5SDimitry Andric func_start_address = sc.symbol->GetAddress();
2575ffd83dbSDimitry Andric if (curr_addr == func_start_address.GetLoadAddress(&GetTarget()))
2580b57cec5SDimitry Andric bytes_to_skip = sc.symbol->GetPrologueByteSize();
2590b57cec5SDimitry Andric }
2600b57cec5SDimitry Andric
2610b57cec5SDimitry Andric if (bytes_to_skip == 0 && sc.symbol) {
2625ffd83dbSDimitry Andric const Architecture *arch = GetTarget().GetArchitecturePlugin();
2630b57cec5SDimitry Andric if (arch) {
2640b57cec5SDimitry Andric Address curr_sec_addr;
2655ffd83dbSDimitry Andric GetTarget().GetSectionLoadList().ResolveLoadAddress(curr_addr,
2660b57cec5SDimitry Andric curr_sec_addr);
2670b57cec5SDimitry Andric bytes_to_skip = arch->GetBytesToSkip(*sc.symbol, curr_sec_addr);
2680b57cec5SDimitry Andric }
2690b57cec5SDimitry Andric }
2700b57cec5SDimitry Andric
2710b57cec5SDimitry Andric if (bytes_to_skip != 0) {
2720b57cec5SDimitry Andric func_start_address.Slide(bytes_to_skip);
273*81ad6265SDimitry Andric log = GetLog(LLDBLog::Step);
2749dba64beSDimitry Andric LLDB_LOGF(log, "Pushing past prologue ");
2750b57cec5SDimitry Andric
2765ffd83dbSDimitry Andric m_sub_plan_sp = thread.QueueThreadPlanForRunToAddress(
2770b57cec5SDimitry Andric false, func_start_address, true, m_status);
2780b57cec5SDimitry Andric }
2790b57cec5SDimitry Andric }
2800b57cec5SDimitry Andric }
2810b57cec5SDimitry Andric }
2820b57cec5SDimitry Andric
2830b57cec5SDimitry Andric if (!m_sub_plan_sp) {
2840b57cec5SDimitry Andric m_no_more_plans = true;
2850b57cec5SDimitry Andric SetPlanComplete();
2860b57cec5SDimitry Andric return true;
2870b57cec5SDimitry Andric } else {
2880b57cec5SDimitry Andric m_no_more_plans = false;
2890b57cec5SDimitry Andric m_sub_plan_sp->SetPrivate(true);
2900b57cec5SDimitry Andric return false;
2910b57cec5SDimitry Andric }
2920b57cec5SDimitry Andric }
2930b57cec5SDimitry Andric
SetAvoidRegexp(const char * name)2940b57cec5SDimitry Andric void ThreadPlanStepInRange::SetAvoidRegexp(const char *name) {
2959dba64beSDimitry Andric if (m_avoid_regexp_up)
296fe6060f1SDimitry Andric *m_avoid_regexp_up = RegularExpression(name);
2979dba64beSDimitry Andric else
298fe6060f1SDimitry Andric m_avoid_regexp_up = std::make_unique<RegularExpression>(name);
2990b57cec5SDimitry Andric }
3000b57cec5SDimitry Andric
SetDefaultFlagValue(uint32_t new_value)3010b57cec5SDimitry Andric void ThreadPlanStepInRange::SetDefaultFlagValue(uint32_t new_value) {
3020b57cec5SDimitry Andric // TODO: Should we test this for sanity?
3030b57cec5SDimitry Andric ThreadPlanStepInRange::s_default_flag_values = new_value;
3040b57cec5SDimitry Andric }
3050b57cec5SDimitry Andric
FrameMatchesAvoidCriteria()3060b57cec5SDimitry Andric bool ThreadPlanStepInRange::FrameMatchesAvoidCriteria() {
3070b57cec5SDimitry Andric StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
3080b57cec5SDimitry Andric
3090b57cec5SDimitry Andric // Check the library list first, as that's cheapest:
3100b57cec5SDimitry Andric bool libraries_say_avoid = false;
3110b57cec5SDimitry Andric
3120b57cec5SDimitry Andric FileSpecList libraries_to_avoid(GetThread().GetLibrariesToAvoid());
3130b57cec5SDimitry Andric size_t num_libraries = libraries_to_avoid.GetSize();
3140b57cec5SDimitry Andric if (num_libraries > 0) {
3150b57cec5SDimitry Andric SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
3160b57cec5SDimitry Andric FileSpec frame_library(sc.module_sp->GetFileSpec());
3170b57cec5SDimitry Andric
3180b57cec5SDimitry Andric if (frame_library) {
3190b57cec5SDimitry Andric for (size_t i = 0; i < num_libraries; i++) {
3200b57cec5SDimitry Andric const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
321480093f4SDimitry Andric if (FileSpec::Match(file_spec, frame_library)) {
3220b57cec5SDimitry Andric libraries_say_avoid = true;
3230b57cec5SDimitry Andric break;
3240b57cec5SDimitry Andric }
3250b57cec5SDimitry Andric }
3260b57cec5SDimitry Andric }
3270b57cec5SDimitry Andric }
3280b57cec5SDimitry Andric if (libraries_say_avoid)
3290b57cec5SDimitry Andric return true;
3300b57cec5SDimitry Andric
3310b57cec5SDimitry Andric const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_up.get();
3320b57cec5SDimitry Andric if (avoid_regexp_to_use == nullptr)
3330b57cec5SDimitry Andric avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
3340b57cec5SDimitry Andric
3350b57cec5SDimitry Andric if (avoid_regexp_to_use != nullptr) {
3360b57cec5SDimitry Andric SymbolContext sc = frame->GetSymbolContext(
3370b57cec5SDimitry Andric eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
3380b57cec5SDimitry Andric if (sc.symbol != nullptr) {
3390b57cec5SDimitry Andric const char *frame_function_name =
3400b57cec5SDimitry Andric sc.GetFunctionName(Mangled::ePreferDemangledWithoutArguments)
3410b57cec5SDimitry Andric .GetCString();
3420b57cec5SDimitry Andric if (frame_function_name) {
343*81ad6265SDimitry Andric bool return_value = avoid_regexp_to_use->Execute(frame_function_name);
344*81ad6265SDimitry Andric if (return_value) {
345*81ad6265SDimitry Andric LLDB_LOGF(GetLog(LLDBLog::Step),
346*81ad6265SDimitry Andric "Stepping out of function \"%s\" because it matches the "
347*81ad6265SDimitry Andric "avoid regexp \"%s\".",
3480b57cec5SDimitry Andric frame_function_name,
349*81ad6265SDimitry Andric avoid_regexp_to_use->GetText().str().c_str());
3500b57cec5SDimitry Andric }
3510b57cec5SDimitry Andric return return_value;
3520b57cec5SDimitry Andric }
3530b57cec5SDimitry Andric }
3540b57cec5SDimitry Andric }
3550b57cec5SDimitry Andric return false;
3560b57cec5SDimitry Andric }
3570b57cec5SDimitry Andric
DefaultShouldStopHereCallback(ThreadPlan * current_plan,Flags & flags,FrameComparison operation,Status & status,void * baton)3580b57cec5SDimitry Andric bool ThreadPlanStepInRange::DefaultShouldStopHereCallback(
3590b57cec5SDimitry Andric ThreadPlan *current_plan, Flags &flags, FrameComparison operation,
3600b57cec5SDimitry Andric Status &status, void *baton) {
3610b57cec5SDimitry Andric bool should_stop_here = true;
3620b57cec5SDimitry Andric StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
363*81ad6265SDimitry Andric Log *log = GetLog(LLDBLog::Step);
3640b57cec5SDimitry Andric
3650b57cec5SDimitry Andric // First see if the ThreadPlanShouldStopHere default implementation thinks we
3660b57cec5SDimitry Andric // should get out of here:
3670b57cec5SDimitry Andric should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback(
3680b57cec5SDimitry Andric current_plan, flags, operation, status, baton);
3690b57cec5SDimitry Andric if (!should_stop_here)
370480093f4SDimitry Andric return false;
3710b57cec5SDimitry Andric
3720b57cec5SDimitry Andric if (should_stop_here && current_plan->GetKind() == eKindStepInRange &&
3730b57cec5SDimitry Andric operation == eFrameCompareYounger) {
3740b57cec5SDimitry Andric ThreadPlanStepInRange *step_in_range_plan =
3750b57cec5SDimitry Andric static_cast<ThreadPlanStepInRange *>(current_plan);
3760b57cec5SDimitry Andric if (step_in_range_plan->m_step_into_target) {
3770b57cec5SDimitry Andric SymbolContext sc = frame->GetSymbolContext(
3780b57cec5SDimitry Andric eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
3790b57cec5SDimitry Andric if (sc.symbol != nullptr) {
3800b57cec5SDimitry Andric // First try an exact match, since that's cheap with ConstStrings.
3810b57cec5SDimitry Andric // Then do a strstr compare.
3820b57cec5SDimitry Andric if (step_in_range_plan->m_step_into_target == sc.GetFunctionName()) {
3830b57cec5SDimitry Andric should_stop_here = true;
3840b57cec5SDimitry Andric } else {
3850b57cec5SDimitry Andric const char *target_name =
3860b57cec5SDimitry Andric step_in_range_plan->m_step_into_target.AsCString();
3870b57cec5SDimitry Andric const char *function_name = sc.GetFunctionName().AsCString();
3880b57cec5SDimitry Andric
3890b57cec5SDimitry Andric if (function_name == nullptr)
3900b57cec5SDimitry Andric should_stop_here = false;
3910b57cec5SDimitry Andric else if (strstr(function_name, target_name) == nullptr)
3920b57cec5SDimitry Andric should_stop_here = false;
3930b57cec5SDimitry Andric }
3940b57cec5SDimitry Andric if (log && !should_stop_here)
3959dba64beSDimitry Andric LLDB_LOGF(log,
3969dba64beSDimitry Andric "Stepping out of frame %s which did not match step into "
3970b57cec5SDimitry Andric "target %s.",
3980b57cec5SDimitry Andric sc.GetFunctionName().AsCString(),
3990b57cec5SDimitry Andric step_in_range_plan->m_step_into_target.AsCString());
4000b57cec5SDimitry Andric }
4010b57cec5SDimitry Andric }
4020b57cec5SDimitry Andric
4030b57cec5SDimitry Andric if (should_stop_here) {
4040b57cec5SDimitry Andric ThreadPlanStepInRange *step_in_range_plan =
4050b57cec5SDimitry Andric static_cast<ThreadPlanStepInRange *>(current_plan);
4060b57cec5SDimitry Andric // Don't log the should_step_out here, it's easier to do it in
4070b57cec5SDimitry Andric // FrameMatchesAvoidCriteria.
4080b57cec5SDimitry Andric should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria();
4090b57cec5SDimitry Andric }
4100b57cec5SDimitry Andric }
4110b57cec5SDimitry Andric
4120b57cec5SDimitry Andric return should_stop_here;
4130b57cec5SDimitry Andric }
4140b57cec5SDimitry Andric
DoPlanExplainsStop(Event * event_ptr)4150b57cec5SDimitry Andric bool ThreadPlanStepInRange::DoPlanExplainsStop(Event *event_ptr) {
4160b57cec5SDimitry Andric // We always explain a stop. Either we've just done a single step, in which
4170b57cec5SDimitry Andric // case we'll do our ordinary processing, or we stopped for some reason that
4180b57cec5SDimitry Andric // isn't handled by our sub-plans, in which case we want to just stop right
4190b57cec5SDimitry Andric // away. In general, we don't want to mark the plan as complete for
4200b57cec5SDimitry Andric // unexplained stops. For instance, if you step in to some code with no debug
4210b57cec5SDimitry Andric // info, so you step out and in the course of that hit a breakpoint, then you
4220b57cec5SDimitry Andric // want to stop & show the user the breakpoint, but not unship the step in
4230b57cec5SDimitry Andric // plan, since you still may want to complete that plan when you continue.
4240b57cec5SDimitry Andric // This is particularly true when doing "step in to target function."
4250b57cec5SDimitry Andric // stepping.
4260b57cec5SDimitry Andric //
4270b57cec5SDimitry Andric // The only variation is that if we are doing "step by running to next
4280b57cec5SDimitry Andric // branch" in which case if we hit our branch breakpoint we don't set the
4290b57cec5SDimitry Andric // plan to complete.
4300b57cec5SDimitry Andric
4310b57cec5SDimitry Andric bool return_value = false;
4320b57cec5SDimitry Andric
4330b57cec5SDimitry Andric if (m_virtual_step) {
4340b57cec5SDimitry Andric return_value = true;
4350b57cec5SDimitry Andric } else {
4360b57cec5SDimitry Andric StopInfoSP stop_info_sp = GetPrivateStopInfo();
4370b57cec5SDimitry Andric if (stop_info_sp) {
4380b57cec5SDimitry Andric StopReason reason = stop_info_sp->GetStopReason();
4390b57cec5SDimitry Andric
4400b57cec5SDimitry Andric if (reason == eStopReasonBreakpoint) {
4410b57cec5SDimitry Andric if (NextRangeBreakpointExplainsStop(stop_info_sp)) {
4420b57cec5SDimitry Andric return_value = true;
4430b57cec5SDimitry Andric }
4440b57cec5SDimitry Andric } else if (IsUsuallyUnexplainedStopReason(reason)) {
445*81ad6265SDimitry Andric Log *log = GetLog(LLDBLog::Step);
4460b57cec5SDimitry Andric if (log)
4470b57cec5SDimitry Andric log->PutCString("ThreadPlanStepInRange got asked if it explains the "
4480b57cec5SDimitry Andric "stop for some reason other than step.");
4490b57cec5SDimitry Andric return_value = false;
4500b57cec5SDimitry Andric } else {
4510b57cec5SDimitry Andric return_value = true;
4520b57cec5SDimitry Andric }
4530b57cec5SDimitry Andric } else
4540b57cec5SDimitry Andric return_value = true;
4550b57cec5SDimitry Andric }
4560b57cec5SDimitry Andric
4570b57cec5SDimitry Andric return return_value;
4580b57cec5SDimitry Andric }
4590b57cec5SDimitry Andric
DoWillResume(lldb::StateType resume_state,bool current_plan)4600b57cec5SDimitry Andric bool ThreadPlanStepInRange::DoWillResume(lldb::StateType resume_state,
4610b57cec5SDimitry Andric bool current_plan) {
4620b57cec5SDimitry Andric m_virtual_step = false;
4630b57cec5SDimitry Andric if (resume_state == eStateStepping && current_plan) {
4645ffd83dbSDimitry Andric Thread &thread = GetThread();
4650b57cec5SDimitry Andric // See if we are about to step over a virtual inlined call.
4665ffd83dbSDimitry Andric bool step_without_resume = thread.DecrementCurrentInlinedDepth();
4670b57cec5SDimitry Andric if (step_without_resume) {
468*81ad6265SDimitry Andric Log *log = GetLog(LLDBLog::Step);
4699dba64beSDimitry Andric LLDB_LOGF(log,
4709dba64beSDimitry Andric "ThreadPlanStepInRange::DoWillResume: returning false, "
4710b57cec5SDimitry Andric "inline_depth: %d",
4725ffd83dbSDimitry Andric thread.GetCurrentInlinedDepth());
4735ffd83dbSDimitry Andric SetStopInfo(StopInfo::CreateStopReasonToTrace(thread));
4740b57cec5SDimitry Andric
4750b57cec5SDimitry Andric // FIXME: Maybe it would be better to create a InlineStep stop reason, but
4760b57cec5SDimitry Andric // then
4770b57cec5SDimitry Andric // the whole rest of the world would have to handle that stop reason.
4780b57cec5SDimitry Andric m_virtual_step = true;
4790b57cec5SDimitry Andric }
4800b57cec5SDimitry Andric return !step_without_resume;
4810b57cec5SDimitry Andric }
4820b57cec5SDimitry Andric return true;
4830b57cec5SDimitry Andric }
4840b57cec5SDimitry Andric
IsVirtualStep()4850b57cec5SDimitry Andric bool ThreadPlanStepInRange::IsVirtualStep() { return m_virtual_step; }
486