Skip to content

[lldb] Make ReadCStringFromMemory default to read from the file-cache. #3856

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
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
5 changes: 3 additions & 2 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -1067,10 +1067,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);

size_t ReadScalarIntegerFromMemory(const Address &addr, uint32_t byte_size,
bool is_signed, Scalar &scalar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ bool LLDBMemoryReader::readString(swift::remote::RemoteAddress address,

Target &target(m_process.GetTarget());
Status error;
target.ReadCStringFromMemory(addr, dest, error);
// We only want to allow the file-cache optimization if we resolved the
// address to section + offset.
const bool force_live_memory =
!readMetadataFromFileCacheEnabled() || !addr.IsSectionOffset();
target.ReadCStringFromMemory(addr, dest, error, force_live_memory);
if (error.Success()) {
auto format_string = [](const std::string &dest) {
StreamString stream;
Expand Down
12 changes: 7 additions & 5 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,13 +1873,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 @@ -1895,7 +1896,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 @@ -1918,8 +1920,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