@@ -57,13 +57,31 @@ class MemoryReader {
57
57
// /
58
58
// / Returns false if the operation failed.
59
59
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
+
61
75
// / Attempts to read an integer from the given address in the remote
62
76
// / process.
63
77
// /
64
78
// / Returns false if the operation failed.
65
79
template <typename IntegerType>
66
80
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
+
67
85
return readBytes (address, reinterpret_cast <uint8_t *>(dest),
68
86
sizeof (IntegerType));
69
87
}
@@ -147,7 +165,8 @@ class MemoryReader {
147
165
virtual RemoteAbsolutePointer resolvePointer (RemoteAddress address,
148
166
uint64_t readValue) {
149
167
// Default implementation returns the read value as is.
150
- return RemoteAbsolutePointer (" " , readValue);
168
+ return RemoteAbsolutePointer (
169
+ RemoteAddress (readValue, address.getAddressSpace ()));
151
170
}
152
171
153
172
// / Performs the inverse operation of \ref resolvePointer.
@@ -166,7 +185,7 @@ class MemoryReader {
166
185
virtual RemoteAbsolutePointer getSymbol (RemoteAddress address) {
167
186
if (auto symbol = resolvePointerAsSymbol (address))
168
187
return *symbol;
169
- return RemoteAbsolutePointer (" " , address. getAddressData () );
188
+ return RemoteAbsolutePointer (address);
170
189
}
171
190
172
191
// / Lookup a dynamic symbol name (ie dynamic loader binding) for the given
@@ -263,7 +282,7 @@ class MemoryReader {
263
282
virtual ~MemoryReader () = default ;
264
283
};
265
284
266
- } // end namespace reflection
285
+ } // end namespace remote
267
286
} // end namespace swift
268
287
269
288
#endif // SWIFT_REFLECTION_READER_H
0 commit comments