@@ -1668,7 +1668,7 @@ CreatePackType(swift::Demangle::Demangler &dem, TypeSystemSwiftTypeRef &ts,
1668
1668
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Pack (
1669
1669
ValueObject &in_value, CompilerType pack_type,
1670
1670
lldb::DynamicValueType use_dynamic, TypeAndOrName &pack_type_or_name,
1671
- Address &address) {
1671
+ Address &address, Value::ValueType &value_type ) {
1672
1672
Log *log (GetLog (LLDBLog::Types));
1673
1673
auto *reflection_ctx = GetReflectionContext ();
1674
1674
if (!reflection_ctx)
@@ -1895,7 +1895,9 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Pack(
1895
1895
CompilerType expanded_type = ts->RemangleAsType (dem, transformed);
1896
1896
pack_type_or_name.SetCompilerType (expanded_type);
1897
1897
1898
- lldb::addr_t addr = in_value.GetAddressOf ();
1898
+ AddressType address_type;
1899
+ lldb::addr_t addr = in_value.GetAddressOf (true , &address_type);
1900
+ value_type = Value::GetValueTypeFromAddressType (address_type);
1899
1901
if (indirect) {
1900
1902
Status status;
1901
1903
addr = m_process.ReadPointerFromMemory (addr, status);
@@ -1943,9 +1945,11 @@ static bool IsPrivateNSClass(NodePointer node) {
1943
1945
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class (
1944
1946
ValueObject &in_value, CompilerType class_type,
1945
1947
lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name,
1946
- Address &address) {
1948
+ Address &address, Value::ValueType &value_type ) {
1947
1949
AddressType address_type;
1948
1950
lldb::addr_t instance_ptr = in_value.GetPointerValue (&address_type);
1951
+ value_type = Value::GetValueTypeFromAddressType (address_type);
1952
+
1949
1953
if (instance_ptr == LLDB_INVALID_ADDRESS || instance_ptr == 0 )
1950
1954
return false ;
1951
1955
@@ -2689,25 +2693,29 @@ bool SwiftLanguageRuntime::GetAbstractTypeName(StreamString &name,
2689
2693
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Value (
2690
2694
ValueObject &in_value, CompilerType &bound_type,
2691
2695
lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name,
2692
- Address &address) {
2696
+ Address &address, Value::ValueType &value_type) {
2697
+ value_type = Value::ValueType::Invalid;
2693
2698
class_type_or_name.SetCompilerType (bound_type);
2694
2699
2695
2700
ExecutionContext exe_ctx = in_value.GetExecutionContextRef ().Lock (true );
2696
2701
llvm::Optional<uint64_t > size =
2697
2702
bound_type.GetByteSize (exe_ctx.GetBestExecutionContextScope ());
2698
2703
if (!size)
2699
2704
return false ;
2700
- lldb::addr_t val_address = in_value.GetAddressOf (true , nullptr );
2705
+ AddressType address_type;
2706
+ lldb::addr_t val_address = in_value.GetAddressOf (true , &address_type);
2701
2707
if (*size && (!val_address || val_address == LLDB_INVALID_ADDRESS))
2702
2708
return false ;
2703
2709
2710
+ value_type = Value::GetValueTypeFromAddressType (address_type);
2704
2711
address.SetLoadAddress (val_address, in_value.GetTargetSP ().get ());
2705
2712
return true ;
2706
2713
}
2707
2714
2708
2715
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_IndirectEnumCase (
2709
2716
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
2710
- TypeAndOrName &class_type_or_name, Address &address) {
2717
+ TypeAndOrName &class_type_or_name, Address &address,
2718
+ Value::ValueType &value_type) {
2711
2719
static ConstString g_offset (" offset" );
2712
2720
2713
2721
DataExtractor data;
@@ -2761,7 +2769,6 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_IndirectEnumCase(
2761
2769
if (!valobj_sp)
2762
2770
return false ;
2763
2771
2764
- Value::ValueType value_type;
2765
2772
if (!GetDynamicTypeAndAddress (*valobj_sp, use_dynamic, class_type_or_name,
2766
2773
address, value_type))
2767
2774
return false ;
@@ -2789,7 +2796,6 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_IndirectEnumCase(
2789
2796
if (!valobj_sp)
2790
2797
return false ;
2791
2798
2792
- Value::ValueType value_type;
2793
2799
if (!GetDynamicTypeAndAddress (*valobj_sp, use_dynamic, class_type_or_name,
2794
2800
address, value_type))
2795
2801
return false ;
@@ -2833,8 +2839,8 @@ Process &SwiftLanguageRuntimeImpl::GetProcess() const {
2833
2839
Value::ValueType
2834
2840
SwiftLanguageRuntimeImpl::GetValueType (ValueObject &in_value,
2835
2841
CompilerType dynamic_type,
2842
+ Value::ValueType static_value_type,
2836
2843
bool is_indirect_enum_case) {
2837
- Value::ValueType static_value_type = in_value.GetValue ().GetValueType ();
2838
2844
CompilerType static_type = in_value.GetCompilerType ();
2839
2845
Flags static_type_flags (static_type.GetTypeInfo ());
2840
2846
Flags dynamic_type_flags (dynamic_type.GetTypeInfo ());
@@ -3039,19 +3045,20 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
3039
3045
if (!type_info.AnySet (eTypeIsSwift))
3040
3046
return false ;
3041
3047
3048
+ Value::ValueType static_value_type = Value::ValueType::Invalid;
3042
3049
bool success = false ;
3043
3050
bool is_indirect_enum_case = IsIndirectEnumCase (in_value);
3044
3051
// Type kinds with instance metadata don't need generic type resolution.
3045
3052
if (is_indirect_enum_case)
3046
3053
success = GetDynamicTypeAndAddress_IndirectEnumCase (
3047
- in_value, use_dynamic, class_type_or_name, address);
3054
+ in_value, use_dynamic, class_type_or_name, address, static_value_type );
3048
3055
else if (type_info.AnySet (eTypeIsPack))
3049
3056
success = GetDynamicTypeAndAddress_Pack (in_value, val_type, use_dynamic,
3050
- class_type_or_name, address);
3057
+ class_type_or_name, address, static_value_type );
3051
3058
else if (type_info.AnySet (eTypeIsClass) ||
3052
3059
type_info.AllSet (eTypeIsBuiltIn | eTypeIsPointer | eTypeHasValue))
3053
3060
success = GetDynamicTypeAndAddress_Class (in_value, val_type, use_dynamic,
3054
- class_type_or_name, address);
3061
+ class_type_or_name, address, static_value_type );
3055
3062
else if (type_info.AnySet (eTypeIsProtocol))
3056
3063
success = GetDynamicTypeAndAddress_Protocol (in_value, val_type, use_dynamic,
3057
3064
class_type_or_name, address);
@@ -3072,20 +3079,28 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
3072
3079
3073
3080
Flags subst_type_info (bound_type.GetTypeInfo ());
3074
3081
if (subst_type_info.AnySet (eTypeIsClass)) {
3075
- success = GetDynamicTypeAndAddress_Class (
3076
- in_value, bound_type, use_dynamic, class_type_or_name, address);
3082
+ success = GetDynamicTypeAndAddress_Class (in_value, bound_type,
3083
+ use_dynamic, class_type_or_name,
3084
+ address, static_value_type);
3077
3085
} else if (subst_type_info.AnySet (eTypeIsProtocol)) {
3078
3086
success = GetDynamicTypeAndAddress_Protocol (
3079
3087
in_value, bound_type, use_dynamic, class_type_or_name, address);
3080
3088
} else {
3081
- success = GetDynamicTypeAndAddress_Value (
3082
- in_value, bound_type, use_dynamic, class_type_or_name, address);
3089
+ success = GetDynamicTypeAndAddress_Value (in_value, bound_type,
3090
+ use_dynamic, class_type_or_name,
3091
+ address, static_value_type);
3083
3092
}
3084
3093
}
3085
3094
3086
- if (success)
3095
+ if (success) {
3096
+ // If we haven't found a better static value type, use the value object's
3097
+ // one.
3098
+ if (static_value_type == Value::ValueType::Invalid)
3099
+ static_value_type = in_value.GetValue ().GetValueType ();
3100
+
3087
3101
value_type = GetValueType (in_value, class_type_or_name.GetCompilerType (),
3088
- is_indirect_enum_case);
3102
+ static_value_type, is_indirect_enum_case);
3103
+ }
3089
3104
return success;
3090
3105
}
3091
3106
0 commit comments