@@ -1847,35 +1847,38 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class(
18471847 return false ;
18481848 }
18491849 Log *log (GetLog (LLDBLog::Types));
1850- ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
1851- if (!reflection_ctx)
1852- return false ;
1850+ // Scope reflection_ctx to minimize its lock scope.
1851+ {
1852+ ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
1853+ if (!reflection_ctx)
1854+ return false ;
18531855
1854- const auto *typeref = reflection_ctx->ReadTypeFromInstance (
1855- instance_ptr, ts->GetDescriptorFinder (), true );
1856+ const auto *typeref = reflection_ctx->ReadTypeFromInstance (
1857+ instance_ptr, ts->GetDescriptorFinder (), true );
18561858
1857- // If we couldn't find the typeref from the instance, the best we can do is
1858- // use the static type. This is a valid use case when the binary doesn't
1859- // contain any metadata (for example, embedded Swift).
1860- if (!typeref)
1861- typeref = reflection_ctx->GetTypeRefOrNull (class_type. GetMangledTypeName (),
1862- ts->GetDescriptorFinder ());
1859+ // If we couldn't find the typeref from the instance, the best we can do is
1860+ // use the static type. This is a valid use case when the binary doesn't
1861+ // contain any metadata (for example, embedded Swift).
1862+ if (!typeref)
1863+ typeref = reflection_ctx->GetTypeRefOrNull (
1864+ class_type. GetMangledTypeName (), ts->GetDescriptorFinder ());
18631865
1864- if (!typeref) {
1865- HEALTH_LOG (" could not read typeref for type: {0} (instance_ptr = {0:x})" ,
1866- class_type.GetMangledTypeName (), instance_ptr);
1867- return false ;
1868- }
1866+ if (!typeref) {
1867+ HEALTH_LOG (" could not read typeref for type: {0} (instance_ptr = {0:x})" ,
1868+ class_type.GetMangledTypeName (), instance_ptr);
1869+ return false ;
1870+ }
18691871
1870- auto flavor =
1871- SwiftLanguageRuntime::GetManglingFlavor ( class_type.GetMangledTypeName ());
1872+ auto flavor = SwiftLanguageRuntime::GetManglingFlavor (
1873+ class_type.GetMangledTypeName ());
18721874
1873- swift::Demangle::Demangler dem;
1874- swift::Demangle::NodePointer node = typeref->getDemangling (dem);
1875- CompilerType dynamic_type = ts->RemangleAsType (dem, node, flavor);
1876- LLDB_LOG (log, " dynamic type of instance_ptr {0:x} is {1}" , instance_ptr,
1877- class_type.GetMangledTypeName ());
1878- class_type_or_name.SetCompilerType (dynamic_type);
1875+ swift::Demangle::Demangler dem;
1876+ swift::Demangle::NodePointer node = typeref->getDemangling (dem);
1877+ CompilerType dynamic_type = ts->RemangleAsType (dem, node, flavor);
1878+ LLDB_LOG (log, " dynamic type of instance_ptr {0:x} is {1}" , instance_ptr,
1879+ class_type.GetMangledTypeName ());
1880+ class_type_or_name.SetCompilerType (dynamic_type);
1881+ }
18791882
18801883#ifndef NDEBUG
18811884 if (ModuleList::GetGlobalModuleListProperties ()
0 commit comments