@@ -128,13 +128,31 @@ class MemoryReader {
128128 // /
129129 // / Returns false if the operation failed.
130130 virtual bool readString (RemoteAddress address, std::string &dest) = 0;
131-
131+
132+ // / Attempts to read a remote address from the given address in the remote
133+ // / process.
134+ // /
135+ // / Returns false if the operator failed.
136+ template <typename IntegerType>
137+ bool readRemoteAddress (RemoteAddress address, RemoteAddress &out) {
138+ IntegerType buf;
139+ if (!readInteger (address, &buf))
140+ return false ;
141+
142+ out = RemoteAddress ((uint64_t )buf, address.getAddressSpace ());
143+ return true ;
144+ }
145+
132146 // / Attempts to read an integer from the given address in the remote
133147 // / process.
134148 // /
135149 // / Returns false if the operation failed.
136150 template <typename IntegerType>
137151 bool readInteger (RemoteAddress address, IntegerType *dest) {
152+ static_assert (!std::is_same<RemoteAddress, IntegerType>(),
153+ " RemoteAddress cannot be read in directly, use "
154+ " readRemoteAddress instead." );
155+
138156 return readBytes (address, reinterpret_cast <uint8_t *>(dest),
139157 sizeof (IntegerType));
140158 }
@@ -218,7 +236,8 @@ class MemoryReader {
218236 virtual RemoteAbsolutePointer resolvePointer (RemoteAddress address,
219237 uint64_t readValue) {
220238 // Default implementation returns the read value as is.
221- return RemoteAbsolutePointer (RemoteAddress (readValue));
239+ return RemoteAbsolutePointer (
240+ RemoteAddress (readValue, address.getAddressSpace ()));
222241 }
223242
224243 // / Performs the inverse operation of \ref resolvePointer.
@@ -321,7 +340,7 @@ class MemoryReader {
321340 virtual ~MemoryReader () = default ;
322341};
323342
324- } // end namespace reflection
343+ } // end namespace remote
325344} // end namespace swift
326345
327346#endif // SWIFT_REFLECTION_READER_H
0 commit comments