emrekultursay created this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits. emrekultursay updated this revision to Diff 252675. emrekultursay added a comment. emrekultursay updated this revision to Diff 252677.
No changes emrekultursay added a comment. Adding 3rd commit to diff ...and replace it with m_last_file_spec instead. When Source Cache is enabled, the value stored in m_last_file_sp is already in the Source Cache, and caching it again in SourceManager brings no extra benefit. All we need is to "remember" the last used file, and FileSpec can serve the same purpose. When Source Cache is disabled, the user explicitly requested no caching of source files, and therefore, m_last_file_sp should NOT be used. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D76803 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/SourceManager.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 @@ -52,27 +52,21 @@ // SourceManager constructor SourceManager::SourceManager(const TargetSP &target_sp) - : m_last_file_sp(), m_last_line(0), m_last_count(0), m_default_set(false), + : m_last_line(0), m_last_count(0), m_default_set(false), m_target_wp(target_sp), m_debugger_wp(target_sp->GetDebugger().shared_from_this()) {} SourceManager::SourceManager(const DebuggerSP &debugger_sp) - : m_last_file_sp(), m_last_line(0), m_last_count(0), m_default_set(false), + : m_last_line(0), m_last_count(0), m_default_set(false), m_target_wp(), m_debugger_wp(debugger_sp) {} // Destructor SourceManager::~SourceManager() {} SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) { - bool same_as_previous = - m_last_file_sp && - FileSpec::Match(file_spec, m_last_file_sp->GetFileSpec()); - DebuggerSP debugger_sp(m_debugger_wp.lock()); FileSP file_sp; - if (same_as_previous) - file_sp = m_last_file_sp; - else if (debugger_sp) + if (debugger_sp && debugger_sp->GetUseSourceCache()) file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(file_spec); TargetSP target_sp(m_target_wp.lock()); @@ -95,7 +89,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; @@ -178,10 +172,11 @@ m_last_line = start_line; m_last_count = count; - if (m_last_file_sp.get()) { + FileSP last_file_sp(GetFile(m_last_file_spec)); + if (last_file_sp.get()) { const uint32_t end_line = start_line + count - 1; for (uint32_t line = start_line; line <= end_line; ++line) { - if (!m_last_file_sp->LineIsValid(line)) { + if (!last_file_sp->LineIsValid(line)) { m_last_line = UINT32_MAX; break; } @@ -219,12 +214,12 @@ columnToHighlight = column - 1; size_t this_line_size = - m_last_file_sp->DisplaySourceLines(line, columnToHighlight, 0, 0, s); + last_file_sp->DisplaySourceLines(line, columnToHighlight, 0, 0, s); if (column != 0 && line == curr_line && should_show_stop_column_with_caret(debugger_sp)) { // Display caret cursor. std::string src_line; - m_last_file_sp->GetLine(line, src_line); + last_file_sp->GetLine(line, src_line); s->Printf(" \t"); // Insert a space for every non-tab character in the source line. for (size_t i = 0; i + 1 < column && i < src_line.length(); ++i) @@ -255,10 +250,11 @@ else start_line = 1; - if (m_last_file_sp.get() != file_sp.get()) { + FileSP last_file_sp(GetFile(m_last_file_spec)); + if (last_file_sp.get() != file_sp.get()) { if (line == 0) m_last_line = 0; - m_last_file_sp = file_sp; + m_last_file_spec = file_spec; } return DisplaySourceLinesWithLineNumbersUsingLastFile( start_line, count, line, column, current_line_cstr, s, bp_locs); @@ -268,14 +264,15 @@ Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs) { // If we get called before anybody has set a default file and line, then try // to figure it out here. - const bool have_default_file_line = m_last_file_sp && m_last_line > 0; + FileSP last_file_sp(GetFile(m_last_file_spec)); + const bool have_default_file_line = last_file_sp && m_last_line > 0; if (!m_default_set) { FileSpec tmp_spec; uint32_t tmp_line; GetDefaultFileAndLine(tmp_spec, tmp_line); } - if (m_last_file_sp) { + if (last_file_sp) { if (m_last_line == UINT32_MAX) return 0; @@ -310,22 +307,22 @@ bool SourceManager::SetDefaultFileAndLine(const FileSpec &file_spec, uint32_t line) { - FileSP old_file_sp = m_last_file_sp; - m_last_file_sp = GetFile(file_spec); - m_default_set = true; - if (m_last_file_sp) { + FileSP file_sp(GetFile(file_spec)); + + if (file_sp) { m_last_line = line; + m_last_file_spec = file_spec; return true; } else { - m_last_file_sp = old_file_sp; return false; } } bool SourceManager::GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line) { - if (m_last_file_sp) { - file_spec = m_last_file_sp->GetFileSpec(); + FileSP last_file_sp(GetFile(m_last_file_spec)); + if (last_file_sp) { + file_spec = last_file_sp->GetFileSpec(); line = m_last_line; return true; } else if (!m_default_set) { @@ -355,7 +352,7 @@ .GetBaseAddress() .CalculateSymbolContextLineEntry(line_entry)) { SetDefaultFileAndLine(line_entry.file, line_entry.line); - file_spec = m_last_file_sp->GetFileSpec(); + file_spec = last_file_sp->GetFileSpec(); line = m_last_line; return true; } @@ -696,7 +693,7 @@ } void SourceManager::SourceFileCache::AddSourceFile(const FileSP &file_sp) { - FileSpec file_spec; + FileSpec file_spec = file_sp->GetFileSpec();; FileCache::iterator pos = m_file_cache.find(file_spec); if (pos == m_file_cache.end()) m_file_cache[file_spec] = 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/SourceManager.h =================================================================== --- lldb/include/lldb/Core/SourceManager.h +++ lldb/include/lldb/Core/SourceManager.h @@ -116,7 +116,7 @@ ~SourceManager(); - FileSP GetLastFile() { return m_last_file_sp; } + FileSP GetLastFile() { return GetFile(m_last_file_spec); } size_t DisplaySourceLinesWithLineNumbers(const FileSpec &file, uint32_t line, @@ -138,7 +138,7 @@ bool GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line); - bool DefaultFileAndLineSet() { return (m_last_file_sp.get() != nullptr); } + bool DefaultFileAndLineSet() { return (GetFile(m_last_file_spec).get() != nullptr); } void FindLinesMatchingRegex(FileSpec &file_spec, RegularExpression ®ex, uint32_t start_line, uint32_t end_line, @@ -147,7 +147,7 @@ FileSP GetFile(const FileSpec &file_spec); protected: - FileSP m_last_file_sp; + FileSpec m_last_file_spec; uint32_t m_last_line; uint32_t m_last_count; bool m_default_set; 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