From eeae558b86b49b0a3868933cb3d9a8e9383670d6 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Fri, 5 Dec 2025 17:02:34 -0800 Subject: [PATCH 1/2] [RemoteInspection] Read ContextDescriptor from symbol if available If the MemoryReader can provide a symbol for the context descriptor, use that instead of building the mangle tree from metadata. This shouldn't hurt other clients, and would have a few benefits for LLDB: - Small but numerous memory reads can be expensive for LLDB, building the mangle tree from a string should be much faster. - For types with private discriminators, this allows LLDB to provide the same private discriminator that's in DWARF and in the swiftmodule (as opposed to using the memory address where the context descriptor lives at). This means that these private types would have the same mangled name in every run. LLDB persistently caches field descriptors by name, but since private discriminators aren't guaranteed to have the same mangled name over multiple runs, LLDB would often need to invalidate its entire cache and rebuild it. Using the stable UUID would solve that issue. rdar://165950673 (cherry picked from commit e3c67c905acdeab42681d4b2eb5b76c9f809d8c1) --- include/swift/Remote/MetadataReader.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/swift/Remote/MetadataReader.h b/include/swift/Remote/MetadataReader.h index 59b9ba031c295..256eaa111a75f 100644 --- a/include/swift/Remote/MetadataReader.h +++ b/include/swift/Remote/MetadataReader.h @@ -2690,6 +2690,18 @@ class MetadataReader { return nullptr; } + // Check if the Reader can provide a symbol for this descriptor, and if it + // can, use that instead. + if (auto remoteAbsolutePointer = + Reader->resolvePointerAsSymbol(descriptor.getRemoteAddress())) { + auto symbol = remoteAbsolutePointer->getSymbol(); + if (!symbol.empty()) { + if (auto demangledSymbol = buildContextManglingForSymbol(symbol, dem)) { + return demangledSymbol; + } + } + } + // Read the parent descriptor. auto parentDescriptorResult = readParentContextDescriptor(descriptor); From 9d2a0f5b6be3a0649800606c84e2b675be06c2f1 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Mon, 8 Dec 2025 14:35:11 -0800 Subject: [PATCH 2/2] [RemoteInspection] Factor out buildContextDescriptorManglingForSymbol A previous commit introduced the usage of buildContextManglingForSymbol in buildContextDescriptorMangling, which was not quite correct, since type nodes needed extra handling, which was done in the other version of buildContextDescriptorMangling. This patch factors out the handling of building context descriptors mangling from symbols, and updates both call sites to use the new function instead. rdar://165950673 (cherry picked from commit ab507becb45d08ef66a2c0547b8f9ad2a6b2b668) --- include/swift/Remote/MetadataReader.h | 32 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/include/swift/Remote/MetadataReader.h b/include/swift/Remote/MetadataReader.h index 256eaa111a75f..b5b99b8befe59 100644 --- a/include/swift/Remote/MetadataReader.h +++ b/include/swift/Remote/MetadataReader.h @@ -2659,6 +2659,26 @@ class MetadataReader { return resultAddress; } + Demangle::NodePointer + buildContextDescriptorManglingForSymbol(llvm::StringRef symbol, + Demangler &dem) { + if (auto demangledSymbol = buildContextManglingForSymbol(symbol, dem)) { + // Look through Type nodes since we're building up a mangling here. + if (demangledSymbol->getKind() == Demangle::Node::Kind::Type) { + demangledSymbol = demangledSymbol->getChild(0); + } + return demangledSymbol; + } + + return nullptr; + } + + Demangle::NodePointer + buildContextDescriptorManglingForSymbol(const std::string &symbol, + Demangler &dem) { + return buildContextDescriptorManglingForSymbol(dem.copyString(symbol), dem); + } + Demangle::NodePointer buildContextDescriptorMangling(const ParentContextDescriptorRef &descriptor, Demangler &dem, int recursion_limit) { @@ -2672,15 +2692,7 @@ class MetadataReader { // Try to demangle the symbol name to figure out what context it would // point to. - auto demangledSymbol = buildContextManglingForSymbol(descriptor.getSymbol(), - dem); - if (!demangledSymbol) - return nullptr; - // Look through Type notes since we're building up a mangling here. - if (demangledSymbol->getKind() == Demangle::Node::Kind::Type){ - demangledSymbol = demangledSymbol->getChild(0); - } - return demangledSymbol; + return buildContextDescriptorManglingForSymbol(descriptor.getSymbol(), dem); } Demangle::NodePointer @@ -2696,7 +2708,7 @@ class MetadataReader { Reader->resolvePointerAsSymbol(descriptor.getRemoteAddress())) { auto symbol = remoteAbsolutePointer->getSymbol(); if (!symbol.empty()) { - if (auto demangledSymbol = buildContextManglingForSymbol(symbol, dem)) { + if (auto demangledSymbol = buildContextDescriptorManglingForSymbol(symbol, dem)) { return demangledSymbol; } }