Skip to content

Commit c8b9012

Browse files
committed
[lldb] Implement LLDBMemoryReader::resolvePointer
1 parent 1e62148 commit c8b9012

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "LLDBMemoryReader.h"
2+
#include "lldb/Core/Address.h"
23
#include "lldb/Core/Section.h"
34
#include "lldb/Utility/Log.h"
45
#include "lldb/Utility/Logging.h"
6+
#include "swift/Demangling/Demangle.h"
57

68
#include "llvm/Support/MathExtras.h"
79

@@ -117,6 +119,29 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) {
117119
return swift::remote::RemoteAddress(load_addr);
118120
}
119121

122+
swift::remote::RemoteAbsolutePointer
123+
LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
124+
uint64_t readValue) {
125+
// If an address has a symbol, that symbol provides additional useful data to
126+
// MetadataReader. Without the symbol, MetadataReader can derive the symbol
127+
// by loading other parts of reflection metadata, but that work has a cost.
128+
// For lldb, that data loading can be a significant performance hit. Providing
129+
// a symbol greatly reduces memory read traffic to the process.
130+
Address addr;
131+
auto &target = m_process.GetTarget();
132+
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+
}
140+
141+
// Return the read value as is.
142+
return {"", (int64_t)readValue};
143+
}
144+
120145
bool LLDBMemoryReader::readBytes(swift::remote::RemoteAddress address,
121146
uint8_t *dest, uint64_t size) {
122147
if (m_local_buffer) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class LLDBMemoryReader : public swift::remote::MemoryReader {
2323
swift::remote::RemoteAddress
2424
getSymbolAddress(const std::string &name) override;
2525

26+
swift::remote::RemoteAbsolutePointer
27+
resolvePointer(swift::remote::RemoteAddress address,
28+
uint64_t readValue) override;
29+
2630
bool readBytes(swift::remote::RemoteAddress address, uint8_t *dest,
2731
uint64_t size) override;
2832

0 commit comments

Comments
 (0)