Files
swift-mirror/include/swift/Remote/RemoteAddress.h
Joe Groff 4012a207c8 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.
2019-09-28 16:53:34 -07:00

91 lines
2.4 KiB
C++

//===--- RemoteAddress.h - Address of remote memory -------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines the RemoteAddress type, which abstracts over an
// address in a remote process.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_REMOTE_REMOTEADDRESS_H
#define SWIFT_REMOTE_REMOTEADDRESS_H
#include <cstdint>
#include <string>
#include <llvm/ADT/StringRef.h>
#include <cassert>
namespace swift {
namespace remote {
/// An abstract address in the remote process's address space.
class RemoteAddress {
uint64_t Data;
public:
explicit RemoteAddress(const void *localPtr)
: Data(reinterpret_cast<uintptr_t>(localPtr)) {}
explicit RemoteAddress(uint64_t addressData) : Data(addressData) {}
explicit operator bool() const {
return Data != 0;
}
template <class T>
const T *getLocalPointer() const {
return reinterpret_cast<const T*>(static_cast<uintptr_t>(Data));
}
uint64_t getAddressData() const {
return Data;
}
};
/// A symbolic relocated absolute pointer value.
class RemoteAbsolutePointer {
/// The symbol name that the pointer refers to. Empty if the value is absolute.
std::string Symbol;
/// The offset from the symbol, or the resolved remote address if \c Symbol is empty.
int64_t Offset;
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(); }
llvm::StringRef getSymbol() const { return Symbol; }
int64_t getOffset() const { return Offset; }
RemoteAddress getResolvedAddress() const {
assert(isResolved());
return RemoteAddress(Offset);
}
explicit operator bool() const {
return Offset != 0 || !Symbol.empty();
}
};
} // end namespace remote
} // end namespace swift
#endif // SWIFT_REMOTE_REMOTEADDRESS_H