[Lldb-commits] [lldb] r219641 - Resolve non-pointer isas for metaclasses.

Sean Callanan scallanan at apple.com
Mon Oct 13 16:03:49 PDT 2014


Author: spyffe
Date: Mon Oct 13 18:03:49 2014
New Revision: 219641

URL: http://llvm.org/viewvc/llvm-project?rev=219641&view=rev
Log:
Resolve non-pointer isas for metaclasses.
Patch by Enrico Granata.
<rdar://problem/18618298>

Modified:
    lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h

Modified: lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h?rev=219641&r1=219640&r2=219641&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h Mon Oct 13 18:03:49 2014
@@ -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

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp?rev=219641&r1=219640&r2=219641&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp Mon Oct 13 18:03:49 2014
@@ -375,15 +375,17 @@ ClassDescriptorV2::Describe (std::functi
     
     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 <void (ObjCLanguageRuntime::ObjCISA)> (nullptr),
-                           class_method_func,
-                           std::function <bool (const char *, const char *)> (nullptr),
-                           std::function <bool (const char *, const char *, lldb::addr_t, uint64_t)> (nullptr));
+        if (metaclass) {
+            metaclass->Describe(std::function <void (ObjCLanguageRuntime::ObjCISA)> (nullptr),
+                                class_method_func,
+                                std::function <bool (const char *, const char *)> (nullptr),
+                                std::function <bool (const char *, const char *, lldb::addr_t, uint64_t)> (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_t> 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 ()
 {

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h?rev=219641&r1=219640&r2=219641&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h Mon Oct 13 18:03:49 2014
@@ -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 ()
     {

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp?rev=219641&r1=219640&r2=219641&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp Mon Oct 13 18:03:49 2014
@@ -271,6 +271,12 @@ AppleObjCRuntimeV1::ClassDescriptorV1::G
     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 <void (ObjCLanguageRuntime::ObjCISA)> const &superclass_func,
                                                  std::function <bool (const char *, const char *)> const &instance_method_func,

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h?rev=219641&r1=219640&r2=219641&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h Mon Oct 13 18:03:49 2014
@@ -40,6 +40,9 @@ public:
         virtual ClassDescriptorSP
         GetSuperclass ();
         
+        virtual ClassDescriptorSP
+        GetMetaclass () const;
+        
         virtual bool
         IsValid ()
         {

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=219641&r1=219640&r2=219641&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Mon Oct 13 18:03:49 2014
@@ -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;
+}

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h?rev=219641&r1=219640&r2=219641&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h Mon Oct 13 18:03:49 2014
@@ -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<ClangFunction>            m_get_class_info_function;
     std::unique_ptr<ClangUtilityFunction>     m_get_class_info_code;
     lldb::addr_t                            m_get_class_info_args;





More information about the lldb-commits mailing list