@@ -2022,21 +2022,6 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack(
2022
2022
return true ;
2023
2023
}
2024
2024
2025
- static bool IsPrivateNSClass (NodePointer node) {
2026
- if (!node || node->getKind () != Node::Kind::Type ||
2027
- node->getNumChildren () == 0 )
2028
- return false ;
2029
- NodePointer classNode = node->getFirstChild ();
2030
- if (!classNode || classNode->getKind () != Node::Kind::Class ||
2031
- classNode->getNumChildren () < 2 )
2032
- return false ;
2033
- for (NodePointer child : *classNode)
2034
- if (child->getKind () == Node::Kind::Identifier && child->hasText ())
2035
- return child->getText ().starts_with (" __NS" ) ||
2036
- child->getText ().starts_with (" NSTaggedPointer" );
2037
- return false ;
2038
- }
2039
-
2040
2025
CompilerType SwiftLanguageRuntime::GetDynamicTypeAndAddress_EmbeddedClass (
2041
2026
uint64_t instance_ptr, CompilerType class_type) {
2042
2027
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
@@ -2091,44 +2076,41 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Class(
2091
2076
return false ;
2092
2077
2093
2078
auto tss = class_type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwift>();
2079
+ if (!tss) {
2080
+ // This could be an Objective-C type implemented in Swift. Get the
2081
+ // Swift typesystem.
2082
+ if (auto module_sp = in_value.GetModule ()) {
2083
+ auto type_system_or_err =
2084
+ module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2085
+ if (!type_system_or_err) {
2086
+ llvm::consumeError (type_system_or_err.takeError ());
2087
+ return false ;
2088
+ }
2089
+ auto ts_sp = *type_system_or_err;
2090
+ tss =
2091
+ llvm::cast<TypeSystemSwift>(ts_sp.get ())->GetTypeSystemSwiftTypeRef ();
2092
+ } else if (auto target_sp = in_value.GetTargetSP ()) {
2093
+ auto type_system_or_err =
2094
+ target_sp->GetScratchTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2095
+ if (!type_system_or_err) {
2096
+ llvm::consumeError (type_system_or_err.takeError ());
2097
+ return false ;
2098
+ }
2099
+ auto ts_sp = *type_system_or_err;
2100
+ tss =
2101
+ llvm::cast<TypeSystemSwift>(ts_sp.get ())->GetTypeSystemSwiftTypeRef ();
2102
+ }
2103
+ }
2094
2104
if (!tss)
2095
2105
return false ;
2106
+
2096
2107
address.SetRawAddress (instance_ptr);
2097
2108
auto ts = tss->GetTypeSystemSwiftTypeRef ();
2098
2109
if (!ts)
2099
2110
return false ;
2100
- // Ask the Objective-C runtime about Objective-C types.
2101
- if (tss->IsImportedType (class_type.GetOpaqueQualType (), nullptr ))
2102
- if (auto *objc_runtime =
2103
- SwiftLanguageRuntime::GetObjCRuntime (GetProcess ())) {
2104
- Value::ValueType value_type;
2105
- if (objc_runtime->GetDynamicTypeAndAddress (in_value, use_dynamic,
2106
- class_type_or_name, address,
2107
- value_type, local_buffer)) {
2108
- bool found = false ;
2109
- // Return the most specific class which we can get the typeref.
2110
- ForEachSuperClassType (in_value, [&](SuperClassType sc) -> bool {
2111
- if (auto *tr = sc.get_typeref ()) {
2112
- swift::Demangle::Demangler dem;
2113
- swift::Demangle::NodePointer node = tr->getDemangling (dem);
2114
- // Skip private Foundation types since it's unlikely that would be
2115
- // useful to users.
2116
- if (IsPrivateNSClass (node))
2117
- return false ;
2118
- class_type_or_name.SetCompilerType (ts->RemangleAsType (
2119
- dem, node, swift::Mangle::ManglingFlavor::Default));
2120
- found = true ;
2121
- return true ;
2122
- }
2123
- return false ;
2124
- });
2125
- return found;
2126
- }
2127
- return false ;
2128
- }
2129
- Log *log (GetLog (LLDBLog::Types));
2130
- // Scope reflection_ctx to minimize its lock scope.
2131
- {
2111
+
2112
+ auto resolve_swift = [&]() {
2113
+ // Scope reflection_ctx to minimize its lock scope.
2132
2114
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
2133
2115
if (!reflection_ctx)
2134
2116
return false ;
@@ -2172,10 +2154,17 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Class(
2172
2154
return false ;
2173
2155
}
2174
2156
}
2175
-
2176
- LLDB_LOG (log , " dynamic type of instance_ptr {0:x} is {1}" , instance_ptr,
2177
- class_type.GetMangledTypeName ());
2178
2157
class_type_or_name.SetCompilerType (dynamic_type);
2158
+ LLDB_LOG (GetLog (LLDBLog::Types),
2159
+ " dynamic type of instance_ptr {0:x} is {1}" , instance_ptr,
2160
+ class_type.GetMangledTypeName ());
2161
+ return true ;
2162
+ };
2163
+
2164
+ if (!resolve_swift ()) {
2165
+ // When returning false here, the next compatible runtime (=
2166
+ // Objective-C) will get ask to resolve this type.
2167
+ return false ;
2179
2168
}
2180
2169
2181
2170
#ifndef NDEBUG
@@ -2833,12 +2822,12 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_IndirectEnumCase(
2833
2822
2834
2823
return GetDynamicTypeAndAddress (*valobj_sp, use_dynamic, class_type_or_name,
2835
2824
address, value_type, local_buffer);
2836
- } else {
2837
- // This is most likely a statically known type.
2838
- address.SetLoadAddress (box_value, &GetProcess ().GetTarget ());
2839
- value_type = Value::GetValueTypeFromAddressType (eAddressTypeLoad);
2840
- return true ;
2841
2825
}
2826
+
2827
+ // This is most likely a statically known type.
2828
+ address.SetLoadAddress (box_value, &GetProcess ().GetTarget ());
2829
+ value_type = Value::GetValueTypeFromAddressType (eAddressTypeLoad);
2830
+ return true ;
2842
2831
}
2843
2832
2844
2833
void SwiftLanguageRuntime::DumpTyperef (CompilerType type,
@@ -3156,22 +3145,27 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
3156
3145
return false ;
3157
3146
3158
3147
LLDB_SCOPED_TIMER ();
3148
+ CompilerType val_type (in_value.GetCompilerType ());
3149
+ Value::ValueType static_value_type = Value::ValueType::Invalid;
3159
3150
3160
3151
// Try to import a Clang type into Swift.
3161
- if (in_value.GetObjectRuntimeLanguage () == eLanguageTypeObjC)
3162
- return GetDynamicTypeAndAddress_ClangType (in_value, use_dynamic,
3163
- class_type_or_name, address,
3164
- value_type, local_buffer);
3152
+ if (in_value.GetObjectRuntimeLanguage () == eLanguageTypeObjC) {
3153
+ if (GetDynamicTypeAndAddress_ClangType (in_value, use_dynamic,
3154
+ class_type_or_name, address,
3155
+ value_type, local_buffer))
3156
+ return true ;
3157
+ return GetDynamicTypeAndAddress_Class (in_value, val_type, use_dynamic,
3158
+ class_type_or_name, address,
3159
+ static_value_type, local_buffer);
3160
+ }
3165
3161
3166
3162
if (!CouldHaveDynamicValue (in_value))
3167
3163
return false ;
3168
3164
3169
- CompilerType val_type (in_value.GetCompilerType ());
3170
3165
Flags type_info (val_type.GetTypeInfo ());
3171
3166
if (!type_info.AnySet (eTypeIsSwift))
3172
3167
return false ;
3173
3168
3174
- Value::ValueType static_value_type = Value::ValueType::Invalid;
3175
3169
bool success = false ;
3176
3170
bool is_indirect_enum_case = IsIndirectEnumCase (in_value);
3177
3171
// Type kinds with instance metadata don't need generic type resolution.
0 commit comments