@@ -619,18 +619,54 @@ LLDBMemoryReader::resolveRemoteAddress(uint64_t address) const {
619
619
return {};
620
620
621
621
Address resolved (file_address, object_file->GetSectionList ());
622
- if (!resolved.IsValid ()) {
622
+
623
+ // If the address doesn't have a section it means we couldn't find a section
624
+ // that contains that file address, and the "resolved" instance is wrong.
625
+ // Calculate the virtual address by finding out the slide of the associated
626
+ // module, and adding that to the file address.
627
+ if (resolved.GetSection ()) {
628
+ LLDB_LOGV (log,
629
+ " [MemoryReader] Successfully resolved mapped address {0:x} into "
630
+ " file address {1:x}" ,
631
+ address, resolved.GetFileAddress ());
632
+ return resolved;
633
+ }
634
+ auto *sec_list = module ->GetSectionList ();
635
+ if (sec_list->GetSize () == 0 ) {
623
636
LLDB_LOG (log,
624
- " [MemoryReader] Could not make a real address out of file address "
625
- " {0:x} and object file {1}" ,
637
+ " [MemoryReader] Could not calculate virtual address from file "
638
+ " address {0:x}, no sections in {1}" ,
626
639
file_address, object_file->GetFileSpec ().GetFilename ());
627
640
return {};
628
641
}
642
+ auto sec = sec_list->GetSectionAtIndex (0 );
643
+ auto sec_file_address = sec->GetFileAddress ();
644
+ auto sec_load_address = sec->GetLoadBaseAddress (&m_process.GetTarget ());
629
645
646
+ bool overflow = false ;
647
+ auto slide =
648
+ llvm::SaturatingAdd (sec_load_address, -sec_file_address, &overflow);
649
+ if (overflow) {
650
+ LLDB_LOG (log,
651
+ " [MemoryReader] section load address {0:x} - file address {1:x} "
652
+ " overflows" ,
653
+ sec_load_address, sec_file_address);
654
+ return {};
655
+ }
656
+
657
+ auto virtual_address = llvm::SaturatingAdd (file_address, slide, &overflow);
658
+ if (overflow) {
659
+ LLDB_LOG (log, " [MemoryReader] file address {0:x} + slide {1:x} overflows" ,
660
+ sec_load_address, sec_file_address);
661
+ return {};
662
+ }
663
+
664
+ resolved = Address (virtual_address);
630
665
LLDB_LOGV (log,
631
- " [MemoryReader] Successfully resolved mapped address {0:x} into "
632
- " file address {1:x}" ,
633
- address, resolved.GetFileAddress ());
666
+ " [MemoryReader] Could not find section with file address {0:x} "
667
+ " and file {1}, resolved it into virtual address {2:x}" ,
668
+ file_address, object_file->GetFileSpec ().GetFilename (),
669
+ virtual_address);
634
670
return resolved;
635
671
}
636
672
0 commit comments