Resolve non-pointer isas for metaclasses.
authorSean Callanan <scallanan@apple.com>
Mon, 13 Oct 2014 23:03:49 +0000 (23:03 +0000)
committerSean Callanan <scallanan@apple.com>
Mon, 13 Oct 2014 23:03:49 +0000 (23:03 +0000)
Patch by Enrico Granata.
<rdar://problem/18618298>

llvm-svn: 219641

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

index 12254f9..9815993 100644 (file)
@@ -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
index 44c7e9d..6396dac 100644 (file)
@@ -375,15 +375,17 @@ ClassDescriptorV2::Describe (std::function <void (ObjCLanguageRuntime::ObjCISA)>
     
     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 ()
 {
index ccd8d51..a5bab02 100644 (file)
@@ -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 ()
     {
index 941e187..0a8c1fc 100644 (file)
@@ -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 <void (ObjCLanguageRuntime::ObjCISA)> const &superclass_func,
                                                  std::function <bool (const char *, const char *)> const &instance_method_func,
index bd66c53..3977548 100644 (file)
@@ -40,6 +40,9 @@ public:
         virtual ClassDescriptorSP
         GetSuperclass ();
         
+        virtual ClassDescriptorSP
+        GetMetaclass () const;
+        
         virtual bool
         IsValid ()
         {
index e3b8ef5..2401952 100644 (file)
@@ -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;
+}
index 3c47ceb..15e7810 100644 (file)
@@ -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;