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
19namespace lldb_private {
20
22public:
24 const lldb::ModuleSP &objc_module_sp);
25
27
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:
39 const char *name = nullptr;
40 bool stret_return = false;
41 bool is_super = false;
42 bool is_super2 = false;
43 bool might_be_reexport = false;
44 };
45
47 ValueList &dispatch_values);
49 void ForEachDispatchFunction(std::function<void(lldb::addr_t,
50 const DispatchFunction &)>);
51
52private:
53 /// These hold the code for the function that finds the implementation of
54 /// an ObjC message send given the class & selector and the kind of dispatch.
55 /// There are two variants depending on whether the platform uses a separate
56 /// _stret passing convention (e.g. Intel) or not (e.g. ARM). The difference
57 /// is only at the very end of the function, so the code is broken into the
58 /// common prefix and the suffix, which get composed appropriately before
59 /// the function gets compiled.
60 /// \{
65 /// \}
66
68 public:
69 // These come from objc-gdb.h.
71 eOBJC_TRAMPOLINE_MESSAGE = (1 << 0), // trampoline acts like objc_msgSend
72 eOBJC_TRAMPOLINE_STRET = (1 << 1), // trampoline is struct-returning
73 eOBJC_TRAMPOLINE_VTABLE = (1 << 2) // trampoline is vtable dispatcher
74 };
75
76 private:
78 VTableDescriptor(uint32_t in_flags, lldb::addr_t in_code_start)
79 : flags(in_flags), code_start(in_code_start) {}
80
81 uint32_t flags;
83 };
84
86 public:
87 VTableRegion() = default;
88
89 VTableRegion(AppleObjCVTables *owner, lldb::addr_t header_addr);
90
91 void SetUpRegion();
92
94
96
98
99 uint32_t GetFlagsForVTableAtAddress(lldb::addr_t address) { return 0; }
100
101 bool IsValid() { return m_valid; }
102
103 bool AddressInRegion(lldb::addr_t addr, uint32_t &flags);
104
105 void Dump(Stream &s);
106
107 bool m_valid = false;
112 std::vector<VTableDescriptor> m_descriptors;
114 };
115
116 public:
117 AppleObjCVTables(const lldb::ProcessSP &process_sp,
118 const lldb::ModuleSP &objc_module_sp);
119
121
123
124 static bool RefreshTrampolines(void *baton,
126 lldb::user_id_t break_id,
127 lldb::user_id_t break_loc_id);
128 bool ReadRegions();
129
130 bool ReadRegions(lldb::addr_t region_addr);
131
132 bool IsAddressInVTables(lldb::addr_t addr, uint32_t &flags);
133
135
136 private:
138 typedef std::vector<VTableRegion> region_collection;
143 };
144
146 static const char *g_opt_dispatch_names[];
147
148 using MsgsendMap = std::map<lldb::addr_t, int>; // This table maps an dispatch
149 // fn address to the index in
150 // g_dispatch_functions
156 std::unique_ptr<UtilityFunction> m_impl_code;
162 std::unique_ptr<AppleObjCVTables> m_vtables_up;
163};
164
165} // namespace lldb_private
166
167#endif // LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLEOBJCTRAMPOLINEHANDLER_H
static bool RefreshTrampolines(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
AppleObjCVTables(const lldb::ProcessSP &process_sp, const lldb::ModuleSP &objc_module_sp)
static const char * g_lookup_implementation_function_name
These hold the code for the function that finds the implementation of an ObjC message send given the ...
static const DispatchFunction g_dispatch_functions[]
lldb::addr_t SetupDispatchFunction(Thread &thread, ValueList &dispatch_values)
std::unique_ptr< AppleObjCVTables > m_vtables_up
std::unique_ptr< UtilityFunction > m_impl_code
void ForEachDispatchFunction(std::function< void(lldb::addr_t, const DispatchFunction &)>)
lldb::ThreadPlanSP GetStepThroughDispatchPlan(Thread &thread, bool stop_others)
const DispatchFunction * FindDispatchFunction(lldb::addr_t addr)
AppleObjCTrampolineHandler(const lldb::ProcessSP &process_sp, const lldb::ModuleSP &objc_module_sp)
Encapsulates a function that can be called.
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
A stream class that can stream formatted output to a file.
Definition Stream.h:28
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
int32_t break_id_t
Definition lldb-types.h:87
std::shared_ptr< lldb_private::Process > ProcessSP
std::weak_ptr< lldb_private::Process > ProcessWP
uint64_t user_id_t
Definition lldb-types.h:82
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP