Skip to content

Commit

Permalink
[lldb] Make ReadCStringFromMemory default to read from the file-cache.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D118265
  • Loading branch information
augusto2112 committed Jan 28, 2022
1 parent a9d5bb9 commit b414954
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lldb/include/lldb/Target/Target.h
Expand Up @@ -1019,10 +1019,11 @@ class Target : public std::enable_shared_from_this<Target>,
lldb::addr_t *load_addr_ptr = nullptr);

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

size_t ReadCStringFromMemory(const Address &addr, char *dst,
size_t dst_max_len, Status &result_error);
size_t dst_max_len, Status &result_error,
bool force_live_memory = false);

/// Read a NULL terminated string from memory
///
Expand Down
12 changes: 7 additions & 5 deletions lldb/source/Target/Target.cpp
Expand Up @@ -1829,13 +1829,14 @@ size_t Target::ReadMemory(const Address &addr, void *dst, size_t dst_len,
}

size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str,
Status &error) {
Status &error, bool force_live_memory) {
char buf[256];
out_str.clear();
addr_t curr_addr = addr.GetLoadAddress(this);
Address address(addr);
while (true) {
size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error);
size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error,
force_live_memory);
if (length == 0)
break;
out_str.append(buf, length);
Expand All @@ -1851,7 +1852,8 @@ size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str,
}

size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
size_t dst_max_len, Status &result_error) {
size_t dst_max_len, Status &result_error,
bool force_live_memory) {
size_t total_cstr_len = 0;
if (dst && dst_max_len) {
result_error.Clear();
Expand All @@ -1874,8 +1876,8 @@ size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
cache_line_size - (curr_addr % cache_line_size);
addr_t bytes_to_read =
std::min<addr_t>(bytes_left, cache_line_bytes_left);
size_t bytes_read =
ReadMemory(address, curr_dst, bytes_to_read, error, true);
size_t bytes_read = ReadMemory(address, curr_dst, bytes_to_read, error,
force_live_memory);

if (bytes_read == 0) {
result_error = error;
Expand Down

0 comments on commit b414954

Please sign in to comment.