From 540df142d718294bdde44ca72a17d40ecbd0a4fb Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 6 Jun 2025 15:10:15 -0700 Subject: [PATCH] [RemoteInspection] Add a hook to process addresses before converting them to hex strings when creating anonymous context descriptors. This aims to solve a problem when LLDB reads reflection metadata directly from local binary files instead of downloading them from in-process memory. LLDB's MemoryReader implements this to convert the file address into an in-process address, so mangled names created from instance metadata can be matched with the field info data read from the local files. rdar://152743797 --- include/swift/Remote/MemoryReader.h | 7 +++++++ include/swift/Remote/MetadataReader.h | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/swift/Remote/MemoryReader.h b/include/swift/Remote/MemoryReader.h index 1008650b43990..7e077a5f7d068 100644 --- a/include/swift/Remote/MemoryReader.h +++ b/include/swift/Remote/MemoryReader.h @@ -150,6 +150,13 @@ class MemoryReader { return RemoteAbsolutePointer("", readValue); } + /// Performs the inverse operation of \ref resolvePointer. + /// A use-case for this is to turn file addresses into in-process addresses. + virtual std::optional + resolveRemoteAddress(RemoteAddress address) const { + return std::nullopt; + } + virtual std::optional resolvePointerAsSymbol(RemoteAddress address) { return std::nullopt; diff --git a/include/swift/Remote/MetadataReader.h b/include/swift/Remote/MetadataReader.h index 262368e9f4a2b..a7d9485e6ad03 100644 --- a/include/swift/Remote/MetadataReader.h +++ b/include/swift/Remote/MetadataReader.h @@ -2907,8 +2907,10 @@ class MetadataReader { case ContextDescriptorKind::Anonymous: { // Use the remote address to identify the anonymous context. char addressBuf[18]; + RemoteAddress address(descriptor.getAddressData()); + address = Reader->resolveRemoteAddress(address).value_or(address); snprintf(addressBuf, sizeof(addressBuf), "$%" PRIx64, - (uint64_t)descriptor.getAddressData()); + (uint64_t)address.getAddressData()); auto anonNode = dem.createNode(Node::Kind::AnonymousContext); CharVector addressStr; addressStr.append(addressBuf, dem);