mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
MetadataReader: Add an API for reading absolute pointers.
Pointer data in some remote reflection targets may required relocation, or may not be fully resolvable, such as when we're dumping info from a single image on disk that references other dynamic libraries. Add a `RemoteAbsolutePointer` type that can hold a symbol, offset, or combination of both, and add APIs to `MemoryReader` and `MetadataReader` for reading pointers that can get unresolved relocation info from an image, or apply relocations to pointer information. MetadataReader can use the symbol name information to fill in demanglings of symbolic-reference-bearing mangled names by using the information from the symbol name to fill in the name even though the context descriptors are not available. For now, this is NFC (MemoryReader::resolvePointer just forwards the pointer data), but lays the groundwork for implementation of relocation in ObjectMemoryReader.
This commit is contained in:
@@ -69,7 +69,7 @@ public:
|
||||
/// NOTE: subclasses MUST override at least one of the readBytes functions. The default
|
||||
/// implementation calls through to the other one.
|
||||
virtual ReadBytesResult
|
||||
readBytes(RemoteAddress address, uint64_t size) {
|
||||
readBytes(RemoteAddress address, uint64_t size) {
|
||||
auto *Buf = malloc(size);
|
||||
ReadBytesResult Result(Buf, [](const void *ptr) {
|
||||
free(const_cast<void *>(ptr));
|
||||
@@ -96,6 +96,34 @@ public:
|
||||
memcpy(dest, Ptr.get(), size);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Attempts to resolve a pointer value read from the given remote address.
|
||||
virtual RemoteAbsolutePointer resolvePointer(RemoteAddress address,
|
||||
uint64_t readValue) {
|
||||
// Default implementation returns the read value as is.
|
||||
return RemoteAbsolutePointer("", readValue);
|
||||
}
|
||||
|
||||
/// Attempt to read and resolve a pointer value at the given remote address.
|
||||
llvm::Optional<RemoteAbsolutePointer> readPointer(RemoteAddress address,
|
||||
unsigned pointerSize) {
|
||||
auto result = readBytes(address, pointerSize);
|
||||
if (!result)
|
||||
return llvm::None;
|
||||
|
||||
uint64_t pointerData;
|
||||
if (pointerSize == 4) {
|
||||
uint32_t theData;
|
||||
memcpy(&theData, result.get(), 4);
|
||||
pointerData = theData;
|
||||
} else if (pointerSize == 8) {
|
||||
memcpy(&pointerData, result.get(), 8);
|
||||
} else {
|
||||
return llvm::None;
|
||||
}
|
||||
|
||||
return resolvePointer(address, pointerData);
|
||||
}
|
||||
|
||||
virtual ~MemoryReader() = default;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user