Skip to content

[lldb] Make LLDBMemoryReader::resolvePointer strip the pointer #4958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
if (!readMetadataFromFileCacheEnabled())
return process_pointer;

// Try to strip the pointer before checking if we have it mapped.
auto strippedPointer = signedPointerStripper(process_pointer);
if (strippedPointer.isResolved())
readValue = strippedPointer.getOffset();

auto &target = m_process.GetTarget();
Address addr;
if (!target.ResolveLoadAddress(readValue, addr)) {
Expand Down
12 changes: 10 additions & 2 deletions lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
namespace lldb_private {
class LLDBMemoryReader : public swift::remote::MemoryReader {
public:
LLDBMemoryReader(Process &p, size_t max_read_amount = INT32_MAX)
: m_process(p), m_range_module_map() {
LLDBMemoryReader(Process &p,
std::function<swift::remote::RemoteAbsolutePointer(
swift::remote::RemoteAbsolutePointer)>
stripper,
size_t max_read_amount = INT32_MAX)
: m_process(p), signedPointerStripper(stripper), m_range_module_map() {
m_max_read_amount = max_read_amount;
}

Expand Down Expand Up @@ -84,6 +88,10 @@ llvm::Optional<Address> resolveRemoteAddressFromSymbolObjectFile(uint64_t addres
llvm::Optional<uint64_t> m_local_buffer;
uint64_t m_local_buffer_size = 0;

std::function<swift::remote::RemoteAbsolutePointer(
swift::remote::RemoteAbsolutePointer)>
signedPointerStripper;

/// LLDBMemoryReader prefers to read reflection metadata from the
/// binary on disk, which is faster than reading it out of process
/// memory, especially when debugging remotely. To achieve this LLDB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ class TargetReflectionContext
return m_reflection_ctx.isValueInlinedInExistentialContainer(
existential_address);
}

swift::remote::RemoteAbsolutePointer
stripSignedPointer(swift::remote::RemoteAbsolutePointer pointer) override {
return m_reflection_ctx.stripSignedPointer(pointer);
}
};

} // namespace
Expand Down Expand Up @@ -406,8 +411,13 @@ const CompilerType &SwiftLanguageRuntimeImpl::GetBoxMetadataType() {

std::shared_ptr<LLDBMemoryReader>
SwiftLanguageRuntimeImpl::GetMemoryReader() {
if (!m_memory_reader_sp)
m_memory_reader_sp.reset(new LLDBMemoryReader(m_process));
if (!m_memory_reader_sp) {
m_memory_reader_sp.reset(new LLDBMemoryReader(
m_process, [&](swift::remote::RemoteAbsolutePointer pointer) {
auto *reflection_context = GetReflectionContext();
return reflection_context->stripSignedPointer(pointer);
}));
}

return m_memory_reader_sp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class SwiftLanguageRuntimeImpl {
virtual swift::reflection::TypeRefBuilder &getBuilder() = 0;
virtual llvm::Optional<bool> isValueInlinedInExistentialContainer(
swift::remote::RemoteAddress existential_address) = 0;
virtual swift::remote::RemoteAbsolutePointer
stripSignedPointer(swift::remote::RemoteAbsolutePointer pointer) = 0;
};

protected:
Expand Down