Skip to content

Commit 51415bc

Browse files
committed
only return symbols for read-only sections
1 parent c8b9012 commit 51415bc

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) {
122122
swift::remote::RemoteAbsolutePointer
123123
LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
124124
uint64_t readValue) {
125+
auto isEffectivelyReadOnly = [](SectionSP section) {
126+
if ((section->GetPermissions() & ePermissionsWritable) ==
127+
ePermissionsWritable)
128+
return true;
129+
if (section->GetName() == "__const")
130+
return true;
131+
if (auto segment = section->GetParent())
132+
if (segment->GetName() == "__DATA_CONST")
133+
return true;
134+
return false;
135+
};
136+
125137
// If an address has a symbol, that symbol provides additional useful data to
126138
// MetadataReader. Without the symbol, MetadataReader can derive the symbol
127139
// by loading other parts of reflection metadata, but that work has a cost.
@@ -130,13 +142,14 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
130142
Address addr;
131143
auto &target = m_process.GetTarget();
132144
if (target.ResolveLoadAddress(address.getAddressData(), addr))
133-
if (auto *symbol = addr.CalculateSymbolContextSymbol()) {
134-
auto mangledName = symbol->GetMangled().GetMangledName().GetStringRef();
135-
// MemoryReader requires any this to be a Swift symbol. LLDB can also be
136-
// aware of local symbols, so avoid returning those.
137-
if (swift::Demangle::isSwiftSymbol(mangledName))
138-
return {mangledName, 0};
139-
}
145+
if (isEffectivelyReadOnly(addr.GetSection()))
146+
if (auto *symbol = addr.CalculateSymbolContextSymbol()) {
147+
auto mangledName = symbol->GetMangled().GetMangledName().GetStringRef();
148+
// MemoryReader requires any this to be a Swift symbol. LLDB can also be
149+
// aware of local symbols, so avoid returning those.
150+
if (swift::Demangle::isSwiftSymbol(mangledName))
151+
return {mangledName, 0};
152+
}
140153

141154
// Return the read value as is.
142155
return {"", (int64_t)readValue};

0 commit comments

Comments
 (0)