@@ -1847,7 +1847,8 @@ static bool IsPrivateNSClass(NodePointer node) {
1847
1847
bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Class (
1848
1848
ValueObject &in_value, CompilerType class_type,
1849
1849
lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name,
1850
- Address &address, Value::ValueType &value_type) {
1850
+ Address &address, Value::ValueType &value_type,
1851
+ llvm::ArrayRef<uint8_t > &local_buffer) {
1851
1852
AddressType address_type;
1852
1853
lldb::addr_t instance_ptr = in_value.GetPointerValue (&address_type);
1853
1854
value_type = Value::GetValueTypeFromAddressType (address_type);
@@ -1873,8 +1874,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Class(
1873
1874
if (auto *objc_runtime =
1874
1875
SwiftLanguageRuntime::GetObjCRuntime (GetProcess ())) {
1875
1876
Value::ValueType value_type;
1876
- if (objc_runtime->GetDynamicTypeAndAddress (
1877
- in_value, use_dynamic, class_type_or_name, address, value_type)) {
1877
+ if (objc_runtime->GetDynamicTypeAndAddress (in_value, use_dynamic,
1878
+ class_type_or_name, address,
1879
+ value_type, local_buffer)) {
1878
1880
bool found = false ;
1879
1881
// Return the most specific class which we can get the typeref.
1880
1882
ForEachSuperClassType (in_value, [&](SuperClassType sc) -> bool {
@@ -2430,17 +2432,41 @@ bool SwiftLanguageRuntime::GetAbstractTypeName(StreamString &name,
2430
2432
bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Value (
2431
2433
ValueObject &in_value, CompilerType &bound_type,
2432
2434
lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name,
2433
- Address &address, Value::ValueType &value_type) {
2435
+ Address &address, Value::ValueType &value_type,
2436
+ llvm::ArrayRef<uint8_t > &local_buffer) {
2437
+ auto static_type = in_value.GetCompilerType ();
2434
2438
value_type = Value::ValueType::Invalid;
2435
2439
class_type_or_name.SetCompilerType (bound_type);
2436
2440
2437
2441
ExecutionContext exe_ctx = in_value.GetExecutionContextRef ().Lock (true );
2442
+ ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope ();
2443
+ if (!exe_scope)
2444
+ return false ;
2438
2445
std::optional<uint64_t > size =
2439
2446
bound_type.GetByteSize (exe_ctx.GetBestExecutionContextScope ());
2440
2447
if (!size)
2441
2448
return false ;
2442
2449
AddressType address_type;
2443
2450
lldb::addr_t val_address = in_value.GetAddressOf (true , &address_type);
2451
+ // If we couldn't find a load address, but the value object has a local
2452
+ // buffer, use that.
2453
+ if (val_address == LLDB_INVALID_ADDRESS && address_type == eAddressTypeHost) {
2454
+ // Get the start and size of the local buffer.
2455
+ auto start = in_value.GetValue ().GetScalar ().ULongLong ();
2456
+ auto local_buffer_size = in_value.GetLocalBufferSize ();
2457
+
2458
+ // If we can't find the size of the local buffer we can't safely know if the
2459
+ // dynamic type fits in it.
2460
+ if (local_buffer_size == LLDB_INVALID_ADDRESS)
2461
+ return false ;
2462
+ // If the dynamic type doesn't in the buffer we can't use it either.
2463
+ if (local_buffer_size < bound_type.GetByteSize (exe_scope))
2464
+ return false ;
2465
+
2466
+ value_type = Value::GetValueTypeFromAddressType (address_type);
2467
+ local_buffer = {(uint8_t *)start, local_buffer_size};
2468
+ return true ;
2469
+ }
2444
2470
if (*size && (!val_address || val_address == LLDB_INVALID_ADDRESS))
2445
2471
return false ;
2446
2472
@@ -2452,7 +2478,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Value(
2452
2478
bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_IndirectEnumCase (
2453
2479
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
2454
2480
TypeAndOrName &class_type_or_name, Address &address,
2455
- Value::ValueType &value_type) {
2481
+ Value::ValueType &value_type, llvm::ArrayRef< uint8_t > &local_buffer ) {
2456
2482
Status error;
2457
2483
CompilerType child_type = in_value.GetCompilerType ();
2458
2484
class_type_or_name.SetCompilerType (child_type);
@@ -2484,7 +2510,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_IndirectEnumCase(
2484
2510
return false ;
2485
2511
2486
2512
return GetDynamicTypeAndAddress (*valobj_sp, use_dynamic, class_type_or_name,
2487
- address, value_type);
2513
+ address, value_type, local_buffer );
2488
2514
} else {
2489
2515
// This is most likely a statically known type.
2490
2516
address.SetLoadAddress (box_value, &GetProcess ().GetTarget ());
@@ -2510,7 +2536,8 @@ void SwiftLanguageRuntime::DumpTyperef(CompilerType type,
2510
2536
2511
2537
Value::ValueType SwiftLanguageRuntime::GetValueType (
2512
2538
ValueObject &in_value, CompilerType dynamic_type,
2513
- Value::ValueType static_value_type, bool is_indirect_enum_case) {
2539
+ Value::ValueType static_value_type, bool is_indirect_enum_case,
2540
+ llvm::ArrayRef<uint8_t > &local_buffer) {
2514
2541
CompilerType static_type = in_value.GetCompilerType ();
2515
2542
Flags static_type_flags (static_type.GetTypeInfo ());
2516
2543
Flags dynamic_type_flags (dynamic_type.GetTypeInfo ());
@@ -2564,6 +2591,12 @@ Value::ValueType SwiftLanguageRuntime::GetValueType(
2564
2591
// If the data is not inlined, we have a pointer.
2565
2592
return Value::ValueType::LoadAddress;
2566
2593
}
2594
+ // If we found a host address and the dynamic type fits in there, and
2595
+ // this is not a pointer from an existential container, then this points to
2596
+ // the local buffer.
2597
+ if (static_value_type == Value::ValueType::HostAddress &&
2598
+ !local_buffer.empty ())
2599
+ return static_value_type;
2567
2600
2568
2601
if (static_type_flags.AllSet (eTypeIsSwift | eTypeIsGenericTypeParam)) {
2569
2602
// if I am handling a non-pointer Swift type obtained from an archetype,
@@ -2671,7 +2704,7 @@ std::optional<SwiftNominalType> GetSwiftClass(ValueObject &valobj,
2671
2704
bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_ClangType (
2672
2705
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
2673
2706
TypeAndOrName &class_type_or_name, Address &address,
2674
- Value::ValueType &value_type) {
2707
+ Value::ValueType &value_type, llvm::ArrayRef< uint8_t > &local_buffer ) {
2675
2708
AppleObjCRuntime *objc_runtime =
2676
2709
SwiftLanguageRuntime::GetObjCRuntime (GetProcess ());
2677
2710
if (!objc_runtime)
@@ -2684,8 +2717,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_ClangType(
2684
2717
// resolution first, and then map the dynamic Objective-C type back
2685
2718
// into Swift.
2686
2719
TypeAndOrName dyn_class_type_or_name = class_type_or_name;
2687
- if (!objc_runtime->GetDynamicTypeAndAddress (
2688
- in_value, use_dynamic, dyn_class_type_or_name, address, value_type))
2720
+ if (!objc_runtime->GetDynamicTypeAndAddress (in_value, use_dynamic,
2721
+ dyn_class_type_or_name, address,
2722
+ value_type, local_buffer))
2689
2723
return false ;
2690
2724
2691
2725
StringRef dyn_name = dyn_class_type_or_name.GetName ().GetStringRef ();
@@ -2791,7 +2825,7 @@ static bool CouldHaveDynamicValue(ValueObject &in_value) {
2791
2825
bool SwiftLanguageRuntime::GetDynamicTypeAndAddress (
2792
2826
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
2793
2827
TypeAndOrName &class_type_or_name, Address &address,
2794
- Value::ValueType &value_type) {
2828
+ Value::ValueType &value_type, llvm::ArrayRef< uint8_t > &local_buffer ) {
2795
2829
class_type_or_name.Clear ();
2796
2830
if (use_dynamic == lldb::eNoDynamicValues)
2797
2831
return false ;
@@ -2800,8 +2834,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2800
2834
2801
2835
// Try to import a Clang type into Swift.
2802
2836
if (in_value.GetObjectRuntimeLanguage () == eLanguageTypeObjC)
2803
- return GetDynamicTypeAndAddress_ClangType (
2804
- in_value, use_dynamic, class_type_or_name, address, value_type);
2837
+ return GetDynamicTypeAndAddress_ClangType (in_value, use_dynamic,
2838
+ class_type_or_name, address,
2839
+ value_type, local_buffer);
2805
2840
2806
2841
if (!CouldHaveDynamicValue (in_value))
2807
2842
return false ;
@@ -2817,7 +2852,8 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2817
2852
// Type kinds with instance metadata don't need generic type resolution.
2818
2853
if (is_indirect_enum_case)
2819
2854
success = GetDynamicTypeAndAddress_IndirectEnumCase (
2820
- in_value, use_dynamic, class_type_or_name, address, static_value_type);
2855
+ in_value, use_dynamic, class_type_or_name, address, static_value_type,
2856
+ local_buffer);
2821
2857
else if (type_info.AnySet (eTypeIsPack))
2822
2858
success = GetDynamicTypeAndAddress_Pack (in_value, val_type, use_dynamic,
2823
2859
class_type_or_name, address,
@@ -2826,7 +2862,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2826
2862
type_info.AllSet (eTypeIsBuiltIn | eTypeIsPointer | eTypeHasValue))
2827
2863
success = GetDynamicTypeAndAddress_Class (in_value, val_type, use_dynamic,
2828
2864
class_type_or_name, address,
2829
- static_value_type);
2865
+ static_value_type, local_buffer );
2830
2866
else if (type_info.AllSet (eTypeIsMetatype | eTypeIsProtocol))
2831
2867
success = GetDynamicTypeAndAddress_ExistentialMetatype (
2832
2868
in_value, val_type, use_dynamic, class_type_or_name, address);
@@ -2850,16 +2886,16 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2850
2886
2851
2887
Flags subst_type_info (bound_type.GetTypeInfo ());
2852
2888
if (subst_type_info.AnySet (eTypeIsClass)) {
2853
- success = GetDynamicTypeAndAddress_Class (in_value, bound_type,
2854
- use_dynamic, class_type_or_name,
2855
- address, static_value_type );
2889
+ success = GetDynamicTypeAndAddress_Class (
2890
+ in_value, bound_type, use_dynamic, class_type_or_name, address ,
2891
+ static_value_type, local_buffer );
2856
2892
} else if (subst_type_info.AnySet (eTypeIsProtocol)) {
2857
2893
success = GetDynamicTypeAndAddress_Existential (
2858
2894
in_value, bound_type, use_dynamic, class_type_or_name, address);
2859
2895
} else {
2860
- success = GetDynamicTypeAndAddress_Value (in_value, bound_type,
2861
- use_dynamic, class_type_or_name,
2862
- address, static_value_type );
2896
+ success = GetDynamicTypeAndAddress_Value (
2897
+ in_value, bound_type, use_dynamic, class_type_or_name, address ,
2898
+ static_value_type, local_buffer );
2863
2899
}
2864
2900
}
2865
2901
@@ -2869,8 +2905,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2869
2905
if (static_value_type == Value::ValueType::Invalid)
2870
2906
static_value_type = in_value.GetValue ().GetValueType ();
2871
2907
2872
- value_type = GetValueType (in_value, class_type_or_name.GetCompilerType (),
2873
- static_value_type, is_indirect_enum_case);
2908
+ value_type =
2909
+ GetValueType (in_value, class_type_or_name.GetCompilerType (),
2910
+ static_value_type, is_indirect_enum_case, local_buffer);
2874
2911
}
2875
2912
return success;
2876
2913
}
0 commit comments