@@ -886,7 +886,7 @@ llvm::Optional<uint64_t> SwiftLanguageRuntimeImpl::GetMemberVariableOffsetRemote
886
886
auto frame = instance ? instance->GetExecutionContextRef ().GetFrameSP ().get ()
887
887
: nullptr ;
888
888
if (auto *ti = llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(
889
- GetTypeInfo (instance_type, frame))) {
889
+ GetSwiftRuntimeTypeInfo (instance_type, frame))) {
890
890
auto fields = ti->getFields ();
891
891
LLDB_LOGF (GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES),
892
892
" using record type info" );
@@ -1040,10 +1040,11 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
1040
1040
auto frame =
1041
1041
valobj ? valobj->GetExecutionContextRef ().GetFrameSP ().get () : nullptr ;
1042
1042
const swift::reflection::TypeRef *tr = nullptr ;
1043
- auto *ti = GetTypeInfo (type, frame, &tr);
1043
+ auto *ti = GetSwiftRuntimeTypeInfo (type, frame, &tr);
1044
+ if (!ti)
1045
+ return {};
1044
1046
// Structs and Tuples.
1045
- if (auto *rti =
1046
- llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
1047
+ if (auto *rti = llvm::dyn_cast<swift::reflection::RecordTypeInfo>(ti)) {
1047
1048
switch (rti->getRecordKind ()) {
1048
1049
case swift::reflection::RecordKind::ExistentialMetatype:
1049
1050
case swift::reflection::RecordKind::ThickFunction:
@@ -1060,13 +1061,11 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
1060
1061
return rti->getNumFields ();
1061
1062
}
1062
1063
}
1063
- if (auto *eti = llvm::dyn_cast_or_null <swift::reflection::EnumTypeInfo>(ti)) {
1064
+ if (auto *eti = llvm::dyn_cast <swift::reflection::EnumTypeInfo>(ti)) {
1064
1065
return eti->getNumPayloadCases ();
1065
1066
}
1066
1067
// Objects.
1067
- if (auto *rti =
1068
- llvm::dyn_cast_or_null<swift::reflection::ReferenceTypeInfo>(ti)) {
1069
-
1068
+ if (auto *rti = llvm::dyn_cast<swift::reflection::ReferenceTypeInfo>(ti)) {
1070
1069
switch (rti->getReferenceKind ()) {
1071
1070
case swift::reflection::ReferenceKind::Weak:
1072
1071
case swift::reflection::ReferenceKind::Unowned:
@@ -1113,7 +1112,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
1113
1112
using namespace swift ::reflection;
1114
1113
// Try the static type metadata.
1115
1114
const TypeRef *tr = nullptr ;
1116
- auto *ti = GetTypeInfo (type, exe_ctx->GetFramePtr (), &tr);
1115
+ auto *ti = GetSwiftRuntimeTypeInfo (type, exe_ctx->GetFramePtr (), &tr);
1116
+ if (!ti)
1117
+ return {};
1117
1118
// Structs and Tuples.
1118
1119
switch (ti->getKind ()) {
1119
1120
case TypeInfoKind::Record: {
@@ -1246,7 +1247,9 @@ llvm::Optional<std::string> SwiftLanguageRuntimeImpl::GetEnumCaseName(
1246
1247
CompilerType type, const DataExtractor &data, ExecutionContext *exe_ctx) {
1247
1248
using namespace swift ::reflection;
1248
1249
using namespace swift ::remote;
1249
- auto *ti = GetTypeInfo (type, exe_ctx->GetFramePtr ());
1250
+ auto *ti = GetSwiftRuntimeTypeInfo (type, exe_ctx->GetFramePtr ());
1251
+ if (!ti)
1252
+ return {};
1250
1253
if (ti->getKind () != TypeInfoKind::Enum)
1251
1254
return {};
1252
1255
@@ -1278,7 +1281,9 @@ llvm::Optional<size_t> SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
1278
1281
using namespace swift ::reflection;
1279
1282
// Try the static type metadata.
1280
1283
const TypeRef *tr = nullptr ;
1281
- auto *ti = GetTypeInfo (type, exe_ctx->GetFramePtr (), &tr);
1284
+ auto *ti = GetSwiftRuntimeTypeInfo (type, exe_ctx->GetFramePtr (), &tr);
1285
+ if (!ti)
1286
+ return {};
1282
1287
switch (ti->getKind ()) {
1283
1288
case TypeInfoKind::Record: {
1284
1289
// Structs and Tuples.
@@ -1391,7 +1396,9 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1391
1396
// Try the static type metadata.
1392
1397
auto frame =
1393
1398
valobj ? valobj->GetExecutionContextRef ().GetFrameSP ().get () : nullptr ;
1394
- auto *ti = GetTypeInfo (type, frame);
1399
+ auto *ti = GetSwiftRuntimeTypeInfo (type, frame);
1400
+ if (!ti)
1401
+ return {};
1395
1402
// Structs and Tuples.
1396
1403
if (auto *rti =
1397
1404
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
@@ -2486,7 +2493,8 @@ static bool CouldHaveDynamicValue(ValueObject &in_value) {
2486
2493
// disable it.
2487
2494
return !in_value.IsBaseClass ();
2488
2495
}
2489
- return var_type.IsPossibleDynamicType (nullptr , false , false );
2496
+ bool check_objc = true ;
2497
+ return var_type.IsPossibleDynamicType (nullptr , false , check_objc);
2490
2498
}
2491
2499
2492
2500
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress (
@@ -2497,10 +2505,6 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
2497
2505
if (use_dynamic == lldb::eNoDynamicValues)
2498
2506
return false ;
2499
2507
2500
- // Try to import a Clang type into Swift.
2501
- if (in_value.GetObjectRuntimeLanguage () == eLanguageTypeObjC)
2502
- return GetDynamicTypeAndAddress_ClangType (
2503
- in_value, use_dynamic, class_type_or_name, address, value_type);
2504
2508
2505
2509
if (!CouldHaveDynamicValue (in_value))
2506
2510
return false ;
@@ -2509,11 +2513,33 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
2509
2513
// use the scratch context where such operations are legal and safe.
2510
2514
assert (IsScratchContextLocked (in_value.GetTargetSP ()) &&
2511
2515
" Swift scratch context not locked ahead of dynamic type resolution" );
2516
+ CompilerType val_type (in_value.GetCompilerType ());
2517
+
2512
2518
llvm::Optional<SwiftASTContextReader> maybe_scratch_ctx =
2513
2519
in_value.GetScratchSwiftASTContext ();
2520
+
2521
+ // Try to import a Clang type into Swift.
2522
+ if (in_value.GetObjectRuntimeLanguage () == eLanguageTypeObjC) {
2523
+ if (GetDynamicTypeAndAddress_ClangType (
2524
+ in_value, use_dynamic, class_type_or_name, address, value_type))
2525
+ return true ;
2526
+ // If the type couldn't be resolved by the Clang runtime:
2527
+ // Foundation, for example, generates new Objective-C classes on
2528
+ // the fly (such as instances of _DictionaryStorage<T1, T2>) and
2529
+ // LLDB's ObjC runtime implementation isn't set up to recognize
2530
+ // these. As a workaround, try to resolve them as Swift types.
2531
+ if (val_type.GetCanonicalType ().GetTypeClass () ==
2532
+ eTypeClassObjCObjectPointer)
2533
+ if (maybe_scratch_ctx)
2534
+ if (auto *scratch_ctx = maybe_scratch_ctx->get ())
2535
+ val_type = scratch_ctx->GetObjCObjectType ();
2536
+ }
2537
+
2514
2538
if (!maybe_scratch_ctx)
2515
2539
return false ;
2516
2540
SwiftASTContextForExpressions *scratch_ctx = maybe_scratch_ctx->get ();
2541
+ if (!scratch_ctx)
2542
+ return false ;
2517
2543
2518
2544
auto retry_once = [&]() {
2519
2545
// Retry exactly once using the per-module fallback scratch context.
@@ -2536,7 +2562,6 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
2536
2562
2537
2563
// Import the type into the scratch context. Any form of dynamic
2538
2564
// type resolution may trigger a cross-module import.
2539
- CompilerType val_type (in_value.GetCompilerType ());
2540
2565
Flags type_info (val_type.GetTypeInfo ());
2541
2566
if (!type_info.AnySet (eTypeIsSwift))
2542
2567
return false ;
@@ -2754,7 +2779,8 @@ SwiftLanguageRuntimeImpl::GetTypeRef(CompilerType type,
2754
2779
return type_ref;
2755
2780
}
2756
2781
2757
- const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo (
2782
+ const swift::reflection::TypeInfo *
2783
+ SwiftLanguageRuntimeImpl::GetSwiftRuntimeTypeInfo (
2758
2784
CompilerType type, ExecutionContextScope *exe_scope,
2759
2785
swift::reflection::TypeRef const **out_tr) {
2760
2786
auto *ts = llvm::dyn_cast_or_null<TypeSystemSwift>(type.GetTypeSystem ());
@@ -2796,30 +2822,30 @@ const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo(
2796
2822
}
2797
2823
2798
2824
bool SwiftLanguageRuntimeImpl::IsStoredInlineInBuffer (CompilerType type) {
2799
- if (auto *type_info = GetTypeInfo (type, nullptr ))
2825
+ if (auto *type_info = GetSwiftRuntimeTypeInfo (type, nullptr ))
2800
2826
return type_info->isBitwiseTakable () && type_info->getSize () <= 24 ;
2801
2827
return true ;
2802
2828
}
2803
2829
2804
2830
llvm::Optional<uint64_t >
2805
2831
SwiftLanguageRuntimeImpl::GetBitSize (CompilerType type,
2806
2832
ExecutionContextScope *exe_scope) {
2807
- if (auto *type_info = GetTypeInfo (type, exe_scope))
2833
+ if (auto *type_info = GetSwiftRuntimeTypeInfo (type, exe_scope))
2808
2834
return type_info->getSize () * 8 ;
2809
2835
return {};
2810
2836
}
2811
2837
2812
2838
llvm::Optional<uint64_t >
2813
2839
SwiftLanguageRuntimeImpl::GetByteStride (CompilerType type) {
2814
- if (auto *type_info = GetTypeInfo (type, nullptr ))
2840
+ if (auto *type_info = GetSwiftRuntimeTypeInfo (type, nullptr ))
2815
2841
return type_info->getStride ();
2816
2842
return {};
2817
2843
}
2818
2844
2819
2845
llvm::Optional<size_t >
2820
2846
SwiftLanguageRuntimeImpl::GetBitAlignment (CompilerType type,
2821
2847
ExecutionContextScope *exe_scope) {
2822
- if (auto *type_info = GetTypeInfo (type, exe_scope))
2848
+ if (auto *type_info = GetSwiftRuntimeTypeInfo (type, exe_scope))
2823
2849
return type_info->getAlignment () * 8 ;
2824
2850
return {};
2825
2851
}
0 commit comments