• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- AppleThreadPlanStepThroughObjCTrampoline.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_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLETHREADPLANSTEPTHROUGHOBJCTRAMPOLINE_H
10 #define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLETHREADPLANSTEPTHROUGHOBJCTRAMPOLINE_H
11 
12 #include "AppleObjCTrampolineHandler.h"
13 #include "lldb/Core/Value.h"
14 #include "lldb/Target/ThreadPlan.h"
15 #include "lldb/Target/ThreadPlanStepInRange.h"
16 #include "lldb/Target/ThreadPlanStepOut.h"
17 #include "lldb/Target/ThreadPlanShouldStopHere.h"
18 #include "lldb/lldb-enumerations.h"
19 #include "lldb/lldb-types.h"
20 
21 namespace lldb_private {
22 
23 class AppleThreadPlanStepThroughObjCTrampoline : public ThreadPlan {
24 public:
25   AppleThreadPlanStepThroughObjCTrampoline(
26       Thread &thread, AppleObjCTrampolineHandler &trampoline_handler,
27       ValueList &values, lldb::addr_t isa_addr, lldb::addr_t sel_addr,
28       bool stop_others);
29 
30   ~AppleThreadPlanStepThroughObjCTrampoline() override;
31 
32   static bool PreResumeInitializeFunctionCaller(void *myself);
33 
34   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
35 
36   bool ValidatePlan(Stream *error) override;
37 
38   lldb::StateType GetPlanRunState() override;
39 
40   bool ShouldStop(Event *event_ptr) override;
41 
StopOthers()42   bool StopOthers() override { return m_stop_others; }
43 
44   // The base class MischiefManaged does some cleanup - so you have to call it
45   // in your MischiefManaged derived class.
46   bool MischiefManaged() override;
47 
48   void DidPush() override;
49 
50   bool WillStop() override;
51 
52 protected:
53   bool DoPlanExplainsStop(Event *event_ptr) override;
54 
55 private:
56   bool InitializeFunctionCaller();
57 
58   AppleObjCTrampolineHandler &m_trampoline_handler; /// The handler itself.
59   lldb::addr_t m_args_addr; /// Stores the address for our step through function
60                             /// result structure.
61   ValueList m_input_values;
62   lldb::addr_t m_isa_addr; /// isa_addr and sel_addr are the keys we will use to
63                            /// cache the implementation.
64   lldb::addr_t m_sel_addr;
65   lldb::ThreadPlanSP m_func_sp; /// This is the function call plan.  We fill it
66                                 /// at start, then set it to NULL when this plan
67                                 /// is done.  That way we know to go on to:
68   lldb::ThreadPlanSP m_run_to_sp;  /// The plan that runs to the target.
69   FunctionCaller *m_impl_function; /// This is a pointer to a impl function that
70                                    /// is owned by the client that pushes this
71                                    /// plan.
72   bool m_stop_others;  /// Whether we should stop other threads.
73 };
74 
75 class AppleThreadPlanStepThroughDirectDispatch: public ThreadPlanStepOut {
76 public:
77   AppleThreadPlanStepThroughDirectDispatch(
78       Thread &thread, AppleObjCTrampolineHandler &handler,
79       llvm::StringRef dispatch_func_name, bool stop_others,
80       LazyBool step_in_avoids_code_without_debug_info);
81 
82   ~AppleThreadPlanStepThroughDirectDispatch() override;
83 
84   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
85 
86   bool ShouldStop(Event *event_ptr) override;
87 
StopOthers()88   bool StopOthers() override { return m_stop_others; }
89 
90   bool MischiefManaged() override;
91 
92   bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
93 
SetFlagsToDefault()94   void SetFlagsToDefault() override {
95           GetFlags().Set(ThreadPlanStepInRange::GetDefaultFlagsValue());
96   }
97 
98 protected:
99   bool DoPlanExplainsStop(Event *event_ptr) override;
100 
101   AppleObjCTrampolineHandler &m_trampoline_handler;
102   std::string m_dispatch_func_name;  /// Which dispatch function we're stepping
103                                      /// through.
104   lldb::ThreadPlanSP m_objc_step_through_sp; /// When we hit an objc_msgSend,
105                                              /// we'll use this plan to get to
106                                              /// its target.
107   std::vector<lldb::BreakpointSP> m_msgSend_bkpts; /// Breakpoints on the objc
108                                                    /// dispatch functions.
109   bool m_at_msg_send;  /// Are we currently handling an msg_send
110   bool m_stop_others;  /// Whether we should stop other threads.
111 
112 };
113 
114 } // namespace lldb_private
115 
116 #endif // LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLETHREADPLANSTEPTHROUGHOBJCTRAMPOLINE_H
117