emrekultursay created this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits. emrekultursay added a child revision: D76805: Fix SourceManager::SourceFileCache insertion.
LLDB memory-maps large source files, and at the same time, caches all source files in the Source Cache. On Windows, memory-mapped source files are not writeable, causing bad user experience in IDEs (such as errors when saving edited files). IDEs should have the ability to disable the Source Cache at LLDB startup, so that users can edit source files while debugging. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D76804 Files: lldb/include/lldb/Core/Debugger.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/SourceManager.cpp Index: lldb/source/Core/SourceManager.cpp =================================================================== --- lldb/source/Core/SourceManager.cpp +++ lldb/source/Core/SourceManager.cpp @@ -72,7 +72,7 @@ FileSP file_sp; if (same_as_previous) file_sp = m_last_file_sp; - else if (debugger_sp) + else if (debugger_sp && debugger_sp->GetUseSourceCache()) file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(file_spec); TargetSP target_sp(m_target_wp.lock()); @@ -95,7 +95,7 @@ else file_sp = std::make_shared<File>(file_spec, debugger_sp); - if (debugger_sp) + if (debugger_sp && debugger_sp->GetUseSourceCache()) debugger_sp->GetSourceFileCache().AddSourceFile(file_sp); } return file_sp; Index: lldb/source/Core/Debugger.cpp =================================================================== --- lldb/source/Core/Debugger.cpp +++ lldb/source/Core/Debugger.cpp @@ -338,6 +338,18 @@ return ret; } +bool Debugger::GetUseSourceCache() const { + const uint32_t idx = ePropertyUseSourceCache; + return m_collection_sp->GetPropertyAtIndexAsBoolean( + nullptr, idx, g_debugger_properties[idx].default_uint_value != 0); +} + +bool Debugger::SetUseSourceCache(bool b) { + const uint32_t idx = ePropertyUseSourceCache; + bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); + SetPrompt(GetPrompt()); + return ret; +} bool Debugger::GetHighlightSource() const { const uint32_t idx = ePropertyHighlightSource; return m_collection_sp->GetPropertyAtIndexAsBoolean( Index: lldb/source/Core/CoreProperties.td =================================================================== --- lldb/source/Core/CoreProperties.td +++ lldb/source/Core/CoreProperties.td @@ -103,6 +103,10 @@ Global, DefaultTrue, Desc<"Whether to use Ansi color codes or not.">; + def UseSourceCache: Property<"use-source-cache", "Boolean">, + Global, + DefaultTrue, + Desc<"Whether to cache source files in memory or not.">; def AutoOneLineSummaries: Property<"auto-one-line-summaries", "Boolean">, Global, DefaultTrue, Index: lldb/include/lldb/Core/Debugger.h =================================================================== --- lldb/include/lldb/Core/Debugger.h +++ lldb/include/lldb/Core/Debugger.h @@ -273,6 +273,10 @@ bool SetUseColor(bool use_color); + bool GetUseSourceCache() const; + + bool SetUseSourceCache(bool use_source_cache); + bool GetHighlightSource() const; lldb::StopShowColumn GetStopShowColumn() const;
Index: lldb/source/Core/SourceManager.cpp =================================================================== --- lldb/source/Core/SourceManager.cpp +++ lldb/source/Core/SourceManager.cpp @@ -72,7 +72,7 @@ FileSP file_sp; if (same_as_previous) file_sp = m_last_file_sp; - else if (debugger_sp) + else if (debugger_sp && debugger_sp->GetUseSourceCache()) file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(file_spec); TargetSP target_sp(m_target_wp.lock()); @@ -95,7 +95,7 @@ else file_sp = std::make_shared<File>(file_spec, debugger_sp); - if (debugger_sp) + if (debugger_sp && debugger_sp->GetUseSourceCache()) debugger_sp->GetSourceFileCache().AddSourceFile(file_sp); } return file_sp; Index: lldb/source/Core/Debugger.cpp =================================================================== --- lldb/source/Core/Debugger.cpp +++ lldb/source/Core/Debugger.cpp @@ -338,6 +338,18 @@ return ret; } +bool Debugger::GetUseSourceCache() const { + const uint32_t idx = ePropertyUseSourceCache; + return m_collection_sp->GetPropertyAtIndexAsBoolean( + nullptr, idx, g_debugger_properties[idx].default_uint_value != 0); +} + +bool Debugger::SetUseSourceCache(bool b) { + const uint32_t idx = ePropertyUseSourceCache; + bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); + SetPrompt(GetPrompt()); + return ret; +} bool Debugger::GetHighlightSource() const { const uint32_t idx = ePropertyHighlightSource; return m_collection_sp->GetPropertyAtIndexAsBoolean( Index: lldb/source/Core/CoreProperties.td =================================================================== --- lldb/source/Core/CoreProperties.td +++ lldb/source/Core/CoreProperties.td @@ -103,6 +103,10 @@ Global, DefaultTrue, Desc<"Whether to use Ansi color codes or not.">; + def UseSourceCache: Property<"use-source-cache", "Boolean">, + Global, + DefaultTrue, + Desc<"Whether to cache source files in memory or not.">; def AutoOneLineSummaries: Property<"auto-one-line-summaries", "Boolean">, Global, DefaultTrue, Index: lldb/include/lldb/Core/Debugger.h =================================================================== --- lldb/include/lldb/Core/Debugger.h +++ lldb/include/lldb/Core/Debugger.h @@ -273,6 +273,10 @@ bool SetUseColor(bool use_color); + bool GetUseSourceCache() const; + + bool SetUseSourceCache(bool use_source_cache); + bool GetHighlightSource() const; lldb::StopShowColumn GetStopShowColumn() const;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits