Skip to content

Commit 4f1fbf7

Browse files
augusto2112mahesh-attarde
authored andcommitted
[lldb] Add an extra optional did_read_live_memory to Target::ReadMemory (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.
1 parent c8870d2 commit 4f1fbf7

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,10 +1110,16 @@ class Target : public std::enable_shared_from_this<Target>,
11101110
// 2 - if there is a process, then read from memory
11111111
// 3 - if there is no process, then read from the file cache
11121112
//
1113+
// If did_read_live_memory is provided, will indicate if the read was from
1114+
// live memory, or from file contents. A caller which needs to treat these two
1115+
// sources differently should use this argument to disambiguate where the data
1116+
// was read from.
1117+
//
11131118
// The method is virtual for mocking in the unit tests.
11141119
virtual size_t ReadMemory(const Address &addr, void *dst, size_t dst_len,
11151120
Status &error, bool force_live_memory = false,
1116-
lldb::addr_t *load_addr_ptr = nullptr);
1121+
lldb::addr_t *load_addr_ptr = nullptr,
1122+
bool *did_read_live_memory = nullptr);
11171123

11181124
size_t ReadCStringFromMemory(const Address &addr, std::string &out_str,
11191125
Status &error, bool force_live_memory = false);

lldb/source/Target/Target.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,8 +1987,11 @@ size_t Target::ReadMemoryFromFileCache(const Address &addr, void *dst,
19871987

19881988
size_t Target::ReadMemory(const Address &addr, void *dst, size_t dst_len,
19891989
Status &error, bool force_live_memory,
1990-
lldb::addr_t *load_addr_ptr) {
1990+
lldb::addr_t *load_addr_ptr,
1991+
bool *did_read_live_memory) {
19911992
error.Clear();
1993+
if (did_read_live_memory)
1994+
*did_read_live_memory = false;
19921995

19931996
Address fixed_addr = addr;
19941997
if (ProcessIsValid())
@@ -2086,6 +2089,8 @@ size_t Target::ReadMemory(const Address &addr, void *dst, size_t dst_len,
20862089
if (bytes_read) {
20872090
if (load_addr_ptr)
20882091
*load_addr_ptr = load_addr;
2092+
if (did_read_live_memory)
2093+
*did_read_live_memory = true;
20892094
return bytes_read;
20902095
}
20912096
}

lldb/unittests/Expression/DWARFExpressionTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class MockTarget : public Target {
111111

112112
size_t ReadMemory(const Address &addr, void *dst, size_t dst_len,
113113
Status &error, bool force_live_memory = false,
114-
lldb::addr_t *load_addr_ptr = nullptr) /*override*/ {
114+
lldb::addr_t *load_addr_ptr = nullptr,
115+
bool *did_read_live_memory = nullptr) /*override*/ {
115116
auto expected_memory = this->ReadMemory(addr.GetOffset(), dst_len);
116117
if (!expected_memory) {
117118
llvm::consumeError(expected_memory.takeError());

0 commit comments

Comments
 (0)