Skip to content

[Debug] Handle AnyObject.Protocol in stringForPrintObject(_:mangledTypeName:)#90032

Open
kastiglione wants to merge 2 commits into
release/6.4.xfrom
dl/Debug-Handle-AnyObject-mangled-name-in-stringForPrintObject-_-mangledTypeName
Open

[Debug] Handle AnyObject.Protocol in stringForPrintObject(_:mangledTypeName:)#90032
kastiglione wants to merge 2 commits into
release/6.4.xfrom
dl/Debug-Handle-AnyObject-mangled-name-in-stringForPrintObject-_-mangledTypeName

Conversation

@kastiglione

@kastiglione kastiglione commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Update stringForPrintObject(_:mangledTypeName:) to support mangled type name for AnyObject ("yXlD"). Handle this by adding a second type is AnyObject.Protocol condition to the branch that bitcasts to AnyObject.

AnyObject is used by LLDB as a fallback when the dynamic type's mangled name contains a private class discriminator, which is not resolved by the Swift runtime.

Assisted-by: claude

…edTypeName:)

The mangled type name for `AnyObject` (s9AnyObjectaD) cannot be resolved by
`_getTypeByMangledNameInContext`. Handle this early and bitcasting the pointer to
`AnyObject` directly.

This is used by LLDB as a fallback when the dynamic type's mangled name contains a
private class discriminator, which is not resolved by the Swift runtime.
@kastiglione kastiglione requested a review from a team as a code owner June 17, 2026 22:19
@kastiglione

Copy link
Copy Markdown
Contributor Author

@swift-ci smoke test

@augusto2112 augusto2112 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why _getTypeByMangledNameInContext cannot resolve AnyObject?

@mikeash

mikeash commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

The proper mangled name for AnyObject should be yXl (class-constrained existential with an empty protocol list). I'm not sure where s9AnyObjectaD comes from. We are able to look up yXl:

$ swift -e 'print(_typeByName("yXl")!)'
AnyObject

@kastiglione

Copy link
Copy Markdown
Contributor Author

I'm not sure where s9AnyObjectaD comes from

It's a typealias declared by the stdlib (https://developer.apple.com/documentation/swift/anyobject). I've seen debug info reference both the alias (s9AnyObjectaD), and the builtin (yXlD).

I didn't go with the builtin because, although type lookup succeed, there were downstream failures that made me think I wasn't taking the right path. I'll debug further and find out where and why it fails after type lookup.

@kastiglione

Copy link
Copy Markdown
Contributor Author

Thanks @mikeash, I've updated the code to support yXlD.

@kastiglione kastiglione requested a review from augusto2112 June 18, 2026 19:48
@kastiglione

Copy link
Copy Markdown
Contributor Author

@swift-ci smoke test

@mikeash

mikeash commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Capturing a bit of offline discussion: there's a difference between AnyObject.Type, which indicates a concrete type that conforms to AnyObject (i.e. any class type), and AnyObject.Protocol which indicates the AnyObject type itself. At least I think that's right....

@kastiglione kastiglione changed the title [Debug] Handle AnyObject mangled name in stringForPrintObject(_:mangledTypeName:) [Debug] Handle AnyObject.Protocol in stringForPrintObject(_:mangledTypeName:) Jun 19, 2026
@kastiglione

Copy link
Copy Markdown
Contributor Author

@swift-ci smoke test macOS

@kastiglione

Copy link
Copy Markdown
Contributor Author

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants