@@ -122,6 +122,18 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) {
122
122
swift::remote::RemoteAbsolutePointer
123
123
LLDBMemoryReader::resolvePointer (swift::remote::RemoteAddress address,
124
124
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
+
125
137
// If an address has a symbol, that symbol provides additional useful data to
126
138
// MetadataReader. Without the symbol, MetadataReader can derive the symbol
127
139
// by loading other parts of reflection metadata, but that work has a cost.
@@ -130,13 +142,14 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
130
142
Address addr;
131
143
auto &target = m_process.GetTarget ();
132
144
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
+ }
140
153
141
154
// Return the read value as is.
142
155
return {" " , (int64_t )readValue};
0 commit comments