@@ -57,13 +57,31 @@ class MemoryReader {
5757 // /
5858 // / Returns false if the operation failed.
5959 virtual bool readString (RemoteAddress address, std::string &dest) = 0;
60-
60+
61+ // / Attempts to read a remote address from the given address in the remote
62+ // / process.
63+ // /
64+ // / Returns false if the operator failed.
65+ template <typename IntegerType>
66+ bool readRemoteAddress (RemoteAddress address, RemoteAddress &out) {
67+ IntegerType buf;
68+ if (!readInteger (address, &buf))
69+ return false ;
70+
71+ out = RemoteAddress ((uint64_t )buf, address.getAddressSpace ());
72+ return true ;
73+ }
74+
6175 // / Attempts to read an integer from the given address in the remote
6276 // / process.
6377 // /
6478 // / Returns false if the operation failed.
6579 template <typename IntegerType>
6680 bool readInteger (RemoteAddress address, IntegerType *dest) {
81+ static_assert (!std::is_same<RemoteAddress, IntegerType>(),
82+ " RemoteAddress cannot be read in directly, use "
83+ " readRemoteAddress instead." );
84+
6785 return readBytes (address, reinterpret_cast <uint8_t *>(dest),
6886 sizeof (IntegerType));
6987 }
@@ -147,7 +165,8 @@ class MemoryReader {
147165 virtual RemoteAbsolutePointer resolvePointer (RemoteAddress address,
148166 uint64_t readValue) {
149167 // Default implementation returns the read value as is.
150- return RemoteAbsolutePointer (" " , readValue);
168+ return RemoteAbsolutePointer (
169+ RemoteAddress (readValue, address.getAddressSpace ()));
151170 }
152171
153172 // / Performs the inverse operation of \ref resolvePointer.
@@ -166,7 +185,7 @@ class MemoryReader {
166185 virtual RemoteAbsolutePointer getSymbol (RemoteAddress address) {
167186 if (auto symbol = resolvePointerAsSymbol (address))
168187 return *symbol;
169- return RemoteAbsolutePointer (" " , address. getAddressData () );
188+ return RemoteAbsolutePointer (address);
170189 }
171190
172191 // / Lookup a dynamic symbol name (ie dynamic loader binding) for the given
@@ -263,7 +282,7 @@ class MemoryReader {
263282 virtual ~MemoryReader () = default ;
264283};
265284
266- } // end namespace reflection
285+ } // end namespace remote
267286} // end namespace swift
268287
269288#endif // SWIFT_REFLECTION_READER_H
0 commit comments