[Lldb-commits] [lldb] [lldb] Support partial memory reads on windows (PR #106981)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 2 08:05:49 PDT 2024
================
@@ -276,16 +276,29 @@ Status ProcessDebugger::ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
LLDB_LOG(log, "attempting to read {0} bytes from address {1:x}", size,
vm_addr);
- HostProcess process = m_session_data->m_debugger->GetProcess();
+ lldb::process_t handle = m_session_data->m_debugger->GetProcess()
+ .GetNativeProcess()
+ .GetSystemHandle();
void *addr = reinterpret_cast<void *>(vm_addr);
SIZE_T num_of_bytes_read = 0;
- if (!::ReadProcessMemory(process.GetNativeProcess().GetSystemHandle(), addr,
- buf, size, &num_of_bytes_read)) {
- error = Status(GetLastError(), eErrorTypeWin32);
- LLDB_LOG(log, "reading failed with error: {0}", error);
- } else {
+ if (::ReadProcessMemory(handle, addr, buf, size, &num_of_bytes_read)) {
+ bytes_read = num_of_bytes_read;
+ return Status();
+ }
+ error = Status(GetLastError(), eErrorTypeWin32);
+ MemoryRegionInfo info;
+ if (GetMemoryRegionInfo(vm_addr, info).Fail() ||
----------------
DavidSpickett wrote:
I'm wondering what happens if the read goes across multiple memory regions then fails. For example:
```
region 1
region 2
<unmapped> <<< want to read into this region.
```
We will read region 1, 2 and then fail. vm_addr still points to the start of region 1 so we'll return only the contents of region 1, but we could have read region 2 as well.
I had to do something like this for memory tagging in `MemoryTagManagerAArch64MTE::MakeTaggedRange` which checks that all the memory regions in a range are memory tagged.
Or perhaps you:
1. Want to avoid the complication of that at this time
2. Know that memory reads here won't span a memory region so you don't need to bother
https://github.com/llvm/llvm-project/pull/106981
More information about the lldb-commits
mailing list