diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -231,6 +231,11 @@ bool GetDebugUtilityExpression() const; + bool GetFetchReadonlySectionsFromFileCache() const; + + void SetFetchReadonlySectionsFromFileCache(bool b); + + private: // Callbacks for m_launch_info. void Arg0ValueChangedCallback(); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1753,6 +1753,15 @@ if (!resolved_addr.IsValid()) resolved_addr = addr; + if (GetFetchReadonlySectionsFromFileCache()) { + SectionSP section_sp(addr.GetSection()); + if (section_sp) { + auto permissions = section_sp->GetPermissions(); + prefer_file_cache |= (permissions & ePermissionsWritable) == 0 && + (permissions & ePermissionsReadable) == 1; + } + } + if (prefer_file_cache) { bytes_read = ReadMemoryFromFileCache(resolved_addr, dst, dst_len, error); if (bytes_read > 0) @@ -4355,6 +4364,17 @@ m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, debug); } +bool TargetProperties::GetFetchReadonlySectionsFromFileCache() const { + const uint32_t idx = ePropertyFetchReadonlySectionsFromFileCache; + return m_collection_sp->GetPropertyAtIndexAsBoolean( + nullptr, idx, g_target_properties[idx].default_uint_value != 0); +} + +void TargetProperties::SetFetchReadonlySectionsFromFileCache(bool b) { + const uint32_t idx = ePropertyFetchReadonlySectionsFromFileCache; + m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); +} + // Target::TargetEventData Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp) diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -175,6 +175,9 @@ def DebugUtilityExpression: Property<"debug-utility-expression", "Boolean">, DefaultFalse, Desc<"Enable debugging of LLDB-internal utility expressions.">; + def FetchReadonlySectionsFromFileCache: Property<"fetch-readonly-sections-from-file-cache", "Boolean">, + DefaultTrue, + Desc<"Enables reading bytes from the file cache instead of process when the address LLDB is reading from falls in a readable but not writable section">; } let Definition = "process_experimental" in {