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