From 0809b2ddc3a8661a55f818dbed8ea71a86e3802a Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Mon, 13 Oct 2014 23:03:49 +0000 Subject: [PATCH] Resolve non-pointer isas for metaclasses. Patch by Enrico Granata. llvm-svn: 219641 --- lldb/include/lldb/Target/ObjCLanguageRuntime.h | 3 +++ .../AppleObjCClassDescriptorV2.cpp | 30 ++++++++++++++++++---- .../AppleObjCRuntime/AppleObjCClassDescriptorV2.h | 17 +++++++++--- .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp | 6 +++++ .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h | 3 +++ .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 11 ++++++++ .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h | 7 +++++ 7 files changed, 68 insertions(+), 9 deletions(-) diff --git a/lldb/include/lldb/Target/ObjCLanguageRuntime.h b/lldb/include/lldb/Target/ObjCLanguageRuntime.h index 12254f9..9815993 100644 --- a/lldb/include/lldb/Target/ObjCLanguageRuntime.h +++ b/lldb/include/lldb/Target/ObjCLanguageRuntime.h @@ -166,6 +166,9 @@ public: virtual ClassDescriptorSP GetSuperclass () = 0; + virtual ClassDescriptorSP + GetMetaclass () const = 0; + // virtual if any implementation has some other version-specific rules // but for the known v1/v2 this is all that needs to be done virtual bool diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp index 44c7e9d..6396dac 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp @@ -375,15 +375,17 @@ ClassDescriptorV2::Describe (std::function if (class_method_func) { - ClassDescriptorV2 metaclass(m_runtime, objc_class->m_isa, NULL); // The metaclass is not in the cache + AppleObjCRuntime::ClassDescriptorSP metaclass(GetMetaclass()); // We don't care about the metaclass's superclass, or its class methods. Its instance methods are // our class methods. - metaclass.Describe(std::function (nullptr), - class_method_func, - std::function (nullptr), - std::function (nullptr)); + if (metaclass) { + metaclass->Describe(std::function (nullptr), + class_method_func, + std::function (nullptr), + std::function (nullptr)); + } } if (ivar_func) @@ -449,6 +451,24 @@ ClassDescriptorV2::GetSuperclass () return m_runtime.ObjCLanguageRuntime::GetClassDescriptorFromISA(objc_class->m_superclass); } +ObjCLanguageRuntime::ClassDescriptorSP +ClassDescriptorV2::GetMetaclass () const +{ + lldb_private::Process *process = m_runtime.GetProcess(); + + if (!process) + return ObjCLanguageRuntime::ClassDescriptorSP(); + + std::unique_ptr objc_class; + + if (!Read_objc_class(process, objc_class)) + return ObjCLanguageRuntime::ClassDescriptorSP(); + + lldb::addr_t candidate_isa = m_runtime.GetPointerISA(objc_class->m_isa); + + return ObjCLanguageRuntime::ClassDescriptorSP(new ClassDescriptorV2(m_runtime, candidate_isa, nullptr)); +} + uint64_t ClassDescriptorV2::GetInstanceSize () { diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h index ccd8d51..a5bab02 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h @@ -31,10 +31,10 @@ private: // The constructor should only be invoked by the runtime as it builds its caches // or populates them. A ClassDescriptorV2 should only ever exist in a cache. ClassDescriptorV2 (AppleObjCRuntimeV2 &runtime, ObjCLanguageRuntime::ObjCISA isa, const char *name) : - m_runtime (runtime), - m_objc_class_ptr (isa), - m_name (name), - m_ivars_storage() + m_runtime (runtime), + m_objc_class_ptr (isa), + m_name (name), + m_ivars_storage() { } @@ -45,6 +45,9 @@ public: virtual ObjCLanguageRuntime::ClassDescriptorSP GetSuperclass (); + virtual ObjCLanguageRuntime::ClassDescriptorSP + GetMetaclass () const; + virtual bool IsValid () { @@ -328,6 +331,12 @@ public: return ObjCLanguageRuntime::ClassDescriptorSP(); } + virtual ObjCLanguageRuntime::ClassDescriptorSP + GetMetaclass () const + { + return ObjCLanguageRuntime::ClassDescriptorSP(); + } + virtual bool IsValid () { diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp index 941e187..0a8c1fc 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp @@ -271,6 +271,12 @@ AppleObjCRuntimeV1::ClassDescriptorV1::GetSuperclass () return ObjCLanguageRuntime::ClassDescriptorSP(new AppleObjCRuntimeV1::ClassDescriptorV1(m_parent_isa,process_sp)); } +AppleObjCRuntime::ClassDescriptorSP +AppleObjCRuntimeV1::ClassDescriptorV1::GetMetaclass () const +{ + return ClassDescriptorSP(); +} + bool AppleObjCRuntimeV1::ClassDescriptorV1::Describe (std::function const &superclass_func, std::function const &instance_method_func, diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h index bd66c53..3977548 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h @@ -40,6 +40,9 @@ public: virtual ClassDescriptorSP GetSuperclass (); + virtual ClassDescriptorSP + GetMetaclass () const; + virtual bool IsValid () { diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index e3b8ef5..2401952 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -1925,3 +1925,14 @@ AppleObjCRuntimeV2::GetEncodingToType () m_encoding_to_type_sp.reset(new AppleObjCTypeEncodingParser(*this)); return m_encoding_to_type_sp; } + +lldb_private::AppleObjCRuntime::ObjCISA +AppleObjCRuntimeV2::GetPointerISA (ObjCISA isa) +{ + ObjCISA ret = isa; + + if (m_non_pointer_isa_cache_ap) + m_non_pointer_isa_cache_ap->EvaluateNonPointerISA(isa, ret); + + return ret; +} diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h index 3c47ceb..15e7810 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h @@ -157,6 +157,8 @@ private: uint64_t m_objc_debug_isa_magic_mask; uint64_t m_objc_debug_isa_magic_value; + friend class AppleObjCRuntimeV2; + DISALLOW_COPY_AND_ASSIGN(NonPointerISACache); }; @@ -241,6 +243,9 @@ private: AppleObjCRuntimeV2 (Process *process, const lldb::ModuleSP &objc_module_sp); + ObjCISA + GetPointerISA (ObjCISA isa); + bool IsTaggedPointer(lldb::addr_t ptr); @@ -263,6 +268,8 @@ private: lldb::addr_t GetSharedCacheReadOnlyAddress(); + friend class ClassDescriptorV2; + std::unique_ptr m_get_class_info_function; std::unique_ptr m_get_class_info_code; lldb::addr_t m_get_class_info_args; -- 2.7.4