mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[RemoteInspection] Change RemoteAbsolutePointer (NFC)
This patch changes RemoteAbsolutePointer to store both the symbol and the resolved address. This allows us to retire some ugly workarounds to deal with non-symbolic addresses and it fixes code paths that would need these workarounds, but haven't implemented them yet (i.e., the pack shape handling in the symbolicReferenceResolver in MetadatyaReader. Addresses parts of rdar://146273066. rdar://153687085 (cherry picked from commit9381a54c67) (cherry picked from commita6eafcb311)
This commit is contained in:
committed by
Augusto Noronha
parent
1dd4a993eb
commit
bfb026cb9e
@@ -147,7 +147,7 @@ public:
|
||||
virtual RemoteAbsolutePointer resolvePointer(RemoteAddress address,
|
||||
uint64_t readValue) {
|
||||
// Default implementation returns the read value as is.
|
||||
return RemoteAbsolutePointer("", readValue);
|
||||
return RemoteAbsolutePointer(RemoteAddress(readValue));
|
||||
}
|
||||
|
||||
/// Performs the inverse operation of \ref resolvePointer.
|
||||
@@ -166,7 +166,7 @@ public:
|
||||
virtual RemoteAbsolutePointer getSymbol(RemoteAddress address) {
|
||||
if (auto symbol = resolvePointerAsSymbol(address))
|
||||
return *symbol;
|
||||
return RemoteAbsolutePointer("", address.getAddressData());
|
||||
return RemoteAbsolutePointer(address);
|
||||
}
|
||||
|
||||
/// Lookup a dynamic symbol name (ie dynamic loader binding) for the given
|
||||
|
||||
@@ -416,11 +416,9 @@ public:
|
||||
}
|
||||
|
||||
RemoteAbsolutePointer stripSignedPointer(const RemoteAbsolutePointer &P) {
|
||||
if (P.isResolved()) {
|
||||
return RemoteAbsolutePointer("",
|
||||
P.getResolvedAddress().getAddressData() & PtrAuthMask);
|
||||
}
|
||||
return P;
|
||||
return RemoteAbsolutePointer(
|
||||
P.getSymbol(), P.getOffset(),
|
||||
RemoteAddress(P.getResolvedAddress().getAddressData() & PtrAuthMask));
|
||||
}
|
||||
|
||||
StoredPointer queryPtrAuthMask() {
|
||||
@@ -519,14 +517,6 @@ public:
|
||||
// The second entry is a relative address to the mangled protocol
|
||||
// without symbolic references.
|
||||
|
||||
// lldb might return an unresolved remote absolute pointer from its
|
||||
// resolvePointerAsSymbol implementation -- workaround this.
|
||||
if (!resolved.isResolved()) {
|
||||
auto remoteAddr = RemoteAddress(remoteAddress);
|
||||
resolved =
|
||||
RemoteAbsolutePointer("", remoteAddr.getAddressData());
|
||||
}
|
||||
|
||||
auto addr =
|
||||
resolved.getResolvedAddress().getAddressData() + sizeof(int32_t);
|
||||
int32_t offset;
|
||||
@@ -534,14 +524,6 @@ public:
|
||||
auto addrOfTypeRef = addr + offset;
|
||||
resolved = Reader->getSymbol(RemoteAddress(addrOfTypeRef));
|
||||
|
||||
// lldb might return an unresolved remote absolute pointer from its
|
||||
// resolvePointerAsSymbol implementation -- workaround this.
|
||||
if (!resolved.isResolved()) {
|
||||
auto remoteAddr = RemoteAddress(addrOfTypeRef);
|
||||
resolved =
|
||||
RemoteAbsolutePointer("", remoteAddr.getAddressData());
|
||||
}
|
||||
|
||||
// Dig out the protocol from the protocol list.
|
||||
auto protocolList = readMangledName(resolved.getResolvedAddress(),
|
||||
MangledNameKind::Type, dem);
|
||||
@@ -1379,12 +1361,10 @@ public:
|
||||
ParentContextDescriptorRef
|
||||
readContextDescriptor(const RemoteAbsolutePointer &address) {
|
||||
// Map an unresolved pointer to an unresolved context ref.
|
||||
if (!address.isResolved()) {
|
||||
if (!address.getSymbol().empty()) {
|
||||
// We can only handle references to a symbol without an offset currently.
|
||||
if (address.getOffset() != 0) {
|
||||
return ParentContextDescriptorRef();
|
||||
}
|
||||
return ParentContextDescriptorRef(address.getSymbol());
|
||||
if (address.getOffset() == 0)
|
||||
return ParentContextDescriptorRef(address.getSymbol());
|
||||
}
|
||||
|
||||
return ParentContextDescriptorRef(
|
||||
@@ -2016,7 +1996,7 @@ public:
|
||||
|
||||
std::optional<StoredPointer> readResolvedPointerValue(StoredPointer address) {
|
||||
if (auto pointer = readPointer(address)) {
|
||||
if (!pointer->isResolved())
|
||||
if (!pointer->getResolvedAddress())
|
||||
return std::nullopt;
|
||||
return (StoredPointer)pointer->getResolvedAddress().getAddressData();
|
||||
}
|
||||
@@ -2079,7 +2059,7 @@ protected:
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return RemoteAbsolutePointer("", resultAddress);
|
||||
return RemoteAbsolutePointer(RemoteAddress(resultAddress));
|
||||
}
|
||||
|
||||
/// Given a pointer to an Objective-C class, try to read its class name.
|
||||
@@ -2335,13 +2315,11 @@ private:
|
||||
auto parentAddress = resolveRelativeIndirectableField(base, base->Parent);
|
||||
if (!parentAddress)
|
||||
return std::nullopt;
|
||||
if (!parentAddress->isResolved()) {
|
||||
if (!parentAddress->getSymbol().empty()) {
|
||||
// Currently we can only handle references directly to a symbol without
|
||||
// an offset.
|
||||
if (parentAddress->getOffset() != 0) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return ParentContextDescriptorRef(parentAddress->getSymbol());
|
||||
if (parentAddress->getOffset() == 0)
|
||||
return ParentContextDescriptorRef(parentAddress->getSymbol());
|
||||
}
|
||||
auto addr = parentAddress->getResolvedAddress();
|
||||
if (!addr)
|
||||
|
||||
@@ -63,35 +63,30 @@ public:
|
||||
|
||||
/// A symbolic relocated absolute pointer value.
|
||||
class RemoteAbsolutePointer {
|
||||
/// The symbol name that the pointer refers to. Empty if the value is absolute.
|
||||
/// The symbol name that the pointer refers to. Empty if only an absolute
|
||||
/// address is available.
|
||||
std::string Symbol;
|
||||
/// The offset from the symbol, or the resolved remote address if \c Symbol is empty.
|
||||
int64_t Offset;
|
||||
/// The offset from the symbol.
|
||||
int64_t Offset = 0;
|
||||
/// The resolved remote address.
|
||||
RemoteAddress Address = RemoteAddress{(uint64_t)0};
|
||||
|
||||
public:
|
||||
RemoteAbsolutePointer()
|
||||
: Symbol(), Offset(0)
|
||||
{}
|
||||
|
||||
RemoteAbsolutePointer(std::nullptr_t)
|
||||
: RemoteAbsolutePointer()
|
||||
{}
|
||||
|
||||
RemoteAbsolutePointer(llvm::StringRef Symbol, int64_t Offset)
|
||||
: Symbol(Symbol), Offset(Offset)
|
||||
{}
|
||||
|
||||
bool isResolved() const { return Symbol.empty(); }
|
||||
RemoteAbsolutePointer() = default;
|
||||
RemoteAbsolutePointer(std::nullptr_t) : RemoteAbsolutePointer() {}
|
||||
|
||||
RemoteAbsolutePointer(llvm::StringRef Symbol, int64_t Offset,
|
||||
RemoteAddress Address)
|
||||
: Symbol(Symbol), Offset(Offset), Address(Address) {}
|
||||
RemoteAbsolutePointer(RemoteAddress Address) : Address(Address) {}
|
||||
|
||||
llvm::StringRef getSymbol() const { return Symbol; }
|
||||
int64_t getOffset() const { return Offset; }
|
||||
|
||||
RemoteAddress getResolvedAddress() const {
|
||||
assert(isResolved());
|
||||
return RemoteAddress(Offset);
|
||||
}
|
||||
|
||||
|
||||
RemoteAddress getResolvedAddress() const { return Address; }
|
||||
|
||||
explicit operator bool() const {
|
||||
return Offset != 0 || !Symbol.empty();
|
||||
return Address || !Symbol.empty();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1020,7 +1020,7 @@ public:
|
||||
auto CDAddr = this->readCaptureDescriptorFromMetadata(*MetadataAddress);
|
||||
if (!CDAddr)
|
||||
return nullptr;
|
||||
if (!CDAddr->isResolved())
|
||||
if (!CDAddr->getResolvedAddress())
|
||||
return nullptr;
|
||||
|
||||
// FIXME: Non-generic SIL boxes also use the HeapLocalVariable metadata
|
||||
|
||||
@@ -1871,7 +1871,7 @@ private:
|
||||
if (auto symbol = OpaquePointerReader(
|
||||
remote::RemoteAddress(adjustedProtocolDescriptorTarget),
|
||||
PointerSize)) {
|
||||
if (!symbol->getSymbol().empty()) {
|
||||
if (!symbol->getSymbol().empty() && symbol->getOffset() == 0) {
|
||||
Demangle::Context Ctx;
|
||||
auto demangledRoot =
|
||||
Ctx.demangleSymbolAsNode(symbol->getSymbol().str());
|
||||
@@ -1882,7 +1882,8 @@ private:
|
||||
nodeToString(demangledRoot->getChild(0)->getChild(0));
|
||||
} else {
|
||||
// This is an absolute address of a protocol descriptor
|
||||
auto protocolDescriptorAddress = (uintptr_t)symbol->getOffset();
|
||||
auto protocolDescriptorAddress =
|
||||
(uintptr_t)symbol->getResolvedAddress().getAddressData();
|
||||
protocolName = readFullyQualifiedProtocolNameFromProtocolDescriptor(
|
||||
protocolDescriptorAddress);
|
||||
}
|
||||
@@ -2026,7 +2027,7 @@ private:
|
||||
if (auto symbol = OpaquePointerReader(
|
||||
remote::RemoteAddress(adjustedParentTargetAddress),
|
||||
PointerSize)) {
|
||||
if (!symbol->getSymbol().empty()) {
|
||||
if (!symbol->getSymbol().empty() && symbol->getOffset() == 0) {
|
||||
Demangle::Context Ctx;
|
||||
auto demangledRoot =
|
||||
Ctx.demangleSymbolAsNode(symbol->getSymbol().str());
|
||||
@@ -2264,7 +2265,7 @@ private:
|
||||
// external, check that first
|
||||
if (auto symbol = OpaqueDynamicSymbolResolver(
|
||||
remote::RemoteAddress(contextTypeDescriptorAddress))) {
|
||||
if (!symbol->isResolved()) {
|
||||
if (!symbol->getSymbol().empty() && symbol->getOffset() == 0) {
|
||||
Demangle::Context Ctx;
|
||||
auto demangledRoot =
|
||||
Ctx.demangleSymbolAsNode(symbol->getSymbol().str());
|
||||
@@ -2283,10 +2284,11 @@ private:
|
||||
mangledTypeName = typeMangling.result();
|
||||
|
||||
return std::make_pair(mangledTypeName, typeName);
|
||||
} else if (symbol->getOffset()) {
|
||||
} else if (symbol->getResolvedAddress()) {
|
||||
// If symbol is empty and has an offset, this is the resolved remote
|
||||
// address
|
||||
contextTypeDescriptorAddress = symbol->getOffset();
|
||||
contextTypeDescriptorAddress =
|
||||
symbol->getResolvedAddress().getAddressData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user