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>

llvm-svn: 359843
This commit is contained in:
Jason Molenda 2019-05-02 23:14:26 +00:00
parent 151ab4844a
commit 3af3900ee7
1 changed files with 32 additions and 1 deletions

View File

@ -289,7 +289,18 @@ __lldb_apple_objc_v2_get_shared_cache_class_info (void *objc_opt_ro_ptr,
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_class_info (void *objc_opt_ro_ptr,
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::ParseClassInfoArray(const DataExtractor &data,
// 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));
// 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