@@ -32,11 +32,6 @@ bool LLDBMemoryReader::queryDataLayout(DataLayoutQueryType type, void *inBuffer,
32
32
return false ;
33
33
// The mask returned by the process masks out the non-addressable bits.
34
34
uint64_t mask_pattern = ~ptrauth_mask;
35
- // LLDBMemoryReader sets LLDB_FILE_ADDRESS_BIT to distinguish process
36
- // addresses and file addresses that point into a reflection section on
37
- // disk. Setting the bit in the mask ensures it isn't accidentally cleared
38
- // by ptrauth stripping.
39
- mask_pattern |= LLDB_FILE_ADDRESS_BIT;
40
35
memcpy (outBuffer, &mask_pattern, m_process.GetAddressByteSize ());
41
36
return true ;
42
37
}
@@ -181,8 +176,7 @@ LLDBMemoryReader::resolvePointerAsSymbol(swift::remote::RemoteAddress address) {
181
176
if (!target.GetSwiftUseReflectionSymbols ())
182
177
return {};
183
178
184
- std::optional<Address> maybeAddr =
185
- resolveRemoteAddress (address.getRawAddress ());
179
+ std::optional<Address> maybeAddr = remoteAddressToLLDBAddress (address);
186
180
// This is not an assert, but should never happen.
187
181
if (!maybeAddr)
188
182
return {};
@@ -231,11 +225,14 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
231
225
// to a tagged address so further memory reads originating from it benefit
232
226
// from the file-cache optimization.
233
227
swift::remote::RemoteAbsolutePointer process_pointer{
234
- swift::remote::RemoteAddress{
235
- readValue, swift::remote::RemoteAddress::DefaultAddressSpace}};
228
+ swift::remote::RemoteAddress{readValue, address.getAddressSpace ()}};
236
229
237
- if (!readMetadataFromFileCacheEnabled ())
230
+ if (!readMetadataFromFileCacheEnabled ()) {
231
+ assert (address.getAddressSpace () ==
232
+ swift::remote::RemoteAddress::DefaultAddressSpace &&
233
+ " Unexpected address space!" );
238
234
return process_pointer;
235
+ }
239
236
240
237
// Try to strip the pointer before checking if we have it mapped.
241
238
auto strippedPointer = signedPointerStripper (process_pointer);
@@ -271,10 +268,10 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
271
268
}
272
269
273
270
// If the containing image is the first registered one, the image's tagged
274
- // start address for it is the first tagged address . Otherwise, the previous
275
- // pair's address is the start tagged address.
271
+ // start address for it is zero . Otherwise, the previous pair's address is the
272
+ // start of the new address.
276
273
uint64_t start_tagged_address = pair_iterator == m_range_module_map.begin ()
277
- ? LLDB_FILE_ADDRESS_BIT
274
+ ? 0
278
275
: std::prev (pair_iterator)->first ;
279
276
280
277
auto *section_list = module_containing_pointer->GetSectionList ();
@@ -298,8 +295,7 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
298
295
}
299
296
300
297
swift::remote::RemoteAbsolutePointer tagged_pointer{
301
- swift::remote::RemoteAddress{
302
- tagged_address, swift::remote::RemoteAddress::DefaultAddressSpace}};
298
+ swift::remote::RemoteAddress{tagged_address, LLDBAddressSpace}};
303
299
304
300
if (tagged_address != (uint64_t )signedPointerStripper (tagged_pointer)
305
301
.getResolvedAddress ()
@@ -341,10 +337,10 @@ bool LLDBMemoryReader::readBytes(swift::remote::RemoteAddress address,
341
337
LLDB_LOGV (log, " [MemoryReader] asked to read {0} bytes at address {1:x}" ,
342
338
size, address.getRawAddress ());
343
339
std::optional<Address> maybeAddr =
344
- resolveRemoteAddressFromSymbolObjectFile (address. getRawAddress () );
340
+ resolveRemoteAddressFromSymbolObjectFile (address);
345
341
346
342
if (!maybeAddr)
347
- maybeAddr = resolveRemoteAddress (address. getRawAddress () );
343
+ maybeAddr = remoteAddressToLLDBAddress (address);
348
344
349
345
if (!maybeAddr) {
350
346
LLDB_LOGV (log, " [MemoryReader] could not resolve address {0:x}" ,
@@ -418,10 +414,10 @@ bool LLDBMemoryReader::readString(swift::remote::RemoteAddress address,
418
414
address.getRawAddress ());
419
415
420
416
std::optional<Address> maybeAddr =
421
- resolveRemoteAddressFromSymbolObjectFile (address. getRawAddress () );
417
+ resolveRemoteAddressFromSymbolObjectFile (address);
422
418
423
419
if (!maybeAddr)
424
- maybeAddr = resolveRemoteAddress (address. getRawAddress () );
420
+ maybeAddr = remoteAddressToLLDBAddress (address);
425
421
426
422
if (!maybeAddr) {
427
423
LLDB_LOGV (log, " [MemoryReader] could not resolve address {0:x}" ,
@@ -461,7 +457,7 @@ bool LLDBMemoryReader::readString(swift::remote::RemoteAddress address,
461
457
462
458
MemoryReaderLocalBufferHolder::~MemoryReaderLocalBufferHolder () {
463
459
if (m_memory_reader)
464
- m_memory_reader->popLocalBuffer ();
460
+ m_memory_reader->popLocalBuffer ();
465
461
}
466
462
467
463
MemoryReaderLocalBufferHolder
@@ -490,12 +486,9 @@ LLDBMemoryReader::addModuleToAddressMap(ModuleSP module,
490
486
" Trying to register symbol object file, but reading from it is "
491
487
" disabled!" );
492
488
493
- // The first available address is the mask, since subsequent images are mapped
494
- // in ascending order, all of them will contain this mask.
495
- uint64_t module_start_address = LLDB_FILE_ADDRESS_BIT;
489
+ uint64_t module_start_address = 0 ;
496
490
if (!m_range_module_map.empty ())
497
- // We map the images contiguously one after the other, all with the tag bit
498
- // set.
491
+ // We map the images contiguously one after the other.
499
492
// The address that maps the last module is exactly the address the new
500
493
// module should start at.
501
494
module_start_address = m_range_module_map.back ().first ;
@@ -541,18 +534,6 @@ LLDBMemoryReader::addModuleToAddressMap(ModuleSP module,
541
534
auto size = end_file_address - start_file_address;
542
535
auto module_end_address = module_start_address + size;
543
536
544
- if (module_end_address !=
545
- signedPointerStripper (
546
- swift::remote::RemoteAbsolutePointer{swift::remote::RemoteAddress{
547
- module_end_address,
548
- swift::reflection::RemoteAddress::DefaultAddressSpace}})
549
- .getResolvedAddress ()
550
- .getRawAddress ()) {
551
- LLDB_LOG (GetLog (LLDBLog::Types),
552
- " [MemoryReader] module to address map ran into pointer "
553
- " authentication mask!" );
554
- return {};
555
- }
556
537
// The address for the next image is the next pointer aligned address
557
538
// available after the end of the current image.
558
539
uint64_t next_module_start_address = llvm::alignTo (module_end_address, 8 );
@@ -566,18 +547,18 @@ LLDBMemoryReader::addModuleToAddressMap(ModuleSP module,
566
547
567
548
std::optional<std::pair<uint64_t , lldb::ModuleSP>>
568
549
LLDBMemoryReader::getFileAddressAndModuleForTaggedAddress (
569
- uint64_t tagged_address) const {
550
+ swift::remote::RemoteAddress tagged_address) const {
570
551
Log *log (GetLog (LLDBLog::Types));
571
552
572
553
if (!readMetadataFromFileCacheEnabled ())
573
554
return {};
574
555
575
- // If the address contains our mask, this is an image we registered.
576
- if (!(tagged_address & LLDB_FILE_ADDRESS_BIT))
556
+ if (tagged_address.getAddressSpace () != LLDBAddressSpace)
577
557
return {};
578
558
579
559
// Dummy pair with the address we're looking for.
580
- auto comparison_pair = std::make_pair (tagged_address, ModuleSP ());
560
+ auto comparison_pair =
561
+ std::make_pair (tagged_address.getRawAddress (), ModuleSP ());
581
562
582
563
// Explicitly compare only the addresses, never the modules in the pairs.
583
564
auto pair_iterator = std::lower_bound (
@@ -589,7 +570,7 @@ LLDBMemoryReader::getFileAddressAndModuleForTaggedAddress(
589
570
LLDB_LOG (log,
590
571
" [MemoryReader] Address {0:x} is larger than the upper bound "
591
572
" address of the mapped in modules" ,
592
- tagged_address);
573
+ tagged_address. getRawAddress () );
593
574
return {};
594
575
}
595
576
@@ -601,14 +582,13 @@ LLDBMemoryReader::getFileAddressAndModuleForTaggedAddress(
601
582
}
602
583
uint64_t file_address;
603
584
if (pair_iterator == m_range_module_map.begin ())
604
- // Since this is the first registered module,
605
- // clearing the tag bit will give the virtual file address.
606
- file_address = tagged_address & ~LLDB_FILE_ADDRESS_BIT;
585
+ file_address = tagged_address.getRawAddress ();
607
586
else
608
587
// The end of the previous section is the start of the current one.
609
588
// We also need to add the first section's file address since we remove it
610
589
// when constructing the range to module map.
611
- file_address = tagged_address - std::prev (pair_iterator)->first ;
590
+ file_address =
591
+ (tagged_address - std::prev (pair_iterator)->first ).getRawAddress ();
612
592
613
593
// We also need to add the module's file address, since we subtract it when
614
594
// building the range to module map.
@@ -620,27 +600,28 @@ std::optional<swift::reflection::RemoteAddress>
620
600
LLDBMemoryReader::resolveRemoteAddress (
621
601
swift::reflection::RemoteAddress address) const {
622
602
std::optional<Address> lldb_address =
623
- LLDBMemoryReader::resolveRemoteAddress (address. getRawAddress () );
603
+ LLDBMemoryReader::remoteAddressToLLDBAddress (address);
624
604
if (!lldb_address)
625
605
return {};
626
606
lldb::addr_t addr = lldb_address->GetLoadAddress (&m_process.GetTarget ());
627
607
if (addr != LLDB_INVALID_ADDRESS)
628
- return swift::reflection::RemoteAddress (addr, swift::reflection::RemoteAddress::DefaultAddressSpace);
608
+ return swift::reflection::RemoteAddress (
609
+ addr, swift::reflection::RemoteAddress::DefaultAddressSpace);
629
610
return {};
630
611
}
631
612
632
- std::optional<Address>
633
- LLDBMemoryReader::resolveRemoteAddress ( uint64_t address) const {
613
+ std::optional<Address> LLDBMemoryReader::remoteAddressToLLDBAddress (
614
+ swift::remote::RemoteAddress address) const {
634
615
Log *log (GetLog (LLDBLog::Types));
635
616
auto maybe_pair = getFileAddressAndModuleForTaggedAddress (address);
636
617
if (!maybe_pair)
637
- return Address (address);
618
+ return Address (address. getRawAddress () );
638
619
639
620
uint64_t file_address = maybe_pair->first ;
640
621
ModuleSP module = maybe_pair->second ;
641
622
642
623
if (m_modules_with_metadata_in_symbol_obj_file.count (module ))
643
- return Address (address);
624
+ return Address (address. getRawAddress () );
644
625
645
626
auto *object_file = module ->GetObjectFile ();
646
627
if (!object_file)
@@ -656,7 +637,7 @@ LLDBMemoryReader::resolveRemoteAddress(uint64_t address) const {
656
637
LLDB_LOGV (log,
657
638
" [MemoryReader] Successfully resolved mapped address {0:x} into "
658
639
" file address {1:x}" ,
659
- address, resolved.GetFileAddress ());
640
+ address. getRawAddress () , resolved.GetFileAddress ());
660
641
return resolved;
661
642
}
662
643
auto *sec_list = module ->GetSectionList ();
@@ -700,7 +681,7 @@ LLDBMemoryReader::resolveRemoteAddress(uint64_t address) const {
700
681
701
682
std::optional<Address>
702
683
LLDBMemoryReader::resolveRemoteAddressFromSymbolObjectFile (
703
- uint64_t address) const {
684
+ swift::remote::RemoteAddress address) const {
704
685
Log *log (GetLog (LLDBLog::Types));
705
686
706
687
if (!m_process.GetTarget ().GetSwiftReadMetadataFromDSYM ())
@@ -744,7 +725,7 @@ LLDBMemoryReader::resolveRemoteAddressFromSymbolObjectFile(
744
725
LLDB_LOGV (log,
745
726
" [MemoryReader] Successfully resolved mapped address {0:x} into "
746
727
" file address {1:x} from symbol object file." ,
747
- address, file_address);
728
+ address. getRawAddress () , file_address);
748
729
return resolved;
749
730
}
750
731
0 commit comments