diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index e459cb281793a..4fcdebe5bac62 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -1505,15 +1505,24 @@ AppleObjCRuntimeV2::GetClassDescriptorFromISA(ObjCISA isa) { ObjCLanguageRuntime::ClassDescriptorSP AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) { + ValueObjectSet seen; + return GetClassDescriptorImpl(valobj, seen); +} + +ObjCLanguageRuntime::ClassDescriptorSP +AppleObjCRuntimeV2::GetClassDescriptorImpl(ValueObject &valobj, + ValueObjectSet &seen) { + seen.insert(&valobj); + ClassDescriptorSP objc_class_sp; if (valobj.IsBaseClass()) { ValueObject *parent = valobj.GetParent(); - // if I am my own parent, bail out of here fast.. - if (parent && parent != &valobj) { - ClassDescriptorSP parent_descriptor_sp = GetClassDescriptor(*parent); - if (parent_descriptor_sp) - return parent_descriptor_sp->GetSuperclass(); - } + // Fail if there's a cycle in our parent chain. + if (!parent || seen.count(parent)) + return nullptr; + if (ClassDescriptorSP parent_descriptor_sp = + GetClassDescriptorImpl(*parent, seen)) + return parent_descriptor_sp->GetSuperclass(); return nullptr; } // if we get an invalid VO (which might still happen when playing around with diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h index 79840f9be79b3..b99bda2f7e259 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h @@ -20,6 +20,7 @@ #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h" #include "llvm/ADT/BitVector.h" +#include "llvm/ADT/SmallSet.h" class RemoteNXMapTable; @@ -421,6 +422,10 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime { lldb::addr_t GetISAHashTablePointer(); + using ValueObjectSet = llvm::SmallPtrSet; + ClassDescriptorSP GetClassDescriptorImpl(ValueObject &valobj, + ValueObjectSet &seen); + /// Update the generation count of realized classes. This is not an exact /// count but rather a value that is incremented when new classes are realized /// or destroyed. Unlike the count in gdb_objc_realized_classes, it will