@@ -447,6 +447,55 @@ class LLDBREPLNameLookup : public LLDBNameLookup {
447
447
};
448
448
}; // END Anonymous namespace
449
449
450
+
451
+ // / Returns the Swift type for a ValueObject representing a variable.
452
+ // / An invalid CompilerType is returned on error.
453
+ static CompilerType GetSwiftTypeForVariableValueObject (
454
+ lldb::ValueObjectSP valobj_sp, lldb::StackFrameSP &stack_frame_sp,
455
+ SwiftLanguageRuntime *runtime, bool use_dynamic_value) {
456
+ // Check that the passed ValueObject is valid.
457
+ if (!valobj_sp || valobj_sp->GetError ().Fail ())
458
+ return CompilerType ();
459
+ CompilerType result = valobj_sp->GetCompilerType ();
460
+ if (use_dynamic_value)
461
+ result = runtime->BindGenericTypeParameters (*stack_frame_sp, result);
462
+ if (!result.GetTypeSystem ()->SupportsLanguage (lldb::eLanguageTypeSwift))
463
+ return CompilerType ();
464
+ return result;
465
+ }
466
+
467
+ // / Return the type for a local variable. This function is threading a
468
+ // / fine line between using dynamic type resolution to resolve generic
469
+ // / types and not resolving too much: Objective-C classes can have
470
+ // / more specific private implementations that LLDB can resolve, but
471
+ // / SwiftASTContext cannot see because there is no header file that
472
+ // / would declare them.
473
+ static CompilerType ResolveVariable (
474
+ lldb::VariableSP variable_sp, lldb::StackFrameSP &stack_frame_sp,
475
+ SwiftLanguageRuntime * runtime, lldb::DynamicValueType use_dynamic) {
476
+ lldb::ValueObjectSP valobj_sp =
477
+ stack_frame_sp->GetValueObjectForFrameVariable (variable_sp,
478
+ lldb::eNoDynamicValues);
479
+ const bool use_dynamic_value = use_dynamic > lldb::eNoDynamicValues;
480
+
481
+ CompilerType var_type = GetSwiftTypeForVariableValueObject (
482
+ valobj_sp, stack_frame_sp, runtime, use_dynamic_value);
483
+
484
+ if (!var_type.IsValid ())
485
+ return {};
486
+
487
+ // If the type can't be realized and dynamic types are allowed, fall back to
488
+ // the dynamic type.
489
+ if (!SwiftASTContext::IsFullyRealized (var_type) && use_dynamic_value) {
490
+ var_type = GetSwiftTypeForVariableValueObject (
491
+ valobj_sp->GetDynamicValue (use_dynamic), stack_frame_sp, runtime,
492
+ use_dynamic_value);
493
+ if (!var_type.IsValid ())
494
+ return {};
495
+ }
496
+ return var_type;
497
+ }
498
+
450
499
static void AddRequiredAliases (Block *block, lldb::StackFrameSP &stack_frame_sp,
451
500
SwiftASTContextForExpressions &swift_ast_context,
452
501
SwiftASTManipulator &manipulator,
@@ -475,16 +524,10 @@ static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
475
524
if (!self_var_sp)
476
525
return ;
477
526
478
- CompilerType self_type;
479
-
480
- if (stack_frame_sp) {
481
- lldb::ValueObjectSP valobj_sp =
482
- stack_frame_sp->GetValueObjectForFrameVariable (self_var_sp,
483
- use_dynamic);
484
-
485
- if (valobj_sp)
486
- self_type = valobj_sp->GetCompilerType ();
487
- }
527
+ auto *swift_runtime =
528
+ SwiftLanguageRuntime::Get (stack_frame_sp->GetThread ()->GetProcess ());
529
+ CompilerType self_type =
530
+ ResolveVariable (self_var_sp, stack_frame_sp, swift_runtime, use_dynamic);
488
531
489
532
if (!self_type.IsValid ()) {
490
533
if (Type *type = self_var_sp->GetType ()) {
@@ -504,8 +547,6 @@ static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
504
547
if (!imported_self_type.IsValid ())
505
548
return ;
506
549
507
- auto *swift_runtime =
508
- SwiftLanguageRuntime::Get (stack_frame_sp->GetThread ()->GetProcess ());
509
550
auto *stack_frame = stack_frame_sp.get ();
510
551
imported_self_type = swift_runtime->BindGenericTypeParameters (
511
552
*stack_frame, imported_self_type);
@@ -588,22 +629,6 @@ static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
588
629
}
589
630
}
590
631
591
- // / Returns the Swift type for a ValueObject representing a variable.
592
- // / An invalid CompilerType is returned on error.
593
- static CompilerType GetSwiftTypeForVariableValueObject (
594
- lldb::ValueObjectSP valobj_sp, lldb::StackFrameSP &stack_frame_sp,
595
- SwiftLanguageRuntime *runtime, bool use_dynamic_value) {
596
- // Check that the passed ValueObject is valid.
597
- if (!valobj_sp || valobj_sp->GetError ().Fail ())
598
- return CompilerType ();
599
- CompilerType result = valobj_sp->GetCompilerType ();
600
- if (use_dynamic_value)
601
- result = runtime->BindGenericTypeParameters (*stack_frame_sp, result);
602
- if (!result.GetTypeSystem ()->SupportsLanguage (lldb::eLanguageTypeSwift))
603
- return CompilerType ();
604
- return result;
605
- }
606
-
607
632
// / Create a \c VariableInfo record for \c variable if there isn't
608
633
// / already shadowing inner declaration in \c processed_variables.
609
634
static llvm::Optional<llvm::Error> AddVariableInfo (
@@ -633,27 +658,8 @@ static llvm::Optional<llvm::Error> AddVariableInfo(
633
658
if (!stack_frame_sp)
634
659
return llvm::None;
635
660
636
- lldb::ValueObjectSP valobj_sp =
637
- stack_frame_sp->GetValueObjectForFrameVariable (variable_sp,
638
- lldb::eNoDynamicValues);
639
-
640
- const bool use_dynamic_value = use_dynamic > lldb::eNoDynamicValues;
641
-
642
- CompilerType var_type = GetSwiftTypeForVariableValueObject (
643
- valobj_sp, stack_frame_sp, runtime, use_dynamic_value);
644
-
645
- if (!var_type.IsValid ())
646
- return {};
647
-
648
- // If the type can't be realized and dynamic types are allowed, fall back to
649
- // the dynamic type.
650
- if (!SwiftASTContext::IsFullyRealized (var_type) && use_dynamic_value) {
651
- var_type = GetSwiftTypeForVariableValueObject (
652
- valobj_sp->GetDynamicValue (use_dynamic), stack_frame_sp, runtime,
653
- use_dynamic_value);
654
- if (!var_type.IsValid ())
655
- return {};
656
- }
661
+ CompilerType var_type =
662
+ ResolveVariable (variable_sp, stack_frame_sp, runtime, use_dynamic);
657
663
658
664
Status error;
659
665
CompilerType target_type = ast_context.ImportType (var_type, error);
0 commit comments