Skip to content

Commit 3af3900

Browse files
committed
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
1 parent 151ab48 commit 3af3900

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,18 @@ __lldb_apple_objc_v2_get_shared_cache_class_info (void *objc_opt_ro_ptr,
289289
const char *s = name;
290290
uint32_t h = 5381;
291291
for (unsigned char c = *s; c; c = *++s)
292+
{
293+
// class_getName demangles swift names and the hash must
294+
// be calculated on the mangled name. hash==0 means lldb
295+
// will fetch the mangled name and compute the hash in
296+
// ParseClassInfoArray.
297+
if (c == '.')
298+
{
299+
h = 0;
300+
break;
301+
}
292302
h = ((h << 5) + h) + c;
303+
}
293304
class_infos[idx].hash = h;
294305
}
295306
else
@@ -321,7 +332,18 @@ __lldb_apple_objc_v2_get_shared_cache_class_info (void *objc_opt_ro_ptr,
321332
const char *s = name;
322333
uint32_t h = 5381;
323334
for (unsigned char c = *s; c; c = *++s)
335+
{
336+
// class_getName demangles swift names and the hash must
337+
// be calculated on the mangled name. hash==0 means lldb
338+
// will fetch the mangled name and compute the hash in
339+
// ParseClassInfoArray.
340+
if (c == '.')
341+
{
342+
h = 0;
343+
break;
344+
}
324345
h = ((h << 5) + h) + c;
346+
}
325347
class_infos[idx].hash = h;
326348
}
327349
++idx;
@@ -1488,7 +1510,16 @@ uint32_t AppleObjCRuntimeV2::ParseClassInfoArray(const DataExtractor &data,
14881510
// Read the 32 bit hash for the class name
14891511
const uint32_t name_hash = data.GetU32(&offset);
14901512
ClassDescriptorSP descriptor_sp(new ClassDescriptorV2(*this, isa, NULL));
1491-
AddClass(isa, descriptor_sp, name_hash);
1513+
1514+
// The code in g_get_shared_cache_class_info_body sets the value of the hash
1515+
// to 0 to signal a demangled symbol. We use class_getName() in that code to
1516+
// find the class name, but this returns a demangled name for Swift symbols.
1517+
// For those symbols, recompute the hash here by reading their name from the
1518+
// runtime.
1519+
if (name_hash)
1520+
AddClass(isa, descriptor_sp, name_hash);
1521+
else
1522+
AddClass(isa, descriptor_sp, descriptor_sp->GetClassName().AsCString(nullptr));
14921523
num_parsed++;
14931524
if (should_log)
14941525
log->Printf("AppleObjCRuntimeV2 added isa=0x%" PRIx64

0 commit comments

Comments
 (0)