[Lldb-commits] [lldb] r177125 - <rdar://problem/12537646>

Greg Clayton gclayton at apple.com
Thu Mar 14 15:52:17 PDT 2013


Author: gclayton
Date: Thu Mar 14 17:52:17 2013
New Revision: 177125

URL: http://llvm.org/viewvc/llvm-project?rev=177125&view=rev
Log:
<rdar://problem/12537646>

lldb remembers not-found source file, setting target.source-map doesn't make it re-check for it. Now this is fixed. Each time the source path remappings get updated, the modification ID in the PathMappingList gets bumped and then we know the re-check for sources.


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

Modified: lldb/trunk/include/lldb/Core/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/SourceManager.h?rev=177125&r1=177124&r2=177125&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/SourceManager.h (original)
+++ lldb/trunk/include/lldb/Core/SourceManager.h Thu Mar 14 17:52:17 2013
@@ -64,6 +64,12 @@ public:
             return m_file_spec;
         }
         
+        uint32_t
+        GetSourceMapModificationID() const
+        {
+            return m_source_map_mod_id;
+        }
+        
     protected:
 
         bool
@@ -72,6 +78,7 @@ public:
         FileSpec m_file_spec_orig;  // The original file spec that was used (can be different from m_file_spec)
         FileSpec m_file_spec;       // The actualy file spec being used (if the target has source mappings, this might be different from m_file_spec_orig)
         TimeValue m_mod_time;       // Keep the modification time that this file data is valid for
+        uint32_t m_source_map_mod_id; // If the target uses path remappings, be sure to clear our notion of a source file if the path modification ID changes
         lldb::DataBufferSP m_data_sp;
         typedef std::vector<uint32_t> LineOffsets;
         LineOffsets m_offsets;

Modified: lldb/trunk/include/lldb/Target/PathMappingList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/PathMappingList.h?rev=177125&r1=177124&r2=177125&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/PathMappingList.h (original)
+++ lldb/trunk/include/lldb/Target/PathMappingList.h Thu Mar 14 17:52:17 2013
@@ -144,6 +144,11 @@ public:
     uint32_t
     FindIndexForPath (const ConstString &path) const;
 
+    uint32_t
+    GetModificationID() const
+    {
+        return m_mod_id;
+    }
 protected:
     typedef std::pair <ConstString, ConstString> pair;
     typedef std::vector <pair> collection;
@@ -159,6 +164,7 @@ protected:
     collection m_pairs;
     ChangedCallback m_callback;
     void * m_callback_baton;
+    uint32_t m_mod_id; // Incremented anytime anything is added or removed.
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Core/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SourceManager.cpp?rev=177125&r1=177124&r2=177125&view=diff
==============================================================================
--- lldb/trunk/source/Core/SourceManager.cpp (original)
+++ lldb/trunk/source/Core/SourceManager.cpp Thu Mar 14 17:52:17 2013
@@ -67,8 +67,19 @@ SourceManager::~SourceManager()
 SourceManager::FileSP
 SourceManager::GetFile (const FileSpec &file_spec)
 {
+    bool same_as_previous = m_last_file_sp && m_last_file_sp->FileSpecMatches (file_spec);
+
     FileSP file_sp;
-    file_sp = m_debugger->GetSourceFileCache().FindSourceFile (file_spec);
+    if (same_as_previous)
+        file_sp = m_last_file_sp;
+    else
+        file_sp = m_debugger->GetSourceFileCache().FindSourceFile (file_spec);
+    
+    // It the target source path map has been updated, get this file again so we
+    // can successfully remap the source file
+    if (file_sp && file_sp->GetSourceMapModificationID() != m_target->GetSourcePathMap().GetModificationID())
+        file_sp.reset();
+
     // If file_sp is no good or it points to a non-existent file, reset it.
     if (!file_sp || !file_sp->GetFileSpec().Exists())
     {
@@ -159,10 +170,7 @@ SourceManager::DisplaySourceLinesWithLin
     const SymbolContextList *bp_locs
 )
 {
-    bool same_as_previous = m_last_file_sp && m_last_file_sp->FileSpecMatches (file_spec);
-
-    if (!same_as_previous)
-        m_last_file_sp = GetFile (file_spec);
+    FileSP file_sp (GetFile (file_spec));
 
     uint32_t start_line;
     uint32_t count = context_before + context_after + 1;
@@ -171,12 +179,12 @@ SourceManager::DisplaySourceLinesWithLin
     else
         start_line = 1;
     
-    if (line == 0)
+    if (m_last_file_sp.get() != file_sp.get())
     {
-        if (!same_as_previous)
+        if (line == 0)
             m_last_line = 0;
+        m_last_file_sp = file_sp;
     }
-
     return DisplaySourceLinesWithLineNumbersUsingLastFile (start_line, count, line, current_line_cstr, s, bp_locs);
 }
 
@@ -317,6 +325,7 @@ SourceManager::File::File(const FileSpec
     m_file_spec_orig (file_spec),
     m_file_spec(file_spec),
     m_mod_time (file_spec.GetModificationTime()),
+    m_source_map_mod_id (0),
     m_data_sp(),
     m_offsets()
 {
@@ -324,6 +333,8 @@ SourceManager::File::File(const FileSpec
     {
         if (target)
         {
+            m_source_map_mod_id = target->GetSourcePathMap().GetModificationID();
+
             if (!file_spec.GetDirectory() && file_spec.GetFilename())
             {
                 // If this is just a file name, lets see if we can find it in the target:

Modified: lldb/trunk/source/Target/PathMappingList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/PathMappingList.cpp?rev=177125&r1=177124&r2=177125&view=diff
==============================================================================
--- lldb/trunk/source/Target/PathMappingList.cpp (original)
+++ lldb/trunk/source/Target/PathMappingList.cpp Thu Mar 14 17:52:17 2013
@@ -28,18 +28,17 @@ using namespace lldb_private;
 PathMappingList::PathMappingList () :
     m_pairs (),
     m_callback (NULL),
-    m_callback_baton (NULL)
+    m_callback_baton (NULL),
+    m_mod_id (0)
 {
 }
 
-PathMappingList::PathMappingList 
-(
-    ChangedCallback callback,
-    void *callback_baton
-) :
+PathMappingList::PathMappingList (ChangedCallback callback,
+                                  void *callback_baton) :
     m_pairs (),
     m_callback (callback),
-    m_callback_baton (callback_baton)
+    m_callback_baton (callback_baton),
+    m_mod_id (0)
 {
 }
 
@@ -47,7 +46,8 @@ PathMappingList::PathMappingList
 PathMappingList::PathMappingList (const PathMappingList &rhs) :
     m_pairs (rhs.m_pairs),
     m_callback (NULL),
-    m_callback_baton (NULL)
+    m_callback_baton (NULL),
+    m_mod_id (0)
 {
     
 }
@@ -60,6 +60,7 @@ PathMappingList::operator =(const PathMa
         m_pairs = rhs.m_pairs;
         m_callback = NULL;
         m_callback_baton = NULL;
+        m_mod_id = rhs.m_mod_id;
     }
     return *this;
 }
@@ -77,6 +78,7 @@ PathMappingList::Append (const ConstStri
                          const ConstString &replacement,
                          bool notify)
 {
+    ++m_mod_id;
     m_pairs.push_back(pair(path, replacement));
     if (notify && m_callback)
         m_callback (*this, m_callback_baton);
@@ -85,6 +87,7 @@ PathMappingList::Append (const ConstStri
 void
 PathMappingList::Append (const PathMappingList &rhs, bool notify)
 {
+    ++m_mod_id;
     if (!rhs.m_pairs.empty())
     {
         const_iterator pos, end = rhs.m_pairs.end();
@@ -101,6 +104,7 @@ PathMappingList::Insert (const ConstStri
                          uint32_t index,
                          bool notify)
 {
+    ++m_mod_id;
     iterator insert_iter;
     if (index >= m_pairs.size())
         insert_iter = m_pairs.end();
@@ -120,6 +124,7 @@ PathMappingList::Replace (const ConstStr
     iterator insert_iter;
     if (index >= m_pairs.size())
         return false;
+    ++m_mod_id;
     m_pairs[index] = pair(path, replacement);
     if (notify && m_callback)
         m_callback (*this, m_callback_baton);
@@ -132,6 +137,7 @@ PathMappingList::Remove (off_t index, bo
     if (index >= m_pairs.size())
         return false;
 
+    ++m_mod_id;
     iterator iter = m_pairs.begin() + index;
     m_pairs.erase(iter);
     if (notify && m_callback)
@@ -164,6 +170,8 @@ PathMappingList::Dump (Stream *s, int pa
 void
 PathMappingList::Clear (bool notify)
 {
+    if (!m_pairs.empty())
+        ++m_mod_id;
     m_pairs.clear();
     if (notify && m_callback)
         m_callback (*this, m_callback_baton);
@@ -255,6 +263,7 @@ PathMappingList::Replace (const ConstStr
     uint32_t idx = FindIndexForPath (path);
     if (idx < m_pairs.size())
     {
+        ++m_mod_id;
         m_pairs[idx].second = new_path;
         if (notify && m_callback)
             m_callback (*this, m_callback_baton);
@@ -269,6 +278,7 @@ PathMappingList::Remove (const ConstStri
     iterator pos = FindIteratorForPath (path);
     if (pos != m_pairs.end())
     {
+        ++m_mod_id;
         m_pairs.erase (pos);
         if (notify && m_callback)
             m_callback (*this, m_callback_baton);





More information about the lldb-commits mailing list