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