@@ -84,7 +84,7 @@ swift::remote::RemoteAddress
84
84
LLDBMemoryReader::getSymbolAddress (const std::string &name) {
85
85
lldbassert (!name.empty ());
86
86
if (name.empty ())
87
- return swift::remote::RemoteAddress (nullptr );
87
+ return swift::remote::RemoteAddress ();
88
88
89
89
Log *log = GetLog (LLDBLog::Types);
90
90
@@ -97,7 +97,7 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) {
97
97
name_cs, lldb::eSymbolTypeAny, sc_list);
98
98
if (!sc_list.GetSize ()) {
99
99
LLDB_LOGV (log, " [MemoryReader] symbol resolution failed {0}" , name);
100
- return swift::remote::RemoteAddress (nullptr );
100
+ return swift::remote::RemoteAddress ();
101
101
}
102
102
103
103
SymbolContext sym_ctx;
@@ -118,14 +118,15 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) {
118
118
if (sym_ctx.symbol ) {
119
119
auto load_addr = sym_ctx.symbol ->GetLoadAddress (&m_process.GetTarget ());
120
120
LLDB_LOGV (log, " [MemoryReader] symbol resolved to {0:x}" , load_addr);
121
- return swift::remote::RemoteAddress (load_addr);
121
+ return swift::remote::RemoteAddress (
122
+ load_addr, swift::remote::RemoteAddress::DefaultAddressSpace);
122
123
}
123
124
}
124
125
125
126
// Empty list, resolution failed.
126
127
if (sc_list.GetSize () == 0 ) {
127
128
LLDB_LOGV (log, " [MemoryReader] symbol resolution failed {0}" , name);
128
- return swift::remote::RemoteAddress (nullptr );
129
+ return swift::remote::RemoteAddress ();
129
130
}
130
131
131
132
// If there's a single symbol, then we're golden. If there's more than
@@ -140,11 +141,12 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) {
140
141
load_addr, m_process.GetAddressByteSize (), 0 , error, true );
141
142
if (sym_value != other_sym_value) {
142
143
LLDB_LOGV (log, " [MemoryReader] symbol resolution failed {0}" , name);
143
- return swift::remote::RemoteAddress (nullptr );
144
+ return swift::remote::RemoteAddress ();
144
145
}
145
146
}
146
147
LLDB_LOGV (log, " [MemoryReader] symbol resolved to {0}" , load_addr);
147
- return swift::remote::RemoteAddress (load_addr);
148
+ return swift::remote::RemoteAddress (
149
+ load_addr, swift::remote::RemoteAddress::DefaultAddressSpace);
148
150
}
149
151
150
152
static std::unique_ptr<swift::SwiftObjectFileFormat>
@@ -180,7 +182,7 @@ LLDBMemoryReader::resolvePointerAsSymbol(swift::remote::RemoteAddress address) {
180
182
return {};
181
183
182
184
std::optional<Address> maybeAddr =
183
- resolveRemoteAddress (address.getAddressData ());
185
+ resolveRemoteAddress (address.getRawAddress ());
184
186
// This is not an assert, but should never happen.
185
187
if (!maybeAddr)
186
188
return {};
@@ -191,7 +193,7 @@ LLDBMemoryReader::resolvePointerAsSymbol(swift::remote::RemoteAddress address) {
191
193
addr = *maybeAddr;
192
194
} else {
193
195
// `address` is a real load address.
194
- if (!target.ResolveLoadAddress (address.getAddressData (), addr))
196
+ if (!target.ResolveLoadAddress (address.getRawAddress (), addr))
195
197
return {};
196
198
}
197
199
@@ -229,23 +231,24 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
229
231
// to a tagged address so further memory reads originating from it benefit
230
232
// from the file-cache optimization.
231
233
swift::remote::RemoteAbsolutePointer process_pointer{
232
- swift::remote::RemoteAddress{readValue}};
234
+ swift::remote::RemoteAddress{
235
+ readValue, swift::remote::RemoteAddress::DefaultAddressSpace}};
233
236
234
237
if (!readMetadataFromFileCacheEnabled ())
235
238
return process_pointer;
236
239
237
240
// Try to strip the pointer before checking if we have it mapped.
238
241
auto strippedPointer = signedPointerStripper (process_pointer);
239
242
if (auto resolved = strippedPointer.getResolvedAddress ())
240
- readValue = resolved.getAddressData ();
243
+ readValue = resolved.getRawAddress ();
241
244
242
245
auto &target = m_process.GetTarget ();
243
246
Address addr;
244
247
if (!target.ResolveLoadAddress (readValue, addr)) {
245
248
LLDB_LOGV (log,
246
249
" [MemoryReader] Could not resolve load address of pointer {0:x} "
247
250
" read from {1:x}." ,
248
- readValue, address.getAddressData ());
251
+ readValue, address.getRawAddress ());
249
252
return process_pointer;
250
253
}
251
254
@@ -263,7 +266,7 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
263
266
LLDB_LOG (log,
264
267
" [MemoryReader] Could not resolve find module containing pointer "
265
268
" {0:x} read from {1:x}." ,
266
- readValue, address.getAddressData ());
269
+ readValue, address.getRawAddress ());
267
270
return process_pointer;
268
271
}
269
272
@@ -290,16 +293,17 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
290
293
LLDB_LOG (log,
291
294
" [MemoryReader] Pointer {0:x} read from {1:x} resolved to tagged "
292
295
" address {2:x}, which is outside its image address space." ,
293
- readValue, address.getAddressData (), tagged_address);
296
+ readValue, address.getRawAddress (), tagged_address);
294
297
return process_pointer;
295
298
}
296
299
297
300
swift::remote::RemoteAbsolutePointer tagged_pointer{
298
- swift::remote::RemoteAddress{tagged_address}};
301
+ swift::remote::RemoteAddress{
302
+ tagged_address, swift::remote::RemoteAddress::DefaultAddressSpace}};
299
303
300
304
if (tagged_address != (uint64_t )signedPointerStripper (tagged_pointer)
301
305
.getResolvedAddress ()
302
- .getAddressData ()) {
306
+ .getRawAddress ()) {
303
307
lldbassert (false &&
304
308
" Tagged pointer runs into pointer authentication mask!" );
305
309
return process_pointer;
@@ -308,7 +312,7 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
308
312
LLDB_LOGV (log,
309
313
" [MemoryReader] Successfully resolved pointer {0:x} read from "
310
314
" {1:x} to tagged address {2:x}." ,
311
- readValue, address.getAddressData (), tagged_address);
315
+ readValue, address.getRawAddress (), tagged_address);
312
316
return tagged_pointer;
313
317
}
314
318
@@ -317,7 +321,7 @@ bool LLDBMemoryReader::readBytes(swift::remote::RemoteAddress address,
317
321
Log *log = GetLog (LLDBLog::Types);
318
322
if (m_local_buffer) {
319
323
bool overflow = false ;
320
- auto addr = address.getAddressData ();
324
+ auto addr = address.getRawAddress ();
321
325
auto end = llvm::SaturatingAdd (addr, size, &overflow);
322
326
if (overflow) {
323
327
LLDB_LOGV (log, " [MemoryReader] address {0:x} + size {1} overflows" , addr,
@@ -335,16 +339,16 @@ bool LLDBMemoryReader::readBytes(swift::remote::RemoteAddress address,
335
339
}
336
340
337
341
LLDB_LOGV (log, " [MemoryReader] asked to read {0} bytes at address {1:x}" ,
338
- size, address.getAddressData ());
342
+ size, address.getRawAddress ());
339
343
std::optional<Address> maybeAddr =
340
- resolveRemoteAddressFromSymbolObjectFile (address.getAddressData ());
344
+ resolveRemoteAddressFromSymbolObjectFile (address.getRawAddress ());
341
345
342
346
if (!maybeAddr)
343
- maybeAddr = resolveRemoteAddress (address.getAddressData ());
347
+ maybeAddr = resolveRemoteAddress (address.getRawAddress ());
344
348
345
349
if (!maybeAddr) {
346
350
LLDB_LOGV (log, " [MemoryReader] could not resolve address {0:x}" ,
347
- address.getAddressData ());
351
+ address.getRawAddress ());
348
352
return false ;
349
353
}
350
354
auto addr = *maybeAddr;
@@ -411,17 +415,17 @@ bool LLDBMemoryReader::readString(swift::remote::RemoteAddress address,
411
415
return std::string (stream.GetData ());
412
416
};
413
417
LLDB_LOGV (log, " [MemoryReader] asked to read string data at address {0:x}" ,
414
- address.getAddressData ());
418
+ address.getRawAddress ());
415
419
416
420
std::optional<Address> maybeAddr =
417
- resolveRemoteAddressFromSymbolObjectFile (address.getAddressData ());
421
+ resolveRemoteAddressFromSymbolObjectFile (address.getRawAddress ());
418
422
419
423
if (!maybeAddr)
420
- maybeAddr = resolveRemoteAddress (address.getAddressData ());
424
+ maybeAddr = resolveRemoteAddress (address.getRawAddress ());
421
425
422
426
if (!maybeAddr) {
423
427
LLDB_LOGV (log, " [MemoryReader] could not resolve address {0:x}" ,
424
- address.getAddressData ());
428
+ address.getRawAddress ());
425
429
return false ;
426
430
}
427
431
auto addr = *maybeAddr;
@@ -455,6 +459,41 @@ bool LLDBMemoryReader::readString(swift::remote::RemoteAddress address,
455
459
return false ;
456
460
}
457
461
462
+ uint64_t LLDBMemoryReader::getPtrauthMask () {
463
+ auto initializePtrauthMask = [&]() -> uint64_t {
464
+ uint8_t pointerSize = 0 ;
465
+ if (!queryDataLayout (DataLayoutQueryType::DLQ_GetPointerSize, nullptr ,
466
+ &pointerSize))
467
+ return ~0ull ;
468
+
469
+ if (pointerSize == 4 ) {
470
+ uint32_t ptrauthMask32 = 0 ;
471
+ if (queryDataLayout (DataLayoutQueryType::DLQ_GetPtrAuthMask, nullptr ,
472
+ &ptrauthMask32))
473
+ return (uint64_t )ptrauthMask32;
474
+ } else if (pointerSize == 8 ) {
475
+ uint64_t ptrauthMask64 = 0 ;
476
+ if (queryDataLayout (DataLayoutQueryType::DLQ_GetPtrAuthMask, nullptr ,
477
+ &ptrauthMask64))
478
+ return ptrauthMask64;
479
+ }
480
+ return ~0ull ;
481
+ };
482
+ if (!m_ptrauth_mask)
483
+ m_ptrauth_mask = initializePtrauthMask ();
484
+ return m_ptrauth_mask;
485
+ }
486
+
487
+ swift::reflection::RemoteAddress
488
+ LLDBMemoryReader::stripSignedPointer (swift::reflection::RemoteAddress P) {
489
+ // Only virtual addresses are signed.
490
+ if (P.getAddressSpace () != swift::reflection::RemoteAddress::DefaultAddressSpace)
491
+ return P;
492
+
493
+ auto ptrauth_mask = getPtrauthMask ();
494
+ return P & ptrauth_mask;
495
+ }
496
+
458
497
MemoryReaderLocalBufferHolder::~MemoryReaderLocalBufferHolder () {
459
498
if (m_memory_reader)
460
499
m_memory_reader->popLocalBuffer ();
@@ -539,10 +578,11 @@ LLDBMemoryReader::addModuleToAddressMap(ModuleSP module,
539
578
540
579
if (module_end_address !=
541
580
signedPointerStripper (
542
- swift::remote::RemoteAbsolutePointer{
543
- swift::remote::RemoteAddress{module_end_address}})
581
+ swift::remote::RemoteAbsolutePointer{swift::remote::RemoteAddress{
582
+ module_end_address,
583
+ swift::reflection::RemoteAddress::DefaultAddressSpace}})
544
584
.getResolvedAddress ()
545
- .getAddressData ()) {
585
+ .getRawAddress ()) {
546
586
LLDB_LOG (GetLog (LLDBLog::Types),
547
587
" [MemoryReader] module to address map ran into pointer "
548
588
" authentication mask!" );
@@ -615,12 +655,12 @@ std::optional<swift::reflection::RemoteAddress>
615
655
LLDBMemoryReader::resolveRemoteAddress (
616
656
swift::reflection::RemoteAddress address) const {
617
657
std::optional<Address> lldb_address =
618
- LLDBMemoryReader::resolveRemoteAddress (address.getAddressData ());
658
+ LLDBMemoryReader::resolveRemoteAddress (address.getRawAddress ());
619
659
if (!lldb_address)
620
660
return {};
621
661
lldb::addr_t addr = lldb_address->GetLoadAddress (&m_process.GetTarget ());
622
662
if (addr != LLDB_INVALID_ADDRESS)
623
- return swift::reflection::RemoteAddress (addr);
663
+ return swift::reflection::RemoteAddress (addr, swift::reflection::RemoteAddress::DefaultAddressSpace );
624
664
return {};
625
665
}
626
666
0 commit comments