From 319a34e6f31c7a8bf904294620286cc621aa8cc0 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Fri, 18 Jul 2025 16:51:08 -0700 Subject: [PATCH] [lldb] Add an extra optional did_read_live_memory to Target::ReadMemory Target::ReadMemory may or may not read live memory, but whether it did read from live memory or from the filecache is opaque to callers. Add an extra out parameter to indicate whether live memory was read or not. --- lldb/include/lldb/Target/Target.h | 8 +++++++- lldb/source/Target/Target.cpp | 7 ++++++- lldb/unittests/Expression/DWARFExpressionTest.cpp | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index a1d881375b08b..7b23c8abe8d2f 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -1110,10 +1110,16 @@ class Target : public std::enable_shared_from_this, // 2 - if there is a process, then read from memory // 3 - if there is no process, then read from the file cache // + // If did_read_live_memory is provided, will indicate if the read was from + // live memory, or from file contents. A caller which needs to treat these two + // sources differently should use this argument to disambiguate where the data + // was read from. + // // The method is virtual for mocking in the unit tests. virtual size_t ReadMemory(const Address &addr, void *dst, size_t dst_len, Status &error, bool force_live_memory = false, - lldb::addr_t *load_addr_ptr = nullptr); + lldb::addr_t *load_addr_ptr = nullptr, + bool *did_read_live_memory = nullptr); size_t ReadCStringFromMemory(const Address &addr, std::string &out_str, Status &error, bool force_live_memory = false); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 7f569173eba20..86ae7dd29b764 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1987,8 +1987,11 @@ size_t Target::ReadMemoryFromFileCache(const Address &addr, void *dst, size_t Target::ReadMemory(const Address &addr, void *dst, size_t dst_len, Status &error, bool force_live_memory, - lldb::addr_t *load_addr_ptr) { + lldb::addr_t *load_addr_ptr, + bool *did_read_live_memory) { error.Clear(); + if (did_read_live_memory) + *did_read_live_memory = false; Address fixed_addr = addr; if (ProcessIsValid()) @@ -2086,6 +2089,8 @@ size_t Target::ReadMemory(const Address &addr, void *dst, size_t dst_len, if (bytes_read) { if (load_addr_ptr) *load_addr_ptr = load_addr; + if (did_read_live_memory) + *did_read_live_memory = true; return bytes_read; } } diff --git a/lldb/unittests/Expression/DWARFExpressionTest.cpp b/lldb/unittests/Expression/DWARFExpressionTest.cpp index fdc9bfae1876c..3c4c496889fca 100644 --- a/lldb/unittests/Expression/DWARFExpressionTest.cpp +++ b/lldb/unittests/Expression/DWARFExpressionTest.cpp @@ -111,7 +111,8 @@ class MockTarget : public Target { size_t ReadMemory(const Address &addr, void *dst, size_t dst_len, Status &error, bool force_live_memory = false, - lldb::addr_t *load_addr_ptr = nullptr) /*override*/ { + lldb::addr_t *load_addr_ptr = nullptr, + bool *did_read_live_memory = nullptr) /*override*/ { auto expected_memory = this->ReadMemory(addr.GetOffset(), dst_len); if (!expected_memory) { llvm::consumeError(expected_memory.takeError());