Skip to content

Commit 0412b03

Browse files
authored
Merge pull request #3856 from augusto2112/read-cstrings-from-filecache-cherry-pick
[lldb] Make ReadCStringFromMemory default to read from the file-cache.
2 parents 684cc4f + 03a0435 commit 0412b03

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,10 +1069,11 @@ class Target : public std::enable_shared_from_this<Target>,
10691069
lldb::addr_t *load_addr_ptr = nullptr);
10701070

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

10741074
size_t ReadCStringFromMemory(const Address &addr, char *dst,
1075-
size_t dst_max_len, Status &result_error);
1075+
size_t dst_max_len, Status &result_error,
1076+
bool force_live_memory = false);
10761077

10771078
size_t ReadScalarIntegerFromMemory(const Address &addr, uint32_t byte_size,
10781079
bool is_signed, Scalar &scalar,

lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ bool LLDBMemoryReader::readString(swift::remote::RemoteAddress address,
244244

245245
Target &target(m_process.GetTarget());
246246
Status error;
247-
target.ReadCStringFromMemory(addr, dest, error);
247+
// We only want to allow the file-cache optimization if we resolved the
248+
// address to section + offset.
249+
const bool force_live_memory =
250+
!readMetadataFromFileCacheEnabled() || !addr.IsSectionOffset();
251+
target.ReadCStringFromMemory(addr, dest, error, force_live_memory);
248252
if (error.Success()) {
249253
auto format_string = [](const std::string &dest) {
250254
StreamString stream;

lldb/source/Target/Target.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,13 +1873,14 @@ size_t Target::ReadMemory(const Address &addr, void *dst, size_t dst_len,
18731873
}
18741874

18751875
size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str,
1876-
Status &error) {
1876+
Status &error, bool force_live_memory) {
18771877
char buf[256];
18781878
out_str.clear();
18791879
addr_t curr_addr = addr.GetLoadAddress(this);
18801880
Address address(addr);
18811881
while (true) {
1882-
size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error);
1882+
size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error,
1883+
force_live_memory);
18831884
if (length == 0)
18841885
break;
18851886
out_str.append(buf, length);
@@ -1895,7 +1896,8 @@ size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str,
18951896
}
18961897

18971898
size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
1898-
size_t dst_max_len, Status &result_error) {
1899+
size_t dst_max_len, Status &result_error,
1900+
bool force_live_memory) {
18991901
size_t total_cstr_len = 0;
19001902
if (dst && dst_max_len) {
19011903
result_error.Clear();
@@ -1918,8 +1920,8 @@ size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
19181920
cache_line_size - (curr_addr % cache_line_size);
19191921
addr_t bytes_to_read =
19201922
std::min<addr_t>(bytes_left, cache_line_bytes_left);
1921-
size_t bytes_read =
1922-
ReadMemory(address, curr_dst, bytes_to_read, error, true);
1923+
size_t bytes_read = ReadMemory(address, curr_dst, bytes_to_read, error,
1924+
force_live_memory);
19231925

19241926
if (bytes_read == 0) {
19251927
result_error = error;

0 commit comments

Comments
 (0)