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 liblldb_ThreadPlanStepInRange_h_
10 #define liblldb_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 protected:
53   static bool DefaultShouldStopHereCallback(ThreadPlan *current_plan,
54                                             Flags &flags,
55                                             lldb::FrameComparison operation,
56                                             Status &status, void *baton);
57 
58   bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
59 
60   bool DoPlanExplainsStop(Event *event_ptr) override;
61 
62   void SetFlagsToDefault() override {
63     GetFlags().Set(ThreadPlanStepInRange::s_default_flag_values);
64   }
65 
66   void SetCallbacks() {
67     ThreadPlanShouldStopHere::ThreadPlanShouldStopHereCallbacks callbacks(
68         ThreadPlanStepInRange::DefaultShouldStopHereCallback, nullptr);
69     SetShouldStopHereCallbacks(&callbacks, nullptr);
70   }
71 
72   bool FrameMatchesAvoidCriteria();
73 
74 private:
75   friend lldb::ThreadPlanSP Thread::QueueThreadPlanForStepOverRange(
76       bool abort_other_plans, const AddressRange &range,
77       const SymbolContext &addr_context, lldb::RunMode stop_others,
78       Status &status, LazyBool avoid_code_without_debug_info);
79   friend lldb::ThreadPlanSP Thread::QueueThreadPlanForStepInRange(
80       bool abort_other_plans, const AddressRange &range,
81       const SymbolContext &addr_context, const char *step_in_target,
82       lldb::RunMode stop_others, Status &status,
83       LazyBool step_in_avoids_code_without_debug_info,
84       LazyBool step_out_avoids_code_without_debug_info);
85 
86   void SetupAvoidNoDebug(LazyBool step_in_avoids_code_without_debug_info,
87                          LazyBool step_out_avoids_code_without_debug_info);
88   // Need an appropriate marker for the current stack so we can tell step out
89   // from step in.
90 
91   static uint32_t s_default_flag_values; // These are the default flag values
92                                          // for the ThreadPlanStepThrough.
93   lldb::ThreadPlanSP m_sub_plan_sp;      // Keep track of the last plan we were
94                                     // running.  If it fails, we should stop.
95   std::unique_ptr<RegularExpression> m_avoid_regexp_up;
96   bool m_step_past_prologue; // FIXME: For now hard-coded to true, we could put
97                              // a switch in for this if there's
98                              // demand for that.
99   bool m_virtual_step; // true if we've just done a "virtual step", i.e. just
100                        // moved the inline stack depth.
101   ConstString m_step_into_target;
102   DISALLOW_COPY_AND_ASSIGN(ThreadPlanStepInRange);
103 };
104 
105 } // namespace lldb_private
106 
107 #endif // liblldb_ThreadPlanStepInRange_h_
108