1 //===-- ThreadPlanStepInRange.h ---------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_TARGET_THREADPLANSTEPINRANGE_H
10 #define LLDB_TARGET_THREADPLANSTEPINRANGE_H
11 
12 #include "lldb/Core/AddressRange.h"
13 #include "lldb/Target/StackID.h"
14 #include "lldb/Target/Thread.h"
15 #include "lldb/Target/ThreadPlanShouldStopHere.h"
16 #include "lldb/Target/ThreadPlanStepRange.h"
17 
18 namespace lldb_private {
19 
20 class ThreadPlanStepInRange : public ThreadPlanStepRange,
21                               public ThreadPlanShouldStopHere {
22 public:
23   ThreadPlanStepInRange(Thread &thread, const AddressRange &range,
24                         const SymbolContext &addr_context,
25                         lldb::RunMode stop_others,
26                         LazyBool step_in_avoids_code_without_debug_info,
27                         LazyBool step_out_avoids_code_without_debug_info);
28 
29   ThreadPlanStepInRange(Thread &thread, const AddressRange &range,
30                         const SymbolContext &addr_context,
31                         const char *step_into_function_name,
32                         lldb::RunMode stop_others,
33                         LazyBool step_in_avoids_code_without_debug_info,
34                         LazyBool step_out_avoids_code_without_debug_info);
35 
36   ~ThreadPlanStepInRange() override;
37 
38   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
39 
40   bool ShouldStop(Event *event_ptr) override;
41 
42   void SetAvoidRegexp(const char *name);
43 
44   void SetStepInTarget(const char *target) {
45     m_step_into_target.SetCString(target);
46   }
47 
48   static void SetDefaultFlagValue(uint32_t new_value);
49 
50   bool IsVirtualStep() override;
51 
52   // Plans that are implementing parts of a step in might need to follow the
53   // behavior of this plan w.r.t. StepThrough.  They can get that from here.
54   static uint32_t GetDefaultFlagsValue() {
55     return s_default_flag_values;
56   }
57 
58 protected:
59   static bool DefaultShouldStopHereCallback(ThreadPlan *current_plan,
60                                             Flags &flags,
61                                             lldb::FrameComparison operation,
62                                             Status &status, void *baton);
63 
64   bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
65 
66   bool DoPlanExplainsStop(Event *event_ptr) override;
67 
68   void SetFlagsToDefault() override {
69     GetFlags().Set(ThreadPlanStepInRange::s_default_flag_values);
70   }
71 
72   void SetCallbacks() {
73     ThreadPlanShouldStopHere::ThreadPlanShouldStopHereCallbacks callbacks(
74         ThreadPlanStepInRange::DefaultShouldStopHereCallback, nullptr);
75     SetShouldStopHereCallbacks(&callbacks, nullptr);
76   }
77 
78   bool FrameMatchesAvoidCriteria();
79 
80 private:
81   friend lldb::ThreadPlanSP Thread::QueueThreadPlanForStepOverRange(
82       bool abort_other_plans, const AddressRange &range,
83       const SymbolContext &addr_context, lldb::RunMode stop_others,
84       Status &status, LazyBool avoid_code_without_debug_info);
85   friend lldb::ThreadPlanSP Thread::QueueThreadPlanForStepInRange(
86       bool abort_other_plans, const AddressRange &range,
87       const SymbolContext &addr_context, const char *step_in_target,
88       lldb::RunMode stop_others, Status &status,
89       LazyBool step_in_avoids_code_without_debug_info,
90       LazyBool step_out_avoids_code_without_debug_info);
91 
92   void SetupAvoidNoDebug(LazyBool step_in_avoids_code_without_debug_info,
93                          LazyBool step_out_avoids_code_without_debug_info);
94   // Need an appropriate marker for the current stack so we can tell step out
95   // from step in.
96 
97   static uint32_t s_default_flag_values; // These are the default flag values
98                                          // for the ThreadPlanStepThrough.
99   lldb::ThreadPlanSP m_sub_plan_sp;      // Keep track of the last plan we were
100                                     // running.  If it fails, we should stop.
101   std::unique_ptr<RegularExpression> m_avoid_regexp_up;
102   bool m_step_past_prologue; // FIXME: For now hard-coded to true, we could put
103                              // a switch in for this if there's
104                              // demand for that.
105   bool m_virtual_step; // true if we've just done a "virtual step", i.e. just
106                        // moved the inline stack depth.
107   ConstString m_step_into_target;
108   DISALLOW_COPY_AND_ASSIGN(ThreadPlanStepInRange);
109 };
110 
111 } // namespace lldb_private
112 
113 #endif // LLDB_TARGET_THREADPLANSTEPINRANGE_H
114