xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Target/ThreadPlanStepOut.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- ThreadPlanStepOut.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_THREADPLANSTEPOUT_H
10 #define LLDB_TARGET_THREADPLANSTEPOUT_H
11 
12 #include "lldb/Target/Thread.h"
13 #include "lldb/Target/ThreadPlan.h"
14 #include "lldb/Target/ThreadPlanShouldStopHere.h"
15 
16 namespace lldb_private {
17 
18 class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
19 public:
20   /// Creates a thread plan to step out from frame_idx, skipping parent frames
21   /// if they are artificial or hidden frames. Also skips frames without debug
22   /// info based on step_out_avoids_code_without_debug_info.
23   ThreadPlanStepOut(Thread &thread, SymbolContext *addr_context,
24                     bool first_insn, bool stop_others, Vote report_stop_vote,
25                     Vote report_run_vote, uint32_t frame_idx,
26                     LazyBool step_out_avoids_code_without_debug_info,
27                     bool continue_to_next_branch = false,
28                     bool gather_return_value = true);
29 
30   /// Creates a thread plan to step out from frame_idx to frame_idx + 1.
31   ThreadPlanStepOut(Thread &thread, bool stop_others, Vote report_stop_vote,
32                     Vote report_run_vote, uint32_t frame_idx,
33                     bool continue_to_next_branch = false,
34                     bool gather_return_value = true);
35 
36   ~ThreadPlanStepOut() override;
37 
38   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
39   bool ValidatePlan(Stream *error) override;
40   bool ShouldStop(Event *event_ptr) override;
41   bool StopOthers() override;
SetStopOthers(bool new_value)42   void SetStopOthers(bool new_value) override { m_stop_others = new_value; }
43   lldb::StateType GetPlanRunState() override;
44   bool WillStop() override;
45   bool MischiefManaged() override;
46   void DidPush() override;
47   bool IsPlanStale() override;
48 
GetReturnValueObject()49   lldb::ValueObjectSP GetReturnValueObject() override {
50     return m_return_valobj_sp;
51   }
52 
53 protected:
SetFlagsToDefault()54   void SetFlagsToDefault() override {
55     GetFlags().Set(ThreadPlanStepOut::s_default_flag_values);
56   }
57 
58   bool DoPlanExplainsStop(Event *event_ptr) override;
59   bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
60   bool QueueInlinedStepPlan(bool queue_now);
61 
62 private:
63   static uint32_t s_default_flag_values; // These are the default flag values
64                                          // for the ThreadPlanStepThrough.
65 
66   lldb::addr_t m_step_from_insn;
67   StackID m_step_out_to_id;
68   StackID m_immediate_step_from_id;
69   lldb::break_id_t m_return_bp_id;
70   lldb::addr_t m_return_addr;
71   bool m_stop_others;
72   lldb::ThreadPlanSP m_step_out_to_inline_plan_sp; // This plan implements step
73                                                    // out to the real function
74                                                    // containing
75   // an inlined frame so we can then step out of that.
76   lldb::ThreadPlanSP m_step_through_inline_plan_sp; // This plan then steps past
77                                                     // the inlined frame(s).
78   lldb::ThreadPlanSP m_step_out_further_plan_sp; // This plan keeps stepping out
79                                                  // if ShouldStopHere told us
80                                                  // to.
81   Function *m_immediate_step_from_function;
82   std::vector<lldb::StackFrameSP> m_stepped_past_frames;
83   lldb::ValueObjectSP m_return_valobj_sp;
84   bool m_calculate_return_value;
85   StreamString m_constructor_errors;
86 
87   friend lldb::ThreadPlanSP Thread::QueueThreadPlanForStepOut(
88       bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
89       bool stop_others, Vote report_stop_vote, Vote report_run_vote,
90       uint32_t frame_idx, Status &status,
91       LazyBool step_out_avoids_code_without_debug_info);
92 
93   void SetupAvoidNoDebug(LazyBool step_out_avoids_code_without_debug_info);
94 
95   void SetupReturnAddress(lldb::StackFrameSP return_frame_sp,
96                           lldb::StackFrameSP immediate_return_from_sp,
97                           uint32_t frame_idx, bool continue_to_next_branch);
98   // Need an appropriate marker for the current stack so we can tell step out
99   // from step in.
100 
101   void CalculateReturnValue();
102 
103   ThreadPlanStepOut(const ThreadPlanStepOut &) = delete;
104   const ThreadPlanStepOut &operator=(const ThreadPlanStepOut &) = delete;
105 };
106 
107 } // namespace lldb_private
108 
109 #endif // LLDB_TARGET_THREADPLANSTEPOUT_H
110