@@ -479,7 +479,7 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
479
479
if (stack_frame_sp) {
480
480
lldb::ValueObjectSP valobj_sp =
481
481
stack_frame_sp->GetValueObjectForFrameVariable (self_var_sp,
482
- lldb::eNoDynamicValues );
482
+ lldb::eDynamicCanRunTarget );
483
483
484
484
if (valobj_sp)
485
485
self_type = valobj_sp->GetCompilerType ();
@@ -604,7 +604,7 @@ static void AddVariableInfo(
604
604
if (stack_frame_sp) {
605
605
lldb::ValueObjectSP valobj_sp =
606
606
stack_frame_sp->GetValueObjectForFrameVariable (variable_sp,
607
- lldb::eNoDynamicValues );
607
+ lldb::eDynamicCanRunTarget );
608
608
609
609
if (!valobj_sp || valobj_sp->GetError ().Fail ()) {
610
610
// Ignore the variable if we couldn't find its corresponding
@@ -628,12 +628,6 @@ static void AddVariableInfo(
628
628
if (!target_type.IsValid ())
629
629
return ;
630
630
631
- // Resolve all archetypes in the variable type.
632
- if (stack_frame_sp)
633
- if (language_runtime)
634
- target_type = language_runtime->BindGenericTypeParameters (*stack_frame_sp,
635
- target_type);
636
-
637
631
// If we couldn't fully realize the type, then we aren't going
638
632
// to get very far making a local out of it, so discard it here.
639
633
Log *log (lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_TYPES |
@@ -642,7 +636,7 @@ static void AddVariableInfo(
642
636
if (log )
643
637
log ->Printf (" Discarding local %s because we couldn't fully realize it, "
644
638
" our best attempt was: %s." ,
645
- name_cstr, target_type.GetTypeName ().AsCString (" <unknown>" ));
639
+ name_cstr, target_type.GetDisplayTypeName ().AsCString (" <unknown>" ));
646
640
return ;
647
641
}
648
642
@@ -656,8 +650,27 @@ static void AddVariableInfo(
656
650
static_cast <void *>(swift_type.getPointer ()),
657
651
static_cast <void *>(ast_context.GetASTContext ()), s.c_str ());
658
652
}
653
+ // A one-off clone of variable_sp with the type replaced by target_type.
654
+ auto patched_variable_sp = std::make_shared<lldb_private::Variable>(
655
+ 0 , variable_sp->GetName ().GetCString (), " " ,
656
+ std::make_shared<lldb_private::SymbolFileType>(
657
+ *variable_sp->GetType ()->GetSymbolFile (),
658
+ std::make_shared<lldb_private::Type>(
659
+ 0 , variable_sp->GetType ()->GetSymbolFile (),
660
+ variable_sp->GetType ()->GetName (), llvm::None,
661
+ variable_sp->GetType ()->GetSymbolContextScope (), LLDB_INVALID_UID,
662
+ Type::eEncodingIsUID, variable_sp->GetType ()->GetDeclaration (),
663
+ target_type, lldb_private::Type::ResolveState::Full,
664
+ variable_sp->GetType ()->GetPayload ())),
665
+ variable_sp->GetScope (), variable_sp->GetSymbolContextScope (),
666
+ variable_sp->GetScopeRange (),
667
+ const_cast <lldb_private::Declaration *>(&variable_sp->GetDeclaration ()),
668
+ variable_sp->LocationExpression (), variable_sp->IsExternal (),
669
+ variable_sp->IsArtificial (),
670
+ variable_sp->GetLocationIsConstantValueData (),
671
+ variable_sp->IsStaticMember (), variable_sp->IsConstant ());
659
672
SwiftASTManipulatorBase::VariableMetadataSP metadata_sp (
660
- new VariableMetadataVariable (variable_sp ));
673
+ new VariableMetadataVariable (patched_variable_sp ));
661
674
SwiftASTManipulator::VariableInfo variable_info (
662
675
target_type, ast_context.GetASTContext ()->getIdentifier (overridden_name),
663
676
metadata_sp,
@@ -917,6 +930,23 @@ CreateMainFile(SwiftASTContextForExpressions &swift_ast_context,
917
930
return {buffer_id, filename.str ()};
918
931
}
919
932
933
+ // / Determine whether this type was defined inside an LLDB expression.
934
+ template <typename TypeType> bool FromLLDBModuleImpl (TypeType *type) {
935
+ if (auto *decl = type->getDecl ())
936
+ if (auto *module = decl->getModuleContext ())
937
+ return module->getName ().str ().startswith (" __lldb_expr_" );
938
+ return false ;
939
+ };
940
+
941
+ // / Determine whether this type was defined inside an LLDB expression.
942
+ static bool FromLLDBModule (swift::TypeBase *type) {
943
+ if (auto *type_alias = llvm::dyn_cast<swift::TypeAliasType>(type))
944
+ return FromLLDBModuleImpl (type_alias);
945
+ if (auto *nominal = llvm::dyn_cast<swift::NominalType>(type))
946
+ return FromLLDBModuleImpl (nominal);
947
+ return false ;
948
+ }
949
+
920
950
// / Attempt to materialize one variable.
921
951
static llvm::Optional<SwiftExpressionParser::SILVariableInfo>
922
952
MaterializeVariable (SwiftASTManipulatorBase::VariableInfo &variable,
@@ -954,23 +984,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
954
984
}
955
985
}
956
986
} else {
957
- CompilerType actual_type (variable.GetType ());
958
- auto orig_swift_type = GetSwiftType (actual_type);
959
- auto *swift_type = orig_swift_type->mapTypeOutOfContext ().getPointer ();
960
- actual_type = ToCompilerType (swift_type);
961
- lldb::StackFrameSP stack_frame_sp = stack_frame_wp.lock ();
962
- if (swift_type->hasTypeParameter ()) {
963
- if (stack_frame_sp && stack_frame_sp->GetThread () &&
964
- stack_frame_sp->GetThread ()->GetProcess ()) {
965
- auto *swift_runtime = SwiftLanguageRuntime::Get (
966
- stack_frame_sp->GetThread ()->GetProcess ());
967
- if (swift_runtime) {
968
- actual_type = swift_runtime->BindGenericTypeParameters (
969
- *stack_frame_sp, actual_type);
970
- }
971
- }
972
- }
973
-
987
+ CompilerType actual_type = variable.GetType ();
974
988
// Desugar '$lldb_context', etc.
975
989
auto transformed_type = GetSwiftType (actual_type).transform (
976
990
[](swift::Type t) -> swift::Type {
@@ -981,7 +995,21 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
981
995
}
982
996
return t;
983
997
});
984
- actual_type = ToCompilerType (transformed_type.getPointer ());
998
+ actual_type =
999
+ ToCompilerType (transformed_type->mapTypeOutOfContext ().getPointer ());
1000
+ // CompilerType return_ast_type =
1001
+ // ToCompilerType(result_type->mapTypeOutOfContext());
1002
+ auto *swift_ast_ctx =
1003
+ llvm::cast<SwiftASTContext>(actual_type.GetTypeSystem ());
1004
+
1005
+ // Currently the Swift runtime cannot resolve types that were
1006
+ // defined in the expression evaluator. That's because we don't
1007
+ // tell it about type metadata sections that were JIT-compiled
1008
+ // by the expression evaluator. Until that is implemented, fall
1009
+ // back to SwiftASTContext.
1010
+ if (!FromLLDBModule (transformed_type.getPointer ()))
1011
+ actual_type =
1012
+ swift_ast_ctx->GetTypeRefType (actual_type.GetOpaqueQualType ());
985
1013
986
1014
if (is_result)
987
1015
offset = materializer.AddResultVariable (
@@ -1009,9 +1037,6 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
1009
1037
VariableMetadataVariable *variable_metadata =
1010
1038
static_cast <VariableMetadataVariable *>(variable.m_metadata .get ());
1011
1039
1012
- // FIXME: It would be nice if we could do something like
1013
- // variable_metadata->m_variable_sp->SetType(variable.GetType())
1014
- // here.
1015
1040
offset = materializer.AddVariable (variable_metadata->m_variable_sp , error);
1016
1041
1017
1042
if (!error.Success ()) {
0 commit comments