[Lldb-commits] [lldb] r359843 - Upstreaming an apple local patch by Frederic Riss.

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Thu May 2 16:14:26 PDT 2019


Author: jmolenda
Date: Thu May  2 16:14:26 2019
New Revision: 359843

URL: http://llvm.org/viewvc/llvm-project?rev=359843&view=rev
Log:
Upstreaming an apple local patch by Frederic Riss.

lldb has an expression that runs in the inferior process to collect
the isa values and hash of the class names for classes in the
system's shared cache.  In recent OSes, swift classes are in this
table and the function the jitted expression calls returns demangled
names.  We need to compute the hashes based on the mangled names.
So for these names, return a hash value of 0 which indicates that
lldb should read the class name directly out of the runtime tables
and compute the hash itself.

When this patch is absent, the lldb+swift testsuite has many failures
on a recent macOS system; there isn't a direct non-swift way to
test for this being correct.

<rdar://problem/47935062>


Modified:
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

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=359843&r1=359842&r2=359843&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Thu May  2 16:14:26 2019
@@ -289,7 +289,18 @@ __lldb_apple_objc_v2_get_shared_cache_cl
                     const char *s = name;
                     uint32_t h = 5381;
                     for (unsigned char c = *s; c; c = *++s)
+                    {
+                        // class_getName demangles swift names and the hash must
+                        // be calculated on the mangled name.  hash==0 means lldb
+                        // will fetch the mangled name and compute the hash in
+                        // ParseClassInfoArray.
+                        if (c == '.')
+                        {
+                            h = 0;
+                            break;
+                        }
                         h = ((h << 5) + h) + c;
+                    }
                     class_infos[idx].hash = h;
                 }
                 else
@@ -321,7 +332,18 @@ __lldb_apple_objc_v2_get_shared_cache_cl
                     const char *s = name;
                     uint32_t h = 5381;
                     for (unsigned char c = *s; c; c = *++s)
+                    {
+                        // class_getName demangles swift names and the hash must
+                        // be calculated on the mangled name.  hash==0 means lldb
+                        // will fetch the mangled name and compute the hash in
+                        // ParseClassInfoArray.
+                        if (c == '.')
+                        {
+                            h = 0;
+                            break;
+                        } 
                         h = ((h << 5) + h) + c;
+                    }
                     class_infos[idx].hash = h;
                 }
                 ++idx;
@@ -1488,7 +1510,16 @@ uint32_t AppleObjCRuntimeV2::ParseClassI
       // Read the 32 bit hash for the class name
       const uint32_t name_hash = data.GetU32(&offset);
       ClassDescriptorSP descriptor_sp(new ClassDescriptorV2(*this, isa, NULL));
-      AddClass(isa, descriptor_sp, name_hash);
+
+      // The code in g_get_shared_cache_class_info_body sets the value of the hash
+      // to 0 to signal a demangled symbol. We use class_getName() in that code to
+      // find the class name, but this returns a demangled name for Swift symbols.
+      // For those symbols, recompute the hash here by reading their name from the
+      // runtime.
+      if (name_hash)
+        AddClass(isa, descriptor_sp, name_hash);
+      else
+        AddClass(isa, descriptor_sp, descriptor_sp->GetClassName().AsCString(nullptr));
       num_parsed++;
       if (should_log)
         log->Printf("AppleObjCRuntimeV2 added isa=0x%" PRIx64




More information about the lldb-commits mailing list