@@ -3327,8 +3327,16 @@ SwiftLanguageRuntime::MaskMaybeBridgedPointer(lldb::addr_t addr,
33273327}
33283328
33293329lldb::addr_t
3330- SwiftLanguageRuntime::MaybeMaskNonTrivialReferencePointer (lldb::addr_t addr) {
3331- if (auto objc_runtime = GetObjCRuntime ()) {
3330+ SwiftLanguageRuntime::MaybeMaskNonTrivialReferencePointer (
3331+ lldb::addr_t addr,
3332+ SwiftASTContext::NonTriviallyManagedReferenceStrategy strategy) {
3333+
3334+ if (addr == 0 )
3335+ return addr;
3336+
3337+ AppleObjCRuntime *objc_runtime = GetObjCRuntime ();
3338+
3339+ if (objc_runtime) {
33323340 // tagged pointers don't perform any masking
33333341 if (objc_runtime->IsTaggedPointer (addr))
33343342 return addr;
@@ -3372,16 +3380,77 @@ SwiftLanguageRuntime::MaybeMaskNonTrivialReferencePointer(lldb::addr_t addr) {
33723380
33733381 lldb::addr_t mask = 0 ;
33743382
3375- if (is_arm && is_64)
3376- mask = SWIFT_ABI_ARM64_OBJC_NUM_RESERVED_LOW_BITS;
3377- else if (is_intel && is_64)
3378- mask = SWIFT_ABI_X86_64_OBJC_NUM_RESERVED_LOW_BITS;
3379- else
3380- mask = SWIFT_ABI_DEFAULT_OBJC_NUM_RESERVED_LOW_BITS;
3383+ if (strategy == SwiftASTContext::NonTriviallyManagedReferenceStrategy::eWeak) {
3384+ bool is_indirect = true ;
3385+
3386+ // On non-objc platforms, the weak reference pointer always pointed to a
3387+ // runtime structure.
3388+ // For ObjC platforms, the masked value determines whether it is indirect.
3389+
3390+ uint32_t value = 0 ;
3391+
3392+ if (objc_runtime)
3393+ {
3394+
3395+ if (is_intel) {
3396+ if (is_64) {
3397+ mask = SWIFT_ABI_X86_64_OBJC_WEAK_REFERENCE_MARKER_MASK;
3398+ value = SWIFT_ABI_X86_64_OBJC_WEAK_REFERENCE_MARKER_VALUE;
3399+ } else {
3400+ mask = SWIFT_ABI_I386_OBJC_WEAK_REFERENCE_MARKER_MASK;
3401+ value = SWIFT_ABI_I386_OBJC_WEAK_REFERENCE_MARKER_VALUE;
3402+ }
3403+ } else if (is_arm) {
3404+ if (is_64) {
3405+ mask = SWIFT_ABI_ARM64_OBJC_WEAK_REFERENCE_MARKER_MASK;
3406+ value = SWIFT_ABI_ARM64_OBJC_WEAK_REFERENCE_MARKER_VALUE;
3407+ } else {
3408+ mask = SWIFT_ABI_ARM_OBJC_WEAK_REFERENCE_MARKER_MASK;
3409+ value = SWIFT_ABI_ARM_OBJC_WEAK_REFERENCE_MARKER_VALUE;
3410+ }
3411+ }
3412+ } else {
3413+ // This name is a little confusing. The "DEFAULT" marking in System.h
3414+ // is supposed to mean: the value for non-ObjC platforms. So
3415+ // DEFAULT_OBJC here actually means "non-ObjC".
3416+ mask = SWIFT_ABI_DEFAULT_OBJC_WEAK_REFERENCE_MARKER_MASK;
3417+ value = SWIFT_ABI_DEFAULT_OBJC_WEAK_REFERENCE_MARKER_VALUE;
3418+ }
3419+
3420+ is_indirect = ((addr & mask) == value);
3421+
3422+ if (!is_indirect)
3423+ return addr;
3424+
3425+ // The masked value of address is a pointer to the runtime structure.
3426+ // The first field of the structure is the actual pointer.
3427+ Process *process = GetProcess ();
3428+ Error error;
3429+
3430+ lldb::addr_t masked_addr = addr & ~mask;
3431+ lldb::addr_t isa_addr = process->ReadPointerFromMemory (masked_addr, error);
3432+ if (error.Fail ())
3433+ {
3434+ // FIXME: do some logging here.
3435+ return addr;
3436+ }
3437+ return isa_addr;
3438+
3439+
3440+ } else {
3441+ if (is_arm && is_64)
3442+ mask = SWIFT_ABI_ARM64_OBJC_NUM_RESERVED_LOW_BITS;
3443+ else if (is_intel && is_64)
3444+ mask = SWIFT_ABI_X86_64_OBJC_NUM_RESERVED_LOW_BITS;
3445+ else
3446+ mask = SWIFT_ABI_DEFAULT_OBJC_NUM_RESERVED_LOW_BITS;
33813447
3382- mask = (1 << mask) | (1 << (mask + 1 ));
3448+ mask = (1 << mask) | (1 << (mask + 1 ));
33833449
3384- return addr & ~mask;
3450+ return addr & ~mask;
3451+ }
3452+
3453+ return addr;
33853454}
33863455
33873456ConstString SwiftLanguageRuntime::GetErrorBackstopName () {
0 commit comments