Skip to content

Commit fff2b06

Browse files
committed
[lldb] Fix slide calculation in LLDBMemoryReader
The slide calculation was incorrectly negating an unsigned integer and passing it to a call to SaturatingAdd. The section load address should always be larger than the section file address, so change the underflow check to a comparison instead. (cherry picked from commit 61f28df)
1 parent 0ffc76a commit fff2b06

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -643,17 +643,17 @@ LLDBMemoryReader::resolveRemoteAddress(uint64_t address) const {
643643
auto sec_file_address = sec->GetFileAddress();
644644
auto sec_load_address = sec->GetLoadBaseAddress(&m_process.GetTarget());
645645

646-
bool overflow = false;
647-
auto slide =
648-
llvm::SaturatingAdd(sec_load_address, -sec_file_address, &overflow);
649-
if (overflow) {
646+
if (sec_load_address < sec_file_address) {
650647
LLDB_LOG(log,
651-
"[MemoryReader] section load address {0:x} - file address {1:x} "
652-
"overflows",
648+
"[MemoryReader] section load address {0:x} is smaller than "
649+
"section file address {1:x}",
653650
sec_load_address, sec_file_address);
654651
return {};
655652
}
656653

654+
auto slide = sec_load_address - sec_file_address;
655+
656+
bool overflow = false;
657657
auto virtual_address = llvm::SaturatingAdd(file_address, slide, &overflow);
658658
if (overflow) {
659659
LLDB_LOG(log, "[MemoryReader] file address {0:x} + slide {1:x} overflows",

0 commit comments

Comments
 (0)