Skip to content

[NFC][lldb] Adapt LLDB to RemoteInspection's RemoteAddress changes #10928

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

Merged

Conversation

augusto2112
Copy link

@augusto2112 augusto2112 commented Jun 30, 2025

Adapts LLDB to the new field in RemoteAddress. This is an NFC that
maintains the current behavior. A follow up patch will be introduced
later that takes advantage of the new behavior to fix a bug in reading
metadata from files instead of the process.

rdar://148361743

@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

@augusto2112 augusto2112 requested a review from adrian-prantl July 1, 2025 20:14
@augusto2112 augusto2112 force-pushed the change-remote-addr branch 2 times, most recently from 10ccd54 to 7ebf13b Compare July 4, 2025 00:13
@augusto2112 augusto2112 changed the title [DRAFT][lldb] Replace StoredPointer with RemoteAddress [NFC][lldb] Adapt LLDB to RemoteInspection's RemoteAddress changes Jul 4, 2025
@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

@augusto2112 augusto2112 marked this pull request as ready for review July 4, 2025 04:48
@augusto2112 augusto2112 requested a review from a team as a code owner July 4, 2025 04:48
@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

1 similar comment
@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

Comment on lines +122 to +123
auto address = swift::remote::RemoteAddress(
pointer, swift::remote::RemoteAddress::DefaultAddressSpace);

Choose a reason for hiding this comment

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

could the second parameter have a default value of swift::remote::RemoteAddress::DefaultAddressSpace? The name does suggest it.

Choose a reason for hiding this comment

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

partially related: a few of the RemoteAddress constructors in this patch use a literal zero instead of DefaultAddressSpace, what's the reason for that?

Copy link
Author

Choose a reason for hiding this comment

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

could the second parameter have a default value of swift::remote::RemoteAddress::DefaultAddressSpace?

I was thinking about making it a default constructor, but I think we want to make it explicit that the address space is something that they think about. I'm worried that if someone updates code in the remote inspection library that grabs the address data from a remote address, threads it to some function, and then builds a new RemoteAddress, they may accidentally change the address space. This pattern of RemoteAddress -> StoredPointer -> RemoteAddress is pretty common, so I want to make it harder to make this mistake.

partially related: a few of the RemoteAddress constructors in this patch use a literal zero instead of DefaultAddressSpace, what's the reason for that?

I just forgot to update those to use the DefaultAddressSpace after I introduced it.

Choose a reason for hiding this comment

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

grabs the address data from a remote address, threads it to some function, and then builds a new RemoteAddress, they may accidentally change the address space. This pattern of RemoteAddress -> StoredPointer -> RemoteAddress is pretty common, so I want to make it harder to make this mistake.

is there a way to provide a safe way of doing this? for example:

auto updatedAddr = originalAddr.map([](StoredPointer rawPtr) {
    // do stuff
    return newPtr;
});

Copy link

@kastiglione kastiglione Jul 8, 2025

Choose a reason for hiding this comment

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

I think my main issue is the repetitiveness combined with the same value. Despite it being explicit, I could see the default being accidentally used via copy and paste, muscle memory, or LLM generated code.

Copy link
Author

Choose a reason for hiding this comment

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

I originally had a fromThis method on RemoteAddress that would construct a new address and preserve its address space, but Adrian suggested that that was too opaque and not explicit enough. After refactoring, I agree with him.

Another common case that I didn't mention is reading some memory and constructing a new address out of one of its fields. Something like:

auto someMetadata = Reader->readSomeMetadata(address);
RemoteAddress newAddress(someMetadata->Field, address.getAddressData());

I don't think this is clearer using a map API:

auto newAddress = address.map([](StoredPointer) {
  auto someMetadata = Reader->readSomeMetadata(address);
  return someMetata->Field;
};

Even if we did adopt such an API, I still think it'd be dangerous to leave the constructor defaulting the address space to the default address space, I think the first thing people would look for when trying to build a new address is its constructor, and they might ignore alternative methods of building the type, and most likely would just write it as:

auto someMetadata = Reader->readSomeMetadata(address);
RemoteAddress newAddress(someMetadata->Field);

Comment on lines 469 to 473
if (pointerSize == 4) {
uint32_t ptrauthMask32 = 0;
if (queryDataLayout(DataLayoutQueryType::DLQ_GetPtrAuthMask, nullptr,
&ptrauthMask32))
return (uint64_t)ptrauthMask32;

Choose a reason for hiding this comment

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

does ptr auth exist for 4 byte pointer systems?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, apparently they can.

Copy link

@kastiglione kastiglione Jul 8, 2025

Choose a reason for hiding this comment

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

it doesn't have to be part of this PR, but this code makes me think the query API of DLQ_GetPtrAuthMask should be always uint64_t, regardless of pointer size. It makes code like this more direct, since no call to DLQ_GetPointerSize would be needed. For pointer size of 4, the top 4 bytes of the returned value will always be zero and any code that is specific to 32bit can convert as necessary.

@augusto2112 augusto2112 force-pushed the change-remote-addr branch from 7ebf13b to 1bb80ea Compare July 8, 2025 20:04
@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

@augusto2112 augusto2112 force-pushed the change-remote-addr branch from 1bb80ea to ec05631 Compare July 9, 2025 00:15
@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

@augusto2112 augusto2112 force-pushed the change-remote-addr branch from ec05631 to bd192c3 Compare July 9, 2025 19:48
@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

@augusto2112 augusto2112 force-pushed the change-remote-addr branch from bd192c3 to 1cc02a4 Compare July 9, 2025 21:53
@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

@augusto2112 augusto2112 force-pushed the change-remote-addr branch from 1cc02a4 to 22004c0 Compare July 9, 2025 21:54
@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

Adapts LLDB to the new field in RemoteAddress. This is an NFC that
maintains the current behavior. A follow up patch will be introduced
later that takes advantage of the new behavior to fix a bug in reading
metadata from files instead of the process.

rdar://148361743
@augusto2112
Copy link
Author

swiftlang/swift#82638
@swift-ci test

@augusto2112
Copy link
Author

@swift-ci test

@nate-chandler nate-chandler merged commit 56bd1dd into swiftlang:stable/20240723 Jul 10, 2025
0 of 3 checks passed
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