mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[RemoteMirrors] Add hook for resolving indirect addresses
Adds a hook so implementations of memory reader can add logic to resolving remote addresses. This is needed because of an interaction between LLDB, which tries to read memory from files instead of process memory whenever possible and the DYLD shared cache. The shared cache will merge pointers in the GOT sections from multiple images into one location, and update the relative offsets to point to the new location. LLDB, will have initially read the offset pointing to the "old" location, which will be zeroed out in live memory. This gives LLDB the opportunity to re-read the relative offset, but from live memory, so it can return the right pointer in the shared cache. (cherry picked from commit 0f4a3ceb67a3669cd5433d5ae13fec6852876173) rdar://163652093
This commit is contained in:
@@ -121,6 +121,20 @@ public:
|
|||||||
return ReadObjResult<T>(reinterpret_cast<const T *>(ptr), deleter);
|
return ReadObjResult<T>(reinterpret_cast<const T *>(ptr), deleter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolves an indirect address at the given relative offset.
|
||||||
|
///
|
||||||
|
/// \param address The base address which contains the relative offset.
|
||||||
|
/// \param offset The offset read.
|
||||||
|
/// \param directnessEncodedInOffset Whether the relative offset encodes the
|
||||||
|
/// directness as the last bit. Note that this is not the offset passed in as
|
||||||
|
/// a parameter, but whether the offset read at address would have the last
|
||||||
|
/// bit set.
|
||||||
|
virtual RemoteAddress
|
||||||
|
resolveIndirectAddressAtOffset(RemoteAddress address, uint64_t offset,
|
||||||
|
bool directnessEncodedInOffset) {
|
||||||
|
return address + offset;
|
||||||
|
}
|
||||||
|
|
||||||
/// Attempts to read 'size' bytes from the given address in the remote process.
|
/// Attempts to read 'size' bytes from the given address in the remote process.
|
||||||
///
|
///
|
||||||
/// Returns a pointer to the requested data and a function that must be called to
|
/// Returns a pointer to the requested data and a function that must be called to
|
||||||
|
|||||||
@@ -461,18 +461,20 @@ public:
|
|||||||
swift::Demangle::NodePointer {
|
swift::Demangle::NodePointer {
|
||||||
// Resolve the reference to a remote address.
|
// Resolve the reference to a remote address.
|
||||||
auto offsetInMangledName =
|
auto offsetInMangledName =
|
||||||
(const char *)base - mangledName.getLocalBuffer();
|
(const char *)base - mangledName.getLocalBuffer();
|
||||||
auto remoteAddress =
|
auto offsetAddress = mangledName.getRemoteAddress() + offsetInMangledName;
|
||||||
mangledName.getRemoteAddress() + offsetInMangledName + offset;
|
|
||||||
|
|
||||||
RemoteAbsolutePointer resolved;
|
RemoteAbsolutePointer resolved;
|
||||||
if (directness == Directness::Indirect) {
|
if (directness == Directness::Indirect) {
|
||||||
|
auto remoteAddress = Reader->resolveIndirectAddressAtOffset(
|
||||||
|
offsetAddress, offset, /*directnessEncodedInOffset=*/false);
|
||||||
if (auto indirectAddress = readPointer(remoteAddress)) {
|
if (auto indirectAddress = readPointer(remoteAddress)) {
|
||||||
resolved = stripSignedPointer(*indirectAddress);
|
resolved = stripSignedPointer(*indirectAddress);
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
auto remoteAddress = offsetAddress + offset;
|
||||||
resolved = Reader->getSymbol(remoteAddress);
|
resolved = Reader->getSymbol(remoteAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2078,17 +2080,19 @@ protected:
|
|||||||
|
|
||||||
using SignedPointer = typename std::make_signed<StoredPointer>::type;
|
using SignedPointer = typename std::make_signed<StoredPointer>::type;
|
||||||
|
|
||||||
RemoteAddress resultAddress = getAddress(fieldRef) + (SignedPointer)offset;
|
|
||||||
|
|
||||||
// Low bit set in the offset indicates that the offset leads to the absolute
|
// Low bit set in the offset indicates that the offset leads to the absolute
|
||||||
// address in memory.
|
// address in memory.
|
||||||
if (indirect) {
|
if (indirect) {
|
||||||
|
RemoteAddress resultAddress = Reader->resolveIndirectAddressAtOffset(
|
||||||
|
getAddress(fieldRef), (SignedPointer)offset,
|
||||||
|
/*directnessEncodedInOffset=*/true);
|
||||||
if (auto ptr = readPointer(resultAddress)) {
|
if (auto ptr = readPointer(resultAddress)) {
|
||||||
return stripSignedPointer(*ptr);
|
return stripSignedPointer(*ptr);
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RemoteAddress resultAddress = getAddress(fieldRef) + (SignedPointer)offset;
|
||||||
return RemoteAbsolutePointer(resultAddress);
|
return RemoteAbsolutePointer(resultAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user