LLDB  mainline
AppleObjCRuntimeV2.h
Go to the documentation of this file.
1 //===-- AppleObjCRuntimeV2.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_APPLEOBJCRUNTIMEV2_H
10 #define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLEOBJCRUNTIMEV2_H
11 
12 #include <map>
13 #include <memory>
14 #include <mutex>
15 
16 #include "AppleObjCRuntime.h"
17 #include "lldb/lldb-private.h"
18 
20 
21 class RemoteNXMapTable;
22 
23 namespace lldb_private {
24 
26 public:
27  ~AppleObjCRuntimeV2() override = default;
28 
29  // Static Functions
30  static void Initialize();
31 
32  static void Terminate();
33 
35  CreateInstance(Process *process, lldb::LanguageType language);
36 
38 
39  static char ID;
40 
41  bool isA(const void *ClassID) const override {
42  return ClassID == &ID || AppleObjCRuntime::isA(ClassID);
43  }
44 
45  static bool classof(const LanguageRuntime *runtime) {
46  return runtime->isA(&ID);
47  }
48 
49  // These are generic runtime functions:
51  lldb::DynamicValueType use_dynamic,
52  TypeAndOrName &class_type_or_name,
53  Address &address,
54  Value::ValueType &value_type) override;
55 
56  UtilityFunction *CreateObjectChecker(const char *) override;
57 
58  // PluginInterface protocol
59  ConstString GetPluginName() override;
60 
61  uint32_t GetPluginVersion() override;
62 
65  }
66 
67  size_t GetByteOffsetForIvar(CompilerType &parent_qual_type,
68  const char *ivar_name) override;
69 
70  void UpdateISAToDescriptorMapIfNeeded() override;
71 
73 
75 
76  DeclVendor *GetDeclVendor() override;
77 
79 
81 
82  bool IsTaggedPointer(lldb::addr_t ptr) override;
83 
85  return m_tagged_pointer_vendor_up.get();
86  }
87 
89 
91  lldb::addr_t &cf_false) override;
92 
93  // none of these are valid ISAs - we use them to infer the type
94  // of tagged pointers - if we have something meaningful to say
95  // we report an actual type - otherwise, we just say tagged
96  // there is no connection between the values here and the tagged pointers map
102  5;
104 
105 protected:
106  lldb::BreakpointResolverSP
107  CreateExceptionResolver(const lldb::BreakpointSP &bkpt,
108  bool catch_bp, bool throw_bp) override;
109 
110 private:
112  public:
114 
115  bool NeedsUpdate(Process *process, AppleObjCRuntimeV2 *runtime,
116  RemoteNXMapTable &hash_table);
117 
118  void UpdateSignature(const RemoteNXMapTable &hash_table);
119 
120  protected:
124  };
125 
127  public:
128  static NonPointerISACache *
130  const lldb::ModuleSP &objc_module_sp);
131 
133 
134  private:
136  const lldb::ModuleSP &objc_module_sp,
137  uint64_t objc_debug_isa_class_mask,
138  uint64_t objc_debug_isa_magic_mask,
139  uint64_t objc_debug_isa_magic_value,
140  uint64_t objc_debug_indexed_isa_magic_mask,
141  uint64_t objc_debug_indexed_isa_magic_value,
142  uint64_t objc_debug_indexed_isa_index_mask,
143  uint64_t objc_debug_indexed_isa_index_shift,
144  lldb::addr_t objc_indexed_classes);
145 
146  bool EvaluateNonPointerISA(ObjCISA isa, ObjCISA &ret_isa);
147 
149  std::map<ObjCISA, ObjCLanguageRuntime::ClassDescriptorSP> m_cache;
150  lldb::ModuleWP m_objc_module_wp;
154 
160 
161  std::vector<lldb::addr_t> m_indexed_isa_cache;
162 
163  friend class AppleObjCRuntimeV2;
164 
166  };
167 
170  public:
171  ~TaggedPointerVendorV2() override = default;
172 
173  static TaggedPointerVendorV2 *
175  const lldb::ModuleSP &objc_module_sp);
176 
177  protected:
179 
181  : TaggedPointerVendor(), m_runtime(runtime) {}
182 
183  private:
185  };
186 
188  public:
189  bool IsPossibleTaggedPointer(lldb::addr_t ptr) override;
190 
192  GetClassDescriptor(lldb::addr_t ptr) override;
193 
194  protected:
196  AppleObjCRuntimeV2 &runtime, uint64_t objc_debug_taggedpointer_mask,
197  uint32_t objc_debug_taggedpointer_slot_shift,
198  uint32_t objc_debug_taggedpointer_slot_mask,
199  uint32_t objc_debug_taggedpointer_payload_lshift,
200  uint32_t objc_debug_taggedpointer_payload_rshift,
201  lldb::addr_t objc_debug_taggedpointer_classes);
202 
203  typedef std::map<uint8_t, ObjCLanguageRuntime::ClassDescriptorSP> Cache;
204  typedef Cache::iterator CacheIterator;
205  Cache m_cache;
212 
214 
216  };
217 
220  public:
222  GetClassDescriptor(lldb::addr_t ptr) override;
223 
224  protected:
226  AppleObjCRuntimeV2 &runtime, uint64_t objc_debug_taggedpointer_mask,
227  uint64_t objc_debug_taggedpointer_ext_mask,
228  uint32_t objc_debug_taggedpointer_slot_shift,
229  uint32_t objc_debug_taggedpointer_ext_slot_shift,
230  uint32_t objc_debug_taggedpointer_slot_mask,
231  uint32_t objc_debug_taggedpointer_ext_slot_mask,
232  uint32_t objc_debug_taggedpointer_payload_lshift,
233  uint32_t objc_debug_taggedpointer_payload_rshift,
234  uint32_t objc_debug_taggedpointer_ext_payload_lshift,
235  uint32_t objc_debug_taggedpointer_ext_payload_rshift,
236  lldb::addr_t objc_debug_taggedpointer_classes,
237  lldb::addr_t objc_debug_taggedpointer_ext_classes);
238 
239  bool IsPossibleExtendedTaggedPointer(lldb::addr_t ptr);
240 
241  typedef std::map<uint8_t, ObjCLanguageRuntime::ClassDescriptorSP> Cache;
242  typedef Cache::iterator CacheIterator;
243  Cache m_ext_cache;
250 
252 
254  };
255 
257  public:
258  bool IsPossibleTaggedPointer(lldb::addr_t ptr) override;
259 
261  GetClassDescriptor(lldb::addr_t ptr) override;
262 
263  protected:
265  : TaggedPointerVendorV2(runtime) {}
266 
268 
270  };
271 
275 
277  m_update_ran = ran;
278  m_num_found = found;
279  }
280 
281  static DescriptorMapUpdateResult Fail() { return {false, 0}; }
282 
284  return {true, found};
285  }
286  };
287 
288  AppleObjCRuntimeV2(Process *process, const lldb::ModuleSP &objc_module_sp);
289 
291 
293 
295 
298 
300  uint32_t num_class_infos);
301 
303 
305  eExpressionExecutionFailure,
306  eNotEnoughClassesRead
307  };
308 
310 
312 
314 
315  friend class ClassDescriptorV2;
316 
317  std::unique_ptr<UtilityFunction> m_get_class_info_code;
320 
321  std::unique_ptr<UtilityFunction> m_get_shared_cache_class_info_code;
324 
325  std::unique_ptr<DeclVendor> m_decl_vendor_up;
331  std::unique_ptr<NonPointerISACache> m_non_pointer_isa_cache_up;
332  std::unique_ptr<TaggedPointerVendor> m_tagged_pointer_vendor_up;
335  llvm::Optional<std::pair<lldb::addr_t, lldb::addr_t>> m_CFBoolean_values;
336 };
337 
338 } // namespace lldb_private
339 
340 #endif // LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLEOBJCRUNTIMEV2_H
ClassDescriptorSP GetClassDescriptor(ValueObject &in_value) override
An data extractor class.
Definition: DataExtractor.h:46
TaggedPointerVendor * GetTaggedPointerVendor() override
lldb::addr_t LookupRuntimeSymbol(ConstString name) override
static const ObjCLanguageRuntime::ObjCISA g_objc_Tagged_ISA_NSDate
A class that represents a running process on the host machine.
UtilityFunction * CreateObjectChecker(const char *) override
Sometimes you can find the name of the type corresponding to an object, but we don&#39;t have debug infor...
Definition: Type.h:381
uint32_t ParseClassInfoArray(const lldb_private::DataExtractor &data, uint32_t num_class_infos)
static DescriptorMapUpdateResult Success(uint32_t found)
std::unique_ptr< UtilityFunction > m_get_shared_cache_class_info_code
ObjCRuntimeVersions GetRuntimeVersion() const override
static const ObjCLanguageRuntime::ObjCISA g_objc_Tagged_ISA_NSDateTS
virtual bool isA(const void *ClassID) const
static const ObjCLanguageRuntime::ObjCISA g_objc_Tagged_ISA_NSNumber
static const ObjCLanguageRuntime::ObjCISA g_objc_Tagged_ISA
DescriptorMapUpdateResult UpdateISAToDescriptorMapDynamic(RemoteNXMapTable &hash_table)
static const ObjCLanguageRuntime::ObjCISA g_objc_Tagged_ISA_NSManagedObject
std::unique_ptr< NonPointerISACache > m_non_pointer_isa_cache_up
std::shared_ptr< ClassDescriptor > ClassDescriptorSP
EncodingToTypeSP GetEncodingToType() override
AppleObjCRuntimeV2(Process *process, const lldb::ModuleSP &objc_module_sp)
void WarnIfNoClassesCached(SharedCacheWarningReason reason)
lldb::BreakpointResolverSP CreateExceptionResolver(const lldb::BreakpointSP &bkpt, bool catch_bp, bool throw_bp) override
~AppleObjCRuntimeV2() override=default
LanguageType
Programming language type.
bool NeedsUpdate(Process *process, AppleObjCRuntimeV2 *runtime, RemoteNXMapTable &hash_table)
size_t GetByteOffsetForIvar(CompilerType &parent_qual_type, const char *ivar_name) override
std::unique_ptr< DeclVendor > m_decl_vendor_up
A plug-in interface definition class for debugging a process.
Definition: Process.h:362
bool UpdateISAToDescriptorMapFromMemory(RemoteNXMapTable &hash_table)
bool IsTaggedPointer(lldb::addr_t ptr) override
DescriptorMapUpdateResult UpdateISAToDescriptorMapSharedCache()
A section + offset based address class.
Definition: Address.h:59
static lldb_private::ConstString GetPluginNameStatic()
bool isA(const void *ClassID) const override
std::unique_ptr< UtilityFunction > m_get_class_info_code
static bool classof(const LanguageRuntime *runtime)
uint64_t addr_t
Definition: lldb-types.h:83
std::map< uint8_t, ObjCLanguageRuntime::ClassDescriptorSP > Cache
A uniqued constant string class.
Definition: ConstString.h:40
bool GetDynamicTypeAndAddress(ValueObject &in_value, lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name, Address &address, Value::ValueType &value_type) override
Represents a generic type in a programming language.
Definition: CompilerType.h:33
DISALLOW_COPY_AND_ASSIGN(ObjCLanguageRuntime)
bool isA(const void *ClassID) const override
static lldb_private::LanguageRuntime * CreateInstance(Process *process, lldb::LanguageType language)
void GetValuesForGlobalCFBooleans(lldb::addr_t &cf_true, lldb::addr_t &cf_false) override
static const ObjCLanguageRuntime::ObjCISA g_objc_Tagged_ISA_NSAtom
llvm::Optional< std::pair< lldb::addr_t, lldb::addr_t > > m_CFBoolean_values
"lldb/Expression/UtilityFunction.h" Encapsulates a bit of source code that provides a function that i...
void UpdateSignature(const RemoteNXMapTable &hash_table)
std::shared_ptr< EncodingToType > EncodingToTypeSP
ClassDescriptorSP GetClassDescriptorFromISA(ObjCISA isa) override
std::map< ObjCISA, ObjCLanguageRuntime::ClassDescriptorSP > m_cache
std::map< uint8_t, ObjCLanguageRuntime::ClassDescriptorSP > Cache
std::unique_ptr< TaggedPointerVendor > m_tagged_pointer_vendor_up