mgorny created this revision. mgorny added reviewers: labath, emaste, krytarowski. Herald added a subscriber: arichardson. mgorny requested review of this revision.
Add a fallback to `GetFileAddress()` when `GetLoadAddress()` fails in `ReadMemory()`. This is consistent with how expression evaluation behaves, and fixes the inconsistency between the two following commands run on top of FreeBSD vmcore: - `p *(int *)&hz` (prints correct value) - `memory read &hz` (prints zeros) https://reviews.llvm.org/D114675 Files: lldb/source/Target/Target.cpp Index: lldb/source/Target/Target.cpp =================================================================== --- lldb/source/Target/Target.cpp +++ lldb/source/Target/Target.cpp @@ -1782,36 +1782,27 @@ if (ProcessIsValid()) { if (load_addr == LLDB_INVALID_ADDRESS) load_addr = resolved_addr.GetLoadAddress(this); - - if (load_addr == LLDB_INVALID_ADDRESS) { - ModuleSP addr_module_sp(resolved_addr.GetModule()); - if (addr_module_sp && addr_module_sp->GetFileSpec()) - error.SetErrorStringWithFormatv( - "{0:F}[{1:x+}] can't be resolved, {0:F} is not currently loaded", - addr_module_sp->GetFileSpec(), resolved_addr.GetFileAddress()); - else - error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", - resolved_addr.GetFileAddress()); - } else { - bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); - if (bytes_read != dst_len) { - if (error.Success()) { - if (bytes_read == 0) - error.SetErrorStringWithFormat( - "read memory from 0x%" PRIx64 " failed", load_addr); - else - error.SetErrorStringWithFormat( - "only %" PRIu64 " of %" PRIu64 - " bytes were read from memory at 0x%" PRIx64, - (uint64_t)bytes_read, (uint64_t)dst_len, load_addr); - } - } - if (bytes_read) { - if (load_addr_ptr) - *load_addr_ptr = load_addr; - return bytes_read; + if (load_addr == LLDB_INVALID_ADDRESS) + load_addr = resolved_addr.GetFileAddress(); + + bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); + if (bytes_read != dst_len) { + if (error.Success()) { + if (bytes_read == 0) + error.SetErrorStringWithFormat( + "read memory from 0x%" PRIx64 " failed", load_addr); + else + error.SetErrorStringWithFormat( + "only %" PRIu64 " of %" PRIu64 + " bytes were read from memory at 0x%" PRIx64, + (uint64_t)bytes_read, (uint64_t)dst_len, load_addr); } } + if (bytes_read) { + if (load_addr_ptr) + *load_addr_ptr = load_addr; + return bytes_read; + } } if (file_cache_read_buffer && file_cache_bytes_read > 0) {
Index: lldb/source/Target/Target.cpp =================================================================== --- lldb/source/Target/Target.cpp +++ lldb/source/Target/Target.cpp @@ -1782,36 +1782,27 @@ if (ProcessIsValid()) { if (load_addr == LLDB_INVALID_ADDRESS) load_addr = resolved_addr.GetLoadAddress(this); - - if (load_addr == LLDB_INVALID_ADDRESS) { - ModuleSP addr_module_sp(resolved_addr.GetModule()); - if (addr_module_sp && addr_module_sp->GetFileSpec()) - error.SetErrorStringWithFormatv( - "{0:F}[{1:x+}] can't be resolved, {0:F} is not currently loaded", - addr_module_sp->GetFileSpec(), resolved_addr.GetFileAddress()); - else - error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", - resolved_addr.GetFileAddress()); - } else { - bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); - if (bytes_read != dst_len) { - if (error.Success()) { - if (bytes_read == 0) - error.SetErrorStringWithFormat( - "read memory from 0x%" PRIx64 " failed", load_addr); - else - error.SetErrorStringWithFormat( - "only %" PRIu64 " of %" PRIu64 - " bytes were read from memory at 0x%" PRIx64, - (uint64_t)bytes_read, (uint64_t)dst_len, load_addr); - } - } - if (bytes_read) { - if (load_addr_ptr) - *load_addr_ptr = load_addr; - return bytes_read; + if (load_addr == LLDB_INVALID_ADDRESS) + load_addr = resolved_addr.GetFileAddress(); + + bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); + if (bytes_read != dst_len) { + if (error.Success()) { + if (bytes_read == 0) + error.SetErrorStringWithFormat( + "read memory from 0x%" PRIx64 " failed", load_addr); + else + error.SetErrorStringWithFormat( + "only %" PRIu64 " of %" PRIu64 + " bytes were read from memory at 0x%" PRIx64, + (uint64_t)bytes_read, (uint64_t)dst_len, load_addr); } } + if (bytes_read) { + if (load_addr_ptr) + *load_addr_ptr = load_addr; + return bytes_read; + } } if (file_cache_read_buffer && file_cache_bytes_read > 0) {
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits