|
1 | 1 | #include "LLDBMemoryReader.h"
|
| 2 | +#include "lldb/Core/Address.h" |
2 | 3 | #include "lldb/Core/Section.h"
|
3 | 4 | #include "lldb/Utility/Log.h"
|
4 | 5 | #include "lldb/Utility/Logging.h"
|
| 6 | +#include "swift/Demangling/Demangle.h" |
5 | 7 |
|
6 | 8 | #include "llvm/Support/MathExtras.h"
|
7 | 9 |
|
@@ -117,6 +119,29 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) {
|
117 | 119 | return swift::remote::RemoteAddress(load_addr);
|
118 | 120 | }
|
119 | 121 |
|
| 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 | + |
120 | 145 | bool LLDBMemoryReader::readBytes(swift::remote::RemoteAddress address,
|
121 | 146 | uint8_t *dest, uint64_t size) {
|
122 | 147 | if (m_local_buffer) {
|
|
0 commit comments