[lldb] Add an extra optional did_read_live_memory to Target::ReadMemory#149620
Merged
augusto2112 merged 1 commit intollvm:mainfrom Jul 21, 2025
Merged
[lldb] Add an extra optional did_read_live_memory to Target::ReadMemory#149620augusto2112 merged 1 commit intollvm:mainfrom
augusto2112 merged 1 commit intollvm:mainfrom
Conversation
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.
Member
|
@llvm/pr-subscribers-lldb Author: Augusto Noronha (augusto2112) ChangesTarget::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. Full diff: https://github.com/llvm/llvm-project/pull/149620.diff 3 Files Affected:
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<Target>,
// 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());
|
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Jul 28, 2025
…ry (llvm#149620) 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.