@@ -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 {
@@ -2436,17 +2438,41 @@ bool SwiftLanguageRuntime::GetAbstractTypeName(StreamString &name,
2436
2438
bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Value (
2437
2439
ValueObject &in_value, CompilerType &bound_type,
2438
2440
lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name,
2439
- Address &address, Value::ValueType &value_type) {
2441
+ Address &address, Value::ValueType &value_type,
2442
+ llvm::ArrayRef<uint8_t > &local_buffer) {
2443
+ auto static_type = in_value.GetCompilerType ();
2440
2444
value_type = Value::ValueType::Invalid;
2441
2445
class_type_or_name.SetCompilerType (bound_type);
2442
2446
2443
2447
ExecutionContext exe_ctx = in_value.GetExecutionContextRef ().Lock (true );
2448
+ ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope ();
2449
+ if (!exe_scope)
2450
+ return false ;
2444
2451
std::optional<uint64_t > size =
2445
2452
bound_type.GetByteSize (exe_ctx.GetBestExecutionContextScope ());
2446
2453
if (!size)
2447
2454
return false ;
2448
2455
AddressType address_type;
2449
2456
lldb::addr_t val_address = in_value.GetAddressOf (true , &address_type);
2457
+ // If we couldn't find a load address, but the value object has a local
2458
+ // buffer, use that.
2459
+ if (val_address == LLDB_INVALID_ADDRESS && address_type == eAddressTypeHost) {
2460
+ // Get the start and size of the local buffer.
2461
+ auto start = in_value.GetValue ().GetScalar ().ULongLong ();
2462
+ auto local_buffer_size = in_value.GetLocalBufferSize ();
2463
+
2464
+ // If we can't find the size of the local buffer we can't safely know if the
2465
+ // dynamic type fits in it.
2466
+ if (local_buffer_size == LLDB_INVALID_ADDRESS)
2467
+ return false ;
2468
+ // If the dynamic type doesn't in the buffer we can't use it either.
2469
+ if (local_buffer_size < bound_type.GetByteSize (exe_scope))
2470
+ return false ;
2471
+
2472
+ value_type = Value::GetValueTypeFromAddressType (address_type);
2473
+ local_buffer = {(uint8_t *)start, local_buffer_size};
2474
+ return true ;
2475
+ }
2450
2476
if (*size && (!val_address || val_address == LLDB_INVALID_ADDRESS))
2451
2477
return false ;
2452
2478
@@ -2458,7 +2484,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Value(
2458
2484
bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_IndirectEnumCase (
2459
2485
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
2460
2486
TypeAndOrName &class_type_or_name, Address &address,
2461
- Value::ValueType &value_type) {
2487
+ Value::ValueType &value_type, llvm::ArrayRef< uint8_t > &local_buffer ) {
2462
2488
Status error;
2463
2489
CompilerType child_type = in_value.GetCompilerType ();
2464
2490
class_type_or_name.SetCompilerType (child_type);
@@ -2490,7 +2516,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_IndirectEnumCase(
2490
2516
return false ;
2491
2517
2492
2518
return GetDynamicTypeAndAddress (*valobj_sp, use_dynamic, class_type_or_name,
2493
- address, value_type);
2519
+ address, value_type, local_buffer );
2494
2520
} else {
2495
2521
// This is most likely a statically known type.
2496
2522
address.SetLoadAddress (box_value, &GetProcess ().GetTarget ());
@@ -2516,7 +2542,8 @@ void SwiftLanguageRuntime::DumpTyperef(CompilerType type,
2516
2542
2517
2543
Value::ValueType SwiftLanguageRuntime::GetValueType (
2518
2544
ValueObject &in_value, CompilerType dynamic_type,
2519
- Value::ValueType static_value_type, bool is_indirect_enum_case) {
2545
+ Value::ValueType static_value_type, bool is_indirect_enum_case,
2546
+ llvm::ArrayRef<uint8_t > &local_buffer) {
2520
2547
CompilerType static_type = in_value.GetCompilerType ();
2521
2548
Flags static_type_flags (static_type.GetTypeInfo ());
2522
2549
Flags dynamic_type_flags (dynamic_type.GetTypeInfo ());
@@ -2570,6 +2597,12 @@ Value::ValueType SwiftLanguageRuntime::GetValueType(
2570
2597
// If the data is not inlined, we have a pointer.
2571
2598
return Value::ValueType::LoadAddress;
2572
2599
}
2600
+ // If we found a host address and the dynamic type fits in there, and
2601
+ // this is not a pointer from an existential container, then this points to
2602
+ // the local buffer.
2603
+ if (static_value_type == Value::ValueType::HostAddress &&
2604
+ !local_buffer.empty ())
2605
+ return static_value_type;
2573
2606
2574
2607
if (static_type_flags.AllSet (eTypeIsSwift | eTypeIsGenericTypeParam)) {
2575
2608
// if I am handling a non-pointer Swift type obtained from an archetype,
@@ -2677,7 +2710,7 @@ std::optional<SwiftNominalType> GetSwiftClass(ValueObject &valobj,
2677
2710
bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_ClangType (
2678
2711
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
2679
2712
TypeAndOrName &class_type_or_name, Address &address,
2680
- Value::ValueType &value_type) {
2713
+ Value::ValueType &value_type, llvm::ArrayRef< uint8_t > &local_buffer ) {
2681
2714
AppleObjCRuntime *objc_runtime =
2682
2715
SwiftLanguageRuntime::GetObjCRuntime (GetProcess ());
2683
2716
if (!objc_runtime)
@@ -2690,8 +2723,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_ClangType(
2690
2723
// resolution first, and then map the dynamic Objective-C type back
2691
2724
// into Swift.
2692
2725
TypeAndOrName dyn_class_type_or_name = class_type_or_name;
2693
- if (!objc_runtime->GetDynamicTypeAndAddress (
2694
- in_value, use_dynamic, dyn_class_type_or_name, address, value_type))
2726
+ if (!objc_runtime->GetDynamicTypeAndAddress (in_value, use_dynamic,
2727
+ dyn_class_type_or_name, address,
2728
+ value_type, local_buffer))
2695
2729
return false ;
2696
2730
2697
2731
StringRef dyn_name = dyn_class_type_or_name.GetName ().GetStringRef ();
@@ -2797,7 +2831,7 @@ static bool CouldHaveDynamicValue(ValueObject &in_value) {
2797
2831
bool SwiftLanguageRuntime::GetDynamicTypeAndAddress (
2798
2832
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
2799
2833
TypeAndOrName &class_type_or_name, Address &address,
2800
- Value::ValueType &value_type) {
2834
+ Value::ValueType &value_type, llvm::ArrayRef< uint8_t > &local_buffer ) {
2801
2835
class_type_or_name.Clear ();
2802
2836
if (use_dynamic == lldb::eNoDynamicValues)
2803
2837
return false ;
@@ -2806,8 +2840,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2806
2840
2807
2841
// Try to import a Clang type into Swift.
2808
2842
if (in_value.GetObjectRuntimeLanguage () == eLanguageTypeObjC)
2809
- return GetDynamicTypeAndAddress_ClangType (
2810
- in_value, use_dynamic, class_type_or_name, address, value_type);
2843
+ return GetDynamicTypeAndAddress_ClangType (in_value, use_dynamic,
2844
+ class_type_or_name, address,
2845
+ value_type, local_buffer);
2811
2846
2812
2847
if (!CouldHaveDynamicValue (in_value))
2813
2848
return false ;
@@ -2823,7 +2858,8 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2823
2858
// Type kinds with instance metadata don't need generic type resolution.
2824
2859
if (is_indirect_enum_case)
2825
2860
success = GetDynamicTypeAndAddress_IndirectEnumCase (
2826
- in_value, use_dynamic, class_type_or_name, address, static_value_type);
2861
+ in_value, use_dynamic, class_type_or_name, address, static_value_type,
2862
+ local_buffer);
2827
2863
else if (type_info.AnySet (eTypeIsPack))
2828
2864
success = GetDynamicTypeAndAddress_Pack (in_value, val_type, use_dynamic,
2829
2865
class_type_or_name, address,
@@ -2832,7 +2868,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2832
2868
type_info.AllSet (eTypeIsBuiltIn | eTypeIsPointer | eTypeHasValue))
2833
2869
success = GetDynamicTypeAndAddress_Class (in_value, val_type, use_dynamic,
2834
2870
class_type_or_name, address,
2835
- static_value_type);
2871
+ static_value_type, local_buffer );
2836
2872
else if (type_info.AllSet (eTypeIsMetatype | eTypeIsProtocol))
2837
2873
success = GetDynamicTypeAndAddress_ExistentialMetatype (
2838
2874
in_value, val_type, use_dynamic, class_type_or_name, address);
@@ -2856,16 +2892,16 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2856
2892
2857
2893
Flags subst_type_info (bound_type.GetTypeInfo ());
2858
2894
if (subst_type_info.AnySet (eTypeIsClass)) {
2859
- success = GetDynamicTypeAndAddress_Class (in_value, bound_type,
2860
- use_dynamic, class_type_or_name,
2861
- address, static_value_type );
2895
+ success = GetDynamicTypeAndAddress_Class (
2896
+ in_value, bound_type, use_dynamic, class_type_or_name, address ,
2897
+ static_value_type, local_buffer );
2862
2898
} else if (subst_type_info.AnySet (eTypeIsProtocol)) {
2863
2899
success = GetDynamicTypeAndAddress_Existential (
2864
2900
in_value, bound_type, use_dynamic, class_type_or_name, address);
2865
2901
} else {
2866
- success = GetDynamicTypeAndAddress_Value (in_value, bound_type,
2867
- use_dynamic, class_type_or_name,
2868
- address, static_value_type );
2902
+ success = GetDynamicTypeAndAddress_Value (
2903
+ in_value, bound_type, use_dynamic, class_type_or_name, address ,
2904
+ static_value_type, local_buffer );
2869
2905
}
2870
2906
}
2871
2907
@@ -2875,8 +2911,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
2875
2911
if (static_value_type == Value::ValueType::Invalid)
2876
2912
static_value_type = in_value.GetValue ().GetValueType ();
2877
2913
2878
- value_type = GetValueType (in_value, class_type_or_name.GetCompilerType (),
2879
- static_value_type, is_indirect_enum_case);
2914
+ value_type =
2915
+ GetValueType (in_value, class_type_or_name.GetCompilerType (),
2916
+ static_value_type, is_indirect_enum_case, local_buffer);
2880
2917
}
2881
2918
return success;
2882
2919
}
0 commit comments