mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[NFC][RemoteInspection] Add an opaque AddressSpace field to RemoteAddress
Add an extra opaque field to AddressSpace, which can be used by clients of RemoteInspection to distinguish between different address spaces. LLDB employs an optimization where it reads memory from files instead of the running process whenever it can to speed up memory reads (these can be slow when debugging something over a network). To do this, it needs to keep track whether an address originated from a process or a file. It currently distinguishes addresses by setting an unused high bit on the address, but because of pointer authentication this is not a reliable solution. In order to keep this optimization working, this patch adds an extra opaque AddressSpace field to RemoteAddress, which LLDB can use on its own implementation of MemoryReader to distinguish between addresses. This patch is NFC for the other RemoteInspection clients, as it adds extra information to RemoteAddress, which is entirely optional and if unused should not change the behavior of the library. Although this patch is quite big the changes are largely mechanical, replacing threading StoredPointer with RemoteAddress. rdar://148361743 (cherry picked from commit58df5534d2) (cherry picked from commit8f3862b5e7)
This commit is contained in:
@@ -57,13 +57,31 @@ public:
|
||||
///
|
||||
/// Returns false if the operation failed.
|
||||
virtual bool readString(RemoteAddress address, std::string &dest) = 0;
|
||||
|
||||
|
||||
/// Attempts to read a remote address from the given address in the remote
|
||||
/// process.
|
||||
///
|
||||
/// Returns false if the operator failed.
|
||||
template <typename IntegerType>
|
||||
bool readRemoteAddress(RemoteAddress address, RemoteAddress &out) {
|
||||
IntegerType buf;
|
||||
if (!readInteger(address, &buf))
|
||||
return false;
|
||||
|
||||
out = RemoteAddress((uint64_t)buf, address.getAddressSpace());
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Attempts to read an integer from the given address in the remote
|
||||
/// process.
|
||||
///
|
||||
/// Returns false if the operation failed.
|
||||
template <typename IntegerType>
|
||||
bool readInteger(RemoteAddress address, IntegerType *dest) {
|
||||
static_assert(!std::is_same<RemoteAddress, IntegerType>(),
|
||||
"RemoteAddress cannot be read in directly, use "
|
||||
"readRemoteAddress instead.");
|
||||
|
||||
return readBytes(address, reinterpret_cast<uint8_t*>(dest),
|
||||
sizeof(IntegerType));
|
||||
}
|
||||
@@ -147,7 +165,8 @@ public:
|
||||
virtual RemoteAbsolutePointer resolvePointer(RemoteAddress address,
|
||||
uint64_t readValue) {
|
||||
// Default implementation returns the read value as is.
|
||||
return RemoteAbsolutePointer(RemoteAddress(readValue));
|
||||
return RemoteAbsolutePointer(
|
||||
RemoteAddress(readValue, address.getAddressSpace()));
|
||||
}
|
||||
|
||||
/// Performs the inverse operation of \ref resolvePointer.
|
||||
@@ -263,7 +282,7 @@ public:
|
||||
virtual ~MemoryReader() = default;
|
||||
};
|
||||
|
||||
} // end namespace reflection
|
||||
} // end namespace remote
|
||||
} // end namespace swift
|
||||
|
||||
#endif // SWIFT_REFLECTION_READER_H
|
||||
|
||||
Reference in New Issue
Block a user