LLDB  mainline
AppleObjCTrampolineHandler.h
Go to the documentation of this file.
1 //===-- AppleObjCTrampolineHandler.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_APPLEOBJCTRAMPOLINEHANDLER_H
10 #define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLEOBJCTRAMPOLINEHANDLER_H
11 
12 #include <map>
13 #include <mutex>
14 #include <vector>
15 
17 #include "lldb/lldb-public.h"
18 
19 namespace lldb_private {
20 
22 public:
23  AppleObjCTrampolineHandler(const lldb::ProcessSP &process_sp,
24  const lldb::ModuleSP &objc_module_sp);
25 
27 
28  lldb::ThreadPlanSP GetStepThroughDispatchPlan(Thread &thread,
29  bool stop_others);
30 
32 
33  bool AddrIsMsgForward(lldb::addr_t addr) const {
34  return (addr == m_msg_forward_addr || addr == m_msg_forward_stret_addr);
35  }
36 
38  public:
40 
41  const char *name;
43  bool is_super;
44  bool is_super2;
46  };
47 
49  ValueList &dispatch_values);
51  void ForEachDispatchFunction(std::function<void(lldb::addr_t,
52  const DispatchFunction &)>);
53 
54 private:
58 
60  public:
61  // These come from objc-gdb.h.
62  enum VTableFlags {
63  eOBJC_TRAMPOLINE_MESSAGE = (1 << 0), // trampoline acts like objc_msgSend
64  eOBJC_TRAMPOLINE_STRET = (1 << 1), // trampoline is struct-returning
65  eOBJC_TRAMPOLINE_VTABLE = (1 << 2) // trampoline is vtable dispatcher
66  };
67 
68  private:
70  VTableDescriptor(uint32_t in_flags, lldb::addr_t in_code_start)
71  : flags(in_flags), code_start(in_code_start) {}
72 
75  };
76 
77  class VTableRegion {
78  public:
79  VTableRegion() = default;
80 
81  VTableRegion(AppleObjCVTables *owner, lldb::addr_t header_addr);
82 
83  void SetUpRegion();
84 
86 
88 
90 
92 
93  bool IsValid() { return m_valid; }
94 
95  bool AddressInRegion(lldb::addr_t addr, uint32_t &flags);
96 
97  void Dump(Stream &s);
98 
99  bool m_valid = false;
104  std::vector<VTableDescriptor> m_descriptors;
106  };
107 
108  public:
109  AppleObjCVTables(const lldb::ProcessSP &process_sp,
110  const lldb::ModuleSP &objc_module_sp);
111 
113 
115 
116  static bool RefreshTrampolines(void *baton,
117  StoppointCallbackContext *context,
118  lldb::user_id_t break_id,
119  lldb::user_id_t break_loc_id);
120  bool ReadRegions();
121 
122  bool ReadRegions(lldb::addr_t region_addr);
123 
124  bool IsAddressInVTables(lldb::addr_t addr, uint32_t &flags);
125 
126  lldb::ProcessSP GetProcessSP() { return m_process_wp.lock(); }
127 
128  private:
129  lldb::ProcessWP m_process_wp;
130  typedef std::vector<VTableRegion> region_collection;
134  lldb::ModuleSP m_objc_module_sp;
135  };
136 
138  static const char *g_opt_dispatch_names[];
139 
140  using MsgsendMap = std::map<lldb::addr_t, int>; // This table maps an dispatch
141  // fn address to the index in
142  // g_dispatch_functions
145  lldb::ProcessWP m_process_wp;
146  lldb::ModuleSP m_objc_module_sp;
148  std::unique_ptr<UtilityFunction> m_impl_code;
154  std::unique_ptr<AppleObjCVTables> m_vtables_up;
155 };
156 
157 } // namespace lldb_private
158 
159 #endif // LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLEOBJCTRAMPOLINEHANDLER_H
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::m_code_start_addr
lldb::addr_t m_code_start_addr
Definition: AppleObjCTrampolineHandler.h:102
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::SetUpRegion
void SetUpRegion()
Definition: AppleObjCTrampolineHandler.cpp:290
lldb-public.h
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::m_process_wp
lldb::ProcessWP m_process_wp
Definition: AppleObjCTrampolineHandler.h:129
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::Dump
void Dump(Stream &s)
Definition: AppleObjCTrampolineHandler.cpp:417
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::is_super
bool is_super
Definition: AppleObjCTrampolineHandler.h:43
lldb_private::StoppointCallbackContext
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
Definition: StoppointCallbackContext.h:26
lldb_private::AppleObjCTrampolineHandler::AppleObjCTrampolineHandler
AppleObjCTrampolineHandler(const lldb::ProcessSP &process_sp, const lldb::ModuleSP &objc_module_sp)
Definition: AppleObjCTrampolineHandler.cpp:676
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::fixedup
FixUpState fixedup
Definition: AppleObjCTrampolineHandler.h:45
lldb_private::AppleObjCTrampolineHandler::AddrIsMsgForward
bool AddrIsMsgForward(lldb::addr_t addr) const
Definition: AppleObjCTrampolineHandler.h:33
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::m_descriptors
std::vector< VTableDescriptor > m_descriptors
Definition: AppleObjCTrampolineHandler.h:104
lldb_private::AppleObjCTrampolineHandler::m_lookup_implementation_function_code
const char * m_lookup_implementation_function_code
Definition: AppleObjCTrampolineHandler.h:147
lldb_private::AppleObjCTrampolineHandler::DispatchFunction
Definition: AppleObjCTrampolineHandler.h:37
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::GetFlagsForVTableAtAddress
uint32_t GetFlagsForVTableAtAddress(lldb::addr_t address)
Definition: AppleObjCTrampolineHandler.h:91
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::~AppleObjCVTables
~AppleObjCVTables()
Definition: AppleObjCTrampolineHandler.cpp:439
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::eFixUpToFix
@ eFixUpToFix
Definition: AppleObjCTrampolineHandler.h:39
lldb_private::AppleObjCTrampolineHandler::g_opt_dispatch_names
static const char * g_opt_dispatch_names[]
Definition: AppleObjCTrampolineHandler.h:138
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableFlags
VTableFlags
Definition: AppleObjCTrampolineHandler.h:62
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::GetNextRegionAddr
lldb::addr_t GetNextRegionAddr()
Definition: AppleObjCTrampolineHandler.h:85
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables
Definition: AppleObjCTrampolineHandler.h:59
lldb_private::ValueList
Definition: Value.h:157
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::IsAddressInVTables
bool IsAddressInVTables(lldb::addr_t addr, uint32_t &flags)
Definition: AppleObjCTrampolineHandler.cpp:603
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::m_objc_module_sp
lldb::ModuleSP m_objc_module_sp
Definition: AppleObjCTrampolineHandler.h:134
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::AppleObjCTrampolineHandler::~AppleObjCTrampolineHandler
~AppleObjCTrampolineHandler()
lldb_private::AppleObjCTrampolineHandler::m_impl_code
std::unique_ptr< UtilityFunction > m_impl_code
Definition: AppleObjCTrampolineHandler.h:148
lldb_private::AppleObjCTrampolineHandler::m_msgSend_map
MsgsendMap m_msgSend_map
Definition: AppleObjCTrampolineHandler.h:143
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::RefreshTrampolines
static bool RefreshTrampolines(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
Definition: AppleObjCTrampolineHandler.cpp:506
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::m_valid
bool m_valid
Definition: AppleObjCTrampolineHandler.h:99
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::m_owner
AppleObjCVTables * m_owner
Definition: AppleObjCTrampolineHandler.h:100
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::m_trampoline_header
lldb::addr_t m_trampoline_header
Definition: AppleObjCTrampolineHandler.h:131
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::name
const char * name
Definition: AppleObjCTrampolineHandler.h:41
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableDescriptor::VTableDescriptor
VTableDescriptor(uint32_t in_flags, lldb::addr_t in_code_start)
Definition: AppleObjCTrampolineHandler.h:70
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::GetCodeStart
lldb::addr_t GetCodeStart()
Definition: AppleObjCTrampolineHandler.h:87
lldb_private::AppleObjCTrampolineHandler::g_lookup_implementation_with_stret_function_code
static const char * g_lookup_implementation_with_stret_function_code
Definition: AppleObjCTrampolineHandler.h:56
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::eOBJC_TRAMPOLINE_VTABLE
@ eOBJC_TRAMPOLINE_VTABLE
Definition: AppleObjCTrampolineHandler.h:65
lldb_private::AppleObjCTrampolineHandler::g_lookup_implementation_function_name
static const char * g_lookup_implementation_function_name
Definition: AppleObjCTrampolineHandler.h:55
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::InitializeVTableSymbols
bool InitializeVTableSymbols()
Definition: AppleObjCTrampolineHandler.cpp:447
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::ReadRegions
bool ReadRegions()
Definition: AppleObjCTrampolineHandler.cpp:554
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::GetCodeEnd
lldb::addr_t GetCodeEnd()
Definition: AppleObjCTrampolineHandler.h:89
lldb_private::AppleObjCTrampolineHandler::m_vtables_up
std::unique_ptr< AppleObjCVTables > m_vtables_up
Definition: AppleObjCTrampolineHandler.h:154
lldb_private::Thread
Definition: Thread.h:60
lldb_private::AppleObjCTrampolineHandler::g_dispatch_functions
static const DispatchFunction g_dispatch_functions[]
Definition: AppleObjCTrampolineHandler.h:137
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::m_trampolines_changed_bp_id
lldb::break_id_t m_trampolines_changed_bp_id
Definition: AppleObjCTrampolineHandler.h:132
lldb::break_id_t
int32_t break_id_t
Definition: lldb-types.h:88
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::m_code_end_addr
lldb::addr_t m_code_end_addr
Definition: AppleObjCTrampolineHandler.h:103
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::region_collection
std::vector< VTableRegion > region_collection
Definition: AppleObjCTrampolineHandler.h:130
lldb_private::AppleObjCTrampolineHandler::ForEachDispatchFunction
void ForEachDispatchFunction(std::function< void(lldb::addr_t, const DispatchFunction &)>)
Definition: AppleObjCTrampolineHandler.cpp:878
lldb_private::AppleObjCTrampolineHandler::m_opt_dispatch_map
MsgsendMap m_opt_dispatch_map
Definition: AppleObjCTrampolineHandler.h:144
lldb_private::AppleObjCTrampolineHandler::FindDispatchFunction
const DispatchFunction * FindDispatchFunction(lldb::addr_t addr)
Definition: AppleObjCTrampolineHandler.cpp:868
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::m_regions
region_collection m_regions
Definition: AppleObjCTrampolineHandler.h:133
lldb_private::AppleObjCTrampolineHandler
Definition: AppleObjCTrampolineHandler.h:21
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableDescriptor::code_start
lldb::addr_t code_start
Definition: AppleObjCTrampolineHandler.h:74
lldb_private::AppleObjCTrampolineHandler::m_msg_forward_addr
lldb::addr_t m_msg_forward_addr
Definition: AppleObjCTrampolineHandler.h:152
UtilityFunction.h
lldb_private::AppleObjCTrampolineHandler::GetLookupImplementationFunctionCaller
FunctionCaller * GetLookupImplementationFunctionCaller()
Definition: AppleObjCTrampolineHandler.cpp:1190
lldb_private::AppleObjCTrampolineHandler::m_impl_stret_fn_addr
lldb::addr_t m_impl_stret_fn_addr
Definition: AppleObjCTrampolineHandler.h:151
lldb_private::AppleObjCTrampolineHandler::MsgsendMap
std::map< lldb::addr_t, int > MsgsendMap
Definition: AppleObjCTrampolineHandler.h:140
uint32_t
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion
Definition: AppleObjCTrampolineHandler.h:77
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::AppleObjCVTables
AppleObjCVTables(const lldb::ProcessSP &process_sp, const lldb::ModuleSP &objc_module_sp)
Definition: AppleObjCTrampolineHandler.cpp:430
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::IsValid
bool IsValid()
Definition: AppleObjCTrampolineHandler.h:93
lldb_private::AppleObjCTrampolineHandler::m_impl_fn_addr
lldb::addr_t m_impl_fn_addr
Definition: AppleObjCTrampolineHandler.h:150
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::AddressInRegion
bool AddressInRegion(lldb::addr_t addr, uint32_t &flags)
Definition: AppleObjCTrampolineHandler.cpp:400
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::VTableRegion
VTableRegion()=default
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::m_next_region
lldb::addr_t m_next_region
Definition: AppleObjCTrampolineHandler.h:105
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::eOBJC_TRAMPOLINE_MESSAGE
@ eOBJC_TRAMPOLINE_MESSAGE
Definition: AppleObjCTrampolineHandler.h:63
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::GetProcessSP
lldb::ProcessSP GetProcessSP()
Definition: AppleObjCTrampolineHandler.h:126
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::eFixUpNone
@ eFixUpNone
Definition: AppleObjCTrampolineHandler.h:39
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::is_super2
bool is_super2
Definition: AppleObjCTrampolineHandler.h:44
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::eOBJC_TRAMPOLINE_STRET
@ eOBJC_TRAMPOLINE_STRET
Definition: AppleObjCTrampolineHandler.h:64
lldb_private::AppleObjCTrampolineHandler::g_lookup_implementation_no_stret_function_code
static const char * g_lookup_implementation_no_stret_function_code
Definition: AppleObjCTrampolineHandler.h:57
lldb_private::AppleObjCTrampolineHandler::m_impl_function_mutex
std::mutex m_impl_function_mutex
Definition: AppleObjCTrampolineHandler.h:149
lldb_private::AppleObjCTrampolineHandler::SetupDispatchFunction
lldb::addr_t SetupDispatchFunction(Thread &thread, ValueList &dispatch_values)
Definition: AppleObjCTrampolineHandler.cpp:793
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableDescriptor::flags
uint32_t flags
Definition: AppleObjCTrampolineHandler.h:73
lldb_private::AppleObjCTrampolineHandler::GetStepThroughDispatchPlan
lldb::ThreadPlanSP GetStepThroughDispatchPlan(Thread &thread, bool stop_others)
Definition: AppleObjCTrampolineHandler.cpp:887
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::eFixUpFixed
@ eFixUpFixed
Definition: AppleObjCTrampolineHandler.h:39
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::stret_return
bool stret_return
Definition: AppleObjCTrampolineHandler.h:42
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::FixUpState
FixUpState
Definition: AppleObjCTrampolineHandler.h:39
lldb_private::AppleObjCTrampolineHandler::m_process_wp
lldb::ProcessWP m_process_wp
Definition: AppleObjCTrampolineHandler.h:145
lldb_private::AppleObjCTrampolineHandler::m_objc_module_sp
lldb::ModuleSP m_objc_module_sp
Definition: AppleObjCTrampolineHandler.h:146
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::m_header_addr
lldb::addr_t m_header_addr
Definition: AppleObjCTrampolineHandler.h:101
lldb_private::FunctionCaller
Definition: FunctionCaller.h:56
lldb_private::AppleObjCTrampolineHandler::m_msg_forward_stret_addr
lldb::addr_t m_msg_forward_stret_addr
Definition: AppleObjCTrampolineHandler.h:153
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableDescriptor
Definition: AppleObjCTrampolineHandler.h:69