[Lldb-commits] [lldb] r243551 - Centralize where we update the source file contents in SourceManager::GetFile() in case APIs are called that don't update the source.

Greg Clayton gclayton at apple.com
Wed Jul 29 11:37:25 PDT 2015


Author: gclayton
Date: Wed Jul 29 13:37:25 2015
New Revision: 243551

URL: http://llvm.org/viewvc/llvm-project?rev=243551&view=rev
Log:
Centralize where we update the source file contents in SourceManager::GetFile() in case APIs are called that don't update the source.

The following functions were the only functions that updates the source file:

SourceManager::File::DisplaySourceLines()
SourceManager::File::FindLinesMatchingRegex()    

But there we API calls that were using the SourceManager::File and asking it questions, like "is line 12 valid" and that might respond incorrectly if the source file had been updated.

<rdar://problem/21269402>


Modified:
    lldb/trunk/include/lldb/Core/SourceManager.h
    lldb/trunk/source/Core/SourceManager.cpp

Modified: lldb/trunk/include/lldb/Core/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/SourceManager.h?rev=243551&r1=243550&r2=243551&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/SourceManager.h (original)
+++ lldb/trunk/include/lldb/Core/SourceManager.h Wed Jul 29 13:37:25 2015
@@ -35,6 +35,9 @@ public:
         File (const FileSpec &file_spec, Target *target);
         ~File();
 
+        void
+        UpdateIfNeeded ();
+
         size_t
         DisplaySourceLines (uint32_t line,
                             uint32_t context_before,

Modified: lldb/trunk/source/Core/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SourceManager.cpp?rev=243551&r1=243550&r2=243551&view=diff
==============================================================================
--- lldb/trunk/source/Core/SourceManager.cpp (original)
+++ lldb/trunk/source/Core/SourceManager.cpp Wed Jul 29 13:37:25 2015
@@ -83,6 +83,10 @@ SourceManager::GetFile (const FileSpec &
     if (target_sp && file_sp && file_sp->GetSourceMapModificationID() != target_sp->GetSourcePathMap().GetModificationID())
         file_sp.reset();
 
+    // Update the file contents if needed if we found a file
+    if (file_sp)
+        file_sp->UpdateIfNeeded();
+
     // If file_sp is no good or it points to a non-existent file, reset it.
     if (!file_sp || !file_sp->GetFileSpec().Exists())
     {
@@ -492,8 +496,8 @@ SourceManager::File::LineIsValid (uint32
     return false;
 }
 
-size_t
-SourceManager::File::DisplaySourceLines (uint32_t line, uint32_t context_before, uint32_t context_after, Stream *s)
+void
+SourceManager::File::UpdateIfNeeded ()
 {
     // TODO: use host API to sign up for file modifications to anything in our
     // source cache and only update when we determine a file has been updated.
@@ -506,7 +510,11 @@ SourceManager::File::DisplaySourceLines
         m_data_sp = m_file_spec.ReadFileContents ();
         m_offsets.clear();
     }
+}
 
+size_t
+SourceManager::File::DisplaySourceLines (uint32_t line, uint32_t context_before, uint32_t context_after, Stream *s)
+{
     // Sanity check m_data_sp before proceeding.
     if (!m_data_sp)
         return 0;
@@ -538,14 +546,6 @@ SourceManager::File::DisplaySourceLines
 void
 SourceManager::File::FindLinesMatchingRegex (RegularExpression& regex, uint32_t start_line, uint32_t end_line, std::vector<uint32_t> &match_lines)
 {
-    TimeValue curr_mod_time (m_file_spec.GetModificationTime());
-    if (m_mod_time != curr_mod_time)
-    {
-        m_mod_time = curr_mod_time;
-        m_data_sp = m_file_spec.ReadFileContents ();
-        m_offsets.clear();
-    }
-    
     match_lines.clear();
     
     if (!LineIsValid(start_line) || (end_line != UINT32_MAX && !LineIsValid(end_line)))





More information about the lldb-commits mailing list