diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp b/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp index 641d06f0c472d..5defaf09491b1 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp +++ b/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp @@ -246,7 +246,9 @@ class TargetReflectionContext : public ReflectionContextInterface { swift::reflection::DescriptorFinder *descriptor_finder, const swift::reflection::TypeRef *tr, std::function fn) override { - while (tr) { + // Guard against faulty self-referential metadata. + unsigned limit = 256; + while (tr && --limit) { if (fn({[=]() -> const swift::reflection::RecordTypeInfo * { auto ti_or_err = GetRecordTypeInfo(*tr, tip, descriptor_finder); LLDB_LOG_ERRORV(GetLog(LLDBLog::Types), ti_or_err.takeError(),