@@ -576,6 +576,22 @@ static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
576
576
}
577
577
}
578
578
579
+ // / Returns the Swift type for a ValueObject representing a variable.
580
+ // / An invalid CompilerType is returned on error.
581
+ static CompilerType GetSwiftTypeForVariableValueObject (
582
+ lldb::ValueObjectSP valobj_sp, lldb::StackFrameSP &stack_frame_sp,
583
+ SwiftLanguageRuntime *runtime, bool use_dynamic_value) {
584
+ // Check that the passed ValueObject is valid.
585
+ if (!valobj_sp || valobj_sp->GetError ().Fail ())
586
+ return CompilerType ();
587
+ CompilerType result = valobj_sp->GetCompilerType ();
588
+ if (use_dynamic_value)
589
+ result = runtime->BindGenericTypeParameters (*stack_frame_sp, result);
590
+ if (!result.GetTypeSystem ()->SupportsLanguage (lldb::eLanguageTypeSwift))
591
+ return CompilerType ();
592
+ return result;
593
+ }
594
+
579
595
// / Create a \c VariableInfo record for \c variable if there isn't
580
596
// / already shadowing inner declaration in \c processed_variables.
581
597
static llvm::Optional<llvm::Error> AddVariableInfo (
@@ -602,31 +618,30 @@ static llvm::Optional<llvm::Error> AddVariableInfo(
602
618
if (processed_variables.count (overridden_name))
603
619
return {};
604
620
605
- CompilerType var_type;
606
- if (stack_frame_sp) {
607
- lldb::ValueObjectSP valobj_sp =
608
- stack_frame_sp->GetValueObjectForFrameVariable (variable_sp,
609
- use_dynamic);
621
+ if (!stack_frame_sp)
622
+ return llvm::None;
610
623
611
- if (!valobj_sp || valobj_sp->GetError ().Fail ()) {
612
- // Ignore the variable if we couldn't find its corresponding
613
- // value object. TODO if the expression tries to use an
614
- // ignored variable, produce a sensible error.
615
- return {};
616
- }
617
- var_type = valobj_sp->GetCompilerType ();
618
- if (use_dynamic > lldb::eNoDynamicValues) {
619
- if (auto *stack_frame = stack_frame_sp.get ())
620
- var_type =
621
- runtime->BindGenericTypeParameters (*stack_frame, var_type);
622
- }
623
- }
624
+ lldb::ValueObjectSP valobj_sp =
625
+ stack_frame_sp->GetValueObjectForFrameVariable (variable_sp,
626
+ lldb::eNoDynamicValues);
627
+
628
+ const bool use_dynamic_value = use_dynamic > lldb::eNoDynamicValues;
629
+
630
+ CompilerType var_type = GetSwiftTypeForVariableValueObject (
631
+ valobj_sp, stack_frame_sp, runtime, use_dynamic_value);
624
632
625
633
if (!var_type.IsValid ())
626
634
return {};
627
635
628
- if (!var_type.GetTypeSystem ()->SupportsLanguage (lldb::eLanguageTypeSwift))
629
- return {};
636
+ // If the type can't be realized and dynamic types are allowed, fall back to
637
+ // the dynamic type.
638
+ if (!SwiftASTContext::IsFullyRealized (var_type) && use_dynamic_value) {
639
+ var_type = GetSwiftTypeForVariableValueObject (
640
+ valobj_sp->GetDynamicValue (use_dynamic), stack_frame_sp, runtime,
641
+ use_dynamic_value);
642
+ if (!var_type.IsValid ())
643
+ return {};
644
+ }
630
645
631
646
Status error;
632
647
CompilerType target_type = ast_context.ImportType (var_type, error);
0 commit comments