Skip to content

[lldb] Add an extra optional did_read_live_memory to Target::ReadMemory #149620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lldb/unittests/Expression/DWARFExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading