Skip to content

[lldb] Add Foundation._NSSwiftTimeZone support #7074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented Jul 11, 2023

_NSSwiftTimeZone is the new Swift implementation of NSTimeZone.

This is tested by TestDataFormatterObjCNSDate.py, where the NSTimeZone summary string tests if run on macOS Sonoma, but with this change they pass.

See #7073 for the infrastructure changes that this depends on.

rdar://108478831

@kastiglione kastiglione changed the base branch from swift/release/5.9 to dl/swift-implemented-objc-classes July 11, 2023 21:59
@kastiglione kastiglione force-pushed the dl/lldb-add-foundation._nsswifttimezone-support branch from 3b74abb to cd909e9 Compare July 11, 2023 22:01
@kastiglione kastiglione reopened this Jul 11, 2023
Comment on lines 110 to 114
lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);

if (!valobj_addr)
return false;

Copy link
Author

Choose a reason for hiding this comment

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

unused code.

@kastiglione kastiglione changed the base branch from dl/swift-implemented-objc-classes to swift/release/5.9 July 11, 2023 22:03
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

kastiglione commented Jul 11, 2023

This depends on #7073. See 89b7e0f90f3829673662e6d7a20a0ec747f936d0 for the changes unique to this PR.

@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione kastiglione force-pushed the dl/lldb-add-foundation._nsswifttimezone-support branch from cd909e9 to 89b7e0f Compare July 12, 2023 02:32
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione kastiglione force-pushed the dl/lldb-add-foundation._nsswifttimezone-support branch from 89b7e0f to 4d1fa0a Compare July 12, 2023 21:59
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione
Copy link
Author

@swift-ci test

Classes implemented in Swift can be exposed to ObjC. For those classes, the ObjC
metadata is incomplete. Specifically, the encoded types of the ivars are incomplete. As
one might expect, the Swift metadata _is_ complete. In such cases, the Swift runtime
should be consulted when determining the dynamic type of a value.

Differential Revision: https://reviews.llvm.org/D152837
@kastiglione kastiglione force-pushed the dl/lldb-add-foundation._nsswifttimezone-support branch from 5848a98 to 2168802 Compare July 19, 2023 21:09
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione kastiglione force-pushed the dl/lldb-add-foundation._nsswifttimezone-support branch from 2168802 to 6875ce8 Compare July 19, 2023 21:23
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test windows

1 similar comment
@kastiglione
Copy link
Author

@swift-ci test windows

};

std::optional<SwiftNominalType> GetSwiftClass(ValueObject &valobj,
AppleObjCRuntime &objc_runtime) {

Choose a reason for hiding this comment

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

There might be one ore two opportunities for comments in this function to explain the algorithm :-)

Copy link
Author

Choose a reason for hiding this comment

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

done

return {};

swift::Demangle::Context ctx;
auto *global = ctx.demangleSymbolAsNode(*swift_symbol);

Choose a reason for hiding this comment

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

No need to do this right away — but for readability this could be a helper in SwiftDemangle.h?

if (auto maybe_swift_class = GetSwiftClass(in_value, *objc_runtime)) {
swift_class = *maybe_swift_class;
std::string type_name =
(llvm::Twine(swift_class.module) + "." + swift_class.identifier).str();

Choose a reason for hiding this comment

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

Is this shorter?

llvm::raw_string_ostream(type_name)<<swift_class.module<<"."<<swift_class.identifier;

Copy link
Author

Choose a reason for hiding this comment

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

unfortunately it's not

std::string remangled;
{
// Create a mangle tree for __C.dyn_name?.
// Create a mangle tree for Swift.Optional<$module.$class>

Choose a reason for hiding this comment

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

This could also be a few helper functions (in a follow-up commit).

@adrian-prantl
Copy link

@swift-ci test windows

2 similar comments
@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione kastiglione force-pushed the dl/lldb-add-foundation._nsswifttimezone-support branch from 6875ce8 to 42c2556 Compare July 20, 2023 16:31
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test windows

@objc classes can be used from ObjC. In those cases, the Swift runtime is used. This
change implements the handling of @objc classes in the Swift language runtime.
`_NSSwiftTimeZone` is the new Swift implementation of `NSTimeZone`.
@kastiglione kastiglione force-pushed the dl/lldb-add-foundation._nsswifttimezone-support branch from 42c2556 to 666003e Compare July 20, 2023 16:34
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test windows

@adrian-prantl adrian-prantl merged commit 5977e12 into swift/release/5.9 Jul 21, 2023
@kastiglione kastiglione deleted the dl/lldb-add-foundation._nsswifttimezone-support branch August 22, 2024 20:37
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