@@ -1688,7 +1688,7 @@ CreatePackType(swift::Demangle::Demangler &dem, TypeSystemSwiftTypeRef &ts,
1688
1688
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Pack (
1689
1689
ValueObject &in_value, CompilerType pack_type,
1690
1690
lldb::DynamicValueType use_dynamic, TypeAndOrName &pack_type_or_name,
1691
- Address &address) {
1691
+ Address &address, Value::ValueType &value_type ) {
1692
1692
Log *log (GetLog (LLDBLog::Types));
1693
1693
auto *reflection_ctx = GetReflectionContext ();
1694
1694
if (!reflection_ctx)
@@ -1915,7 +1915,9 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Pack(
1915
1915
CompilerType expanded_type = ts->RemangleAsType (dem, transformed);
1916
1916
pack_type_or_name.SetCompilerType (expanded_type);
1917
1917
1918
- lldb::addr_t addr = in_value.GetAddressOf ();
1918
+ AddressType address_type;
1919
+ lldb::addr_t addr = in_value.GetAddressOf (true , &address_type);
1920
+ value_type = Value::GetValueTypeFromAddressType (address_type);
1919
1921
if (indirect) {
1920
1922
Status status;
1921
1923
addr = m_process.ReadPointerFromMemory (addr, status);
@@ -1961,9 +1963,11 @@ static bool IsPrivateNSClass(NodePointer node) {
1961
1963
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class (
1962
1964
ValueObject &in_value, CompilerType class_type,
1963
1965
lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name,
1964
- Address &address) {
1966
+ Address &address, Value::ValueType &value_type ) {
1965
1967
AddressType address_type;
1966
1968
lldb::addr_t instance_ptr = in_value.GetPointerValue (&address_type);
1969
+ value_type = Value::GetValueTypeFromAddressType (address_type);
1970
+
1967
1971
if (instance_ptr == LLDB_INVALID_ADDRESS || instance_ptr == 0 )
1968
1972
return false ;
1969
1973
@@ -2707,25 +2711,29 @@ bool SwiftLanguageRuntime::GetAbstractTypeName(StreamString &name,
2707
2711
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Value (
2708
2712
ValueObject &in_value, CompilerType &bound_type,
2709
2713
lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name,
2710
- Address &address) {
2714
+ Address &address, Value::ValueType &value_type) {
2715
+ value_type = Value::ValueType::Invalid;
2711
2716
class_type_or_name.SetCompilerType (bound_type);
2712
2717
2713
2718
ExecutionContext exe_ctx = in_value.GetExecutionContextRef ().Lock (true );
2714
2719
llvm::Optional<uint64_t > size =
2715
2720
bound_type.GetByteSize (exe_ctx.GetBestExecutionContextScope ());
2716
2721
if (!size)
2717
2722
return false ;
2718
- lldb::addr_t val_address = in_value.GetAddressOf (true , nullptr );
2723
+ AddressType address_type;
2724
+ lldb::addr_t val_address = in_value.GetAddressOf (true , &address_type);
2719
2725
if (*size && (!val_address || val_address == LLDB_INVALID_ADDRESS))
2720
2726
return false ;
2721
2727
2728
+ value_type = Value::GetValueTypeFromAddressType (address_type);
2722
2729
address.SetLoadAddress (val_address, in_value.GetTargetSP ().get ());
2723
2730
return true ;
2724
2731
}
2725
2732
2726
2733
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_IndirectEnumCase (
2727
2734
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
2728
- TypeAndOrName &class_type_or_name, Address &address) {
2735
+ TypeAndOrName &class_type_or_name, Address &address,
2736
+ Value::ValueType &value_type) {
2729
2737
static ConstString g_offset (" offset" );
2730
2738
2731
2739
DataExtractor data;
@@ -2779,7 +2787,6 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_IndirectEnumCase(
2779
2787
if (!valobj_sp)
2780
2788
return false ;
2781
2789
2782
- Value::ValueType value_type;
2783
2790
if (!GetDynamicTypeAndAddress (*valobj_sp, use_dynamic, class_type_or_name,
2784
2791
address, value_type))
2785
2792
return false ;
@@ -2807,7 +2814,6 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_IndirectEnumCase(
2807
2814
if (!valobj_sp)
2808
2815
return false ;
2809
2816
2810
- Value::ValueType value_type;
2811
2817
if (!GetDynamicTypeAndAddress (*valobj_sp, use_dynamic, class_type_or_name,
2812
2818
address, value_type))
2813
2819
return false ;
@@ -2851,8 +2857,8 @@ Process &SwiftLanguageRuntimeImpl::GetProcess() const {
2851
2857
Value::ValueType
2852
2858
SwiftLanguageRuntimeImpl::GetValueType (ValueObject &in_value,
2853
2859
CompilerType dynamic_type,
2860
+ Value::ValueType static_value_type,
2854
2861
bool is_indirect_enum_case) {
2855
- Value::ValueType static_value_type = in_value.GetValue ().GetValueType ();
2856
2862
CompilerType static_type = in_value.GetCompilerType ();
2857
2863
Flags static_type_flags (static_type.GetTypeInfo ());
2858
2864
Flags dynamic_type_flags (dynamic_type.GetTypeInfo ());
@@ -3057,19 +3063,20 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
3057
3063
if (!type_info.AnySet (eTypeIsSwift))
3058
3064
return false ;
3059
3065
3066
+ Value::ValueType static_value_type = Value::ValueType::Invalid;
3060
3067
bool success = false ;
3061
3068
bool is_indirect_enum_case = IsIndirectEnumCase (in_value);
3062
3069
// Type kinds with instance metadata don't need generic type resolution.
3063
3070
if (is_indirect_enum_case)
3064
3071
success = GetDynamicTypeAndAddress_IndirectEnumCase (
3065
- in_value, use_dynamic, class_type_or_name, address);
3072
+ in_value, use_dynamic, class_type_or_name, address, static_value_type );
3066
3073
else if (type_info.AnySet (eTypeIsPack))
3067
3074
success = GetDynamicTypeAndAddress_Pack (in_value, val_type, use_dynamic,
3068
- class_type_or_name, address);
3075
+ class_type_or_name, address, static_value_type );
3069
3076
else if (type_info.AnySet (eTypeIsClass) ||
3070
3077
type_info.AllSet (eTypeIsBuiltIn | eTypeIsPointer | eTypeHasValue))
3071
3078
success = GetDynamicTypeAndAddress_Class (in_value, val_type, use_dynamic,
3072
- class_type_or_name, address);
3079
+ class_type_or_name, address, static_value_type );
3073
3080
else if (type_info.AnySet (eTypeIsProtocol))
3074
3081
success = GetDynamicTypeAndAddress_Protocol (in_value, val_type, use_dynamic,
3075
3082
class_type_or_name, address);
@@ -3090,20 +3097,28 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
3090
3097
3091
3098
Flags subst_type_info (bound_type.GetTypeInfo ());
3092
3099
if (subst_type_info.AnySet (eTypeIsClass)) {
3093
- success = GetDynamicTypeAndAddress_Class (
3094
- in_value, bound_type, use_dynamic, class_type_or_name, address);
3100
+ success = GetDynamicTypeAndAddress_Class (in_value, bound_type,
3101
+ use_dynamic, class_type_or_name,
3102
+ address, static_value_type);
3095
3103
} else if (subst_type_info.AnySet (eTypeIsProtocol)) {
3096
3104
success = GetDynamicTypeAndAddress_Protocol (
3097
3105
in_value, bound_type, use_dynamic, class_type_or_name, address);
3098
3106
} else {
3099
- success = GetDynamicTypeAndAddress_Value (
3100
- in_value, bound_type, use_dynamic, class_type_or_name, address);
3107
+ success = GetDynamicTypeAndAddress_Value (in_value, bound_type,
3108
+ use_dynamic, class_type_or_name,
3109
+ address, static_value_type);
3101
3110
}
3102
3111
}
3103
3112
3104
- if (success)
3113
+ if (success) {
3114
+ // If we haven't found a better static value type, use the value object's
3115
+ // one.
3116
+ if (static_value_type == Value::ValueType::Invalid)
3117
+ static_value_type = in_value.GetValue ().GetValueType ();
3118
+
3105
3119
value_type = GetValueType (in_value, class_type_or_name.GetCompilerType (),
3106
- is_indirect_enum_case);
3120
+ static_value_type, is_indirect_enum_case);
3121
+ }
3107
3122
return success;
3108
3123
}
3109
3124
0 commit comments