1 //===-- AppleObjCRuntimeV1.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_APPLEOBJCRUNTIMEV1_H 10 #define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLEOBJCRUNTIMEV1_H 11 12 #include "AppleObjCRuntime.h" 13 #include "lldb/lldb-private.h" 14 15 #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h" 16 17 namespace lldb_private { 18 19 class AppleObjCRuntimeV1 : public AppleObjCRuntime { 20 public: 21 ~AppleObjCRuntimeV1() override = default; 22 23 // Static Functions 24 static void Initialize(); 25 26 static void Terminate(); 27 28 static lldb_private::LanguageRuntime * 29 CreateInstance(Process *process, lldb::LanguageType language); 30 31 static lldb_private::ConstString GetPluginNameStatic(); 32 33 static char ID; 34 isA(const void * ClassID)35 bool isA(const void *ClassID) const override { 36 return ClassID == &ID || AppleObjCRuntime::isA(ClassID); 37 } 38 classof(const LanguageRuntime * runtime)39 static bool classof(const LanguageRuntime *runtime) { 40 return runtime->isA(&ID); 41 } 42 43 lldb::addr_t GetTaggedPointerObfuscator(); 44 45 class ClassDescriptorV1 : public ObjCLanguageRuntime::ClassDescriptor { 46 public: 47 ClassDescriptorV1(ValueObject &isa_pointer); 48 ClassDescriptorV1(ObjCISA isa, lldb::ProcessSP process_sp); 49 50 ~ClassDescriptorV1() override = default; 51 GetClassName()52 ConstString GetClassName() override { return m_name; } 53 54 ClassDescriptorSP GetSuperclass() override; 55 56 ClassDescriptorSP GetMetaclass() const override; 57 IsValid()58 bool IsValid() override { return m_valid; } 59 60 // v1 does not support tagged pointers 61 bool GetTaggedPointerInfo(uint64_t *info_bits = nullptr, 62 uint64_t *value_bits = nullptr, 63 uint64_t *payload = nullptr) override { 64 return false; 65 } 66 GetInstanceSize()67 uint64_t GetInstanceSize() override { return m_instance_size; } 68 GetISA()69 ObjCISA GetISA() override { return m_isa; } 70 71 bool 72 Describe(std::function<void(ObjCLanguageRuntime::ObjCISA)> const 73 &superclass_func, 74 std::function<bool(const char *, const char *)> const 75 &instance_method_func, 76 std::function<bool(const char *, const char *)> const 77 &class_method_func, 78 std::function<bool(const char *, const char *, lldb::addr_t, 79 uint64_t)> const &ivar_func) const override; 80 81 protected: 82 void Initialize(ObjCISA isa, lldb::ProcessSP process_sp); 83 84 private: 85 ConstString m_name; 86 ObjCISA m_isa; 87 ObjCISA m_parent_isa; 88 bool m_valid; 89 lldb::ProcessWP m_process_wp; 90 uint64_t m_instance_size; 91 }; 92 93 // These are generic runtime functions: 94 bool GetDynamicTypeAndAddress(ValueObject &in_value, 95 lldb::DynamicValueType use_dynamic, 96 TypeAndOrName &class_type_or_name, 97 Address &address, 98 Value::ValueType &value_type) override; 99 100 llvm::Expected<std::unique_ptr<UtilityFunction>> 101 CreateObjectChecker(std::string, ExecutionContext &exe_ctx) override; 102 103 // PluginInterface protocol 104 ConstString GetPluginName() override; 105 106 uint32_t GetPluginVersion() override; 107 GetRuntimeVersion()108 ObjCRuntimeVersions GetRuntimeVersion() const override { 109 return ObjCRuntimeVersions::eAppleObjC_V1; 110 } 111 112 void UpdateISAToDescriptorMapIfNeeded() override; 113 114 DeclVendor *GetDeclVendor() override; 115 116 protected: 117 lldb::BreakpointResolverSP 118 CreateExceptionResolver(const lldb::BreakpointSP &bkpt, 119 bool catch_bp, bool throw_bp) override; 120 121 class HashTableSignature { 122 public: HashTableSignature()123 HashTableSignature() 124 : m_count(0), m_num_buckets(0), m_buckets_ptr(LLDB_INVALID_ADDRESS) {} 125 NeedsUpdate(uint32_t count,uint32_t num_buckets,lldb::addr_t buckets_ptr)126 bool NeedsUpdate(uint32_t count, uint32_t num_buckets, 127 lldb::addr_t buckets_ptr) { 128 return m_count != count || m_num_buckets != num_buckets || 129 m_buckets_ptr != buckets_ptr; 130 } 131 UpdateSignature(uint32_t count,uint32_t num_buckets,lldb::addr_t buckets_ptr)132 void UpdateSignature(uint32_t count, uint32_t num_buckets, 133 lldb::addr_t buckets_ptr) { 134 m_count = count; 135 m_num_buckets = num_buckets; 136 m_buckets_ptr = buckets_ptr; 137 } 138 139 protected: 140 uint32_t m_count; 141 uint32_t m_num_buckets; 142 lldb::addr_t m_buckets_ptr; 143 }; 144 145 lldb::addr_t GetISAHashTablePointer(); 146 147 HashTableSignature m_hash_signature; 148 lldb::addr_t m_isa_hash_table_ptr; 149 std::unique_ptr<DeclVendor> m_decl_vendor_up; 150 151 private: 152 AppleObjCRuntimeV1(Process *process); 153 }; 154 155 } // namespace lldb_private 156 157 #endif // LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_OBJC_APPLEOBJCRUNTIME_APPLEOBJCRUNTIMEV1_H 158