Skip to content

Commit c4fee95

Browse files
fredrissJDevlieghere
authored andcommitted
[lldb/ObjC] Make the NonPointerIsaCache initialization lazy
The objc_debug_isa_class_mask magic value that the objc runtime vends is now initialized using a static initializer instead of a constant value. The runtime plugin itself will be initialized before the value is computed and as a result, the cache will get the wrong value. Making the creation of the NonPointerIsaCache fully lazy fixes this.
1 parent ff29fdf commit c4fee95

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,15 @@ static void RegisterObjCExceptionRecognizer(Process *process);
414414

415415
AppleObjCRuntimeV2::AppleObjCRuntimeV2(Process *process,
416416
const ModuleSP &objc_module_sp)
417-
: AppleObjCRuntime(process), m_get_class_info_code(),
418-
m_get_class_info_args(LLDB_INVALID_ADDRESS),
417+
: AppleObjCRuntime(process), m_objc_module_sp(objc_module_sp),
418+
m_get_class_info_code(), m_get_class_info_args(LLDB_INVALID_ADDRESS),
419419
m_get_class_info_args_mutex(), m_get_shared_cache_class_info_code(),
420420
m_get_shared_cache_class_info_args(LLDB_INVALID_ADDRESS),
421421
m_get_shared_cache_class_info_args_mutex(), m_decl_vendor_up(),
422422
m_tagged_pointer_obfuscator(LLDB_INVALID_ADDRESS),
423423
m_isa_hash_table_ptr(LLDB_INVALID_ADDRESS), m_hash_signature(),
424424
m_has_object_getClass(false), m_loaded_objc_opt(false),
425-
m_non_pointer_isa_cache_up(
426-
NonPointerISACache::CreateInstance(*this, objc_module_sp)),
425+
m_non_pointer_isa_cache_up(),
427426
m_tagged_pointer_vendor_up(
428427
TaggedPointerVendorV2::CreateInstance(*this, objc_module_sp)),
429428
m_encoding_to_type_sp(), m_noclasses_warning_emitted(false),
@@ -642,6 +641,7 @@ class CommandObjectObjC_ClassTable_Dump : public CommandObjectParsed {
642641
ivar.m_type.GetDisplayTypeName().AsCString("<unknown>"),
643642
ivar.m_size, ivar.m_offset);
644643
}
644+
645645
iterator->second->Describe(
646646
nullptr,
647647
[&std_out](const char *name, const char *type) -> bool {
@@ -1179,8 +1179,8 @@ bool AppleObjCRuntimeV2::HashTableSignature::NeedsUpdate(
11791179
ObjCLanguageRuntime::ClassDescriptorSP
11801180
AppleObjCRuntimeV2::GetClassDescriptorFromISA(ObjCISA isa) {
11811181
ObjCLanguageRuntime::ClassDescriptorSP class_descriptor_sp;
1182-
if (m_non_pointer_isa_cache_up)
1183-
class_descriptor_sp = m_non_pointer_isa_cache_up->GetClassDescriptor(isa);
1182+
if (auto *non_pointer_isa_cache = GetNonPointerIsaCache())
1183+
class_descriptor_sp = non_pointer_isa_cache->GetClassDescriptor(isa);
11841184
if (!class_descriptor_sp)
11851185
class_descriptor_sp = ObjCLanguageRuntime::GetClassDescriptorFromISA(isa);
11861186
return class_descriptor_sp;
@@ -2561,8 +2561,8 @@ lldb_private::AppleObjCRuntime::ObjCISA
25612561
AppleObjCRuntimeV2::GetPointerISA(ObjCISA isa) {
25622562
ObjCISA ret = isa;
25632563

2564-
if (m_non_pointer_isa_cache_up)
2565-
m_non_pointer_isa_cache_up->EvaluateNonPointerISA(isa, ret);
2564+
if (auto *non_pointer_isa_cache = GetNonPointerIsaCache())
2565+
non_pointer_isa_cache->EvaluateNonPointerISA(isa, ret);
25662566

25672567
return ret;
25682568
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,17 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {
320320

321321
bool GetCFBooleanValuesIfNeeded();
322322

323+
NonPointerISACache *GetNonPointerIsaCache() {
324+
if (!m_non_pointer_isa_cache_up)
325+
m_non_pointer_isa_cache_up.reset(
326+
NonPointerISACache::CreateInstance(*this, m_objc_module_sp));
327+
return m_non_pointer_isa_cache_up.get();
328+
}
329+
323330
friend class ClassDescriptorV2;
324331

332+
lldb::ModuleSP m_objc_module_sp;
333+
325334
std::unique_ptr<UtilityFunction> m_get_class_info_code;
326335
lldb::addr_t m_get_class_info_args;
327336
std::mutex m_get_class_info_args_mutex;

0 commit comments

Comments
 (0)