[Lldb-commits] [lldb] r139564 - in /lldb/trunk: include/lldb/API/ include/lldb/Core/ scripts/Python/interface/ source/API/ source/Core/ source/Target/ tools/driver/

Jim Ingham jingham at apple.com
Mon Sep 12 17:29:56 PDT 2011


Author: jingham
Date: Mon Sep 12 19:29:56 2011
New Revision: 139564

URL: http://llvm.org/viewvc/llvm-project?rev=139564&view=rev
Log:
SBSourceManager now gets the real source manager either from the Debugger or Target.  Also, move the SourceManager file cache into the debugger
so it can be shared amongst the targets.

Modified:
    lldb/trunk/include/lldb/API/SBDebugger.h
    lldb/trunk/include/lldb/API/SBFileSpec.h
    lldb/trunk/include/lldb/API/SBSourceManager.h
    lldb/trunk/include/lldb/API/SBStream.h
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/include/lldb/Core/SourceManager.h
    lldb/trunk/scripts/Python/interface/SBDebugger.i
    lldb/trunk/scripts/Python/interface/SBTarget.i
    lldb/trunk/source/API/SBCommandInterpreter.cpp
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/API/SBSourceManager.cpp
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Core/SourceManager.cpp
    lldb/trunk/source/Target/Target.cpp
    lldb/trunk/tools/driver/Driver.cpp

Modified: lldb/trunk/include/lldb/API/SBDebugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBDebugger.h (original)
+++ lldb/trunk/include/lldb/API/SBDebugger.h Mon Sep 12 19:29:56 2011
@@ -127,7 +127,7 @@
     lldb::SBTarget
     GetSelectedTarget ();
 
-    lldb::SBSourceManager &
+    lldb::SBSourceManager
     GetSourceManager ();
 
     // REMOVE: just for a quick fix, need to expose platforms through
@@ -234,6 +234,7 @@
     friend class SBInputReader;
     friend class SBProcess;
     friend class SBTarget;
+    friend class SBSourceManager_impl;
     
     lldb::SBTarget
     FindTargetWithLLDBProcess (const lldb::ProcessSP &processSP);

Modified: lldb/trunk/include/lldb/API/SBFileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFileSpec.h?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBFileSpec.h (original)
+++ lldb/trunk/include/lldb/API/SBFileSpec.h Mon Sep 12 19:29:56 2011
@@ -63,7 +63,7 @@
     friend class SBLineEntry;
     friend class SBModule;
     friend class SBProcess;
-    friend class SBSourceManager;
+    friend class SBSourceManager_impl;
     friend class SBThread;
     friend class SBTarget;
 

Modified: lldb/trunk/include/lldb/API/SBSourceManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSourceManager.h?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBSourceManager.h (original)
+++ lldb/trunk/include/lldb/API/SBSourceManager.h Mon Sep 12 19:29:56 2011
@@ -16,10 +16,14 @@
 
 namespace lldb {
 
+class SBSourceManager_impl;
+
 class SBSourceManager
 {
 public:
-    SBSourceManager (const lldb::SBSourceManager &rhs);
+    SBSourceManager (const SBDebugger &debugger);
+    SBSourceManager (const SBTarget &target);
+    SBSourceManager (const SBSourceManager &rhs);
     
     ~SBSourceManager();
 
@@ -45,7 +49,7 @@
 
 private:
 
-    lldb_private::SourceManager *m_opaque_ptr;
+    std::auto_ptr<SBSourceManager_impl> m_opaque_ap;
 };
 
 } // namespace lldb

Modified: lldb/trunk/include/lldb/API/SBStream.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStream.h?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBStream.h (original)
+++ lldb/trunk/include/lldb/API/SBStream.h Mon Sep 12 19:29:56 2011
@@ -69,7 +69,7 @@
     friend class SBInstruction;
     friend class SBInstructionList;
     friend class SBModule;
-    friend class SBSourceManager;
+    friend class SBSourceManager_impl;
     friend class SBSymbol;
     friend class SBSymbolContext;
     friend class SBTarget;

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Mon Sep 12 19:29:56 2011
@@ -349,6 +349,9 @@
     
     lldb::SBTypeList
     FindTypes (const char* type);
+    
+    SBSourceManager
+    GetSourceManager();
 
 #ifndef SWIG
     bool
@@ -375,6 +378,7 @@
     friend class SBSymbol;
     friend class SBModule;
     friend class SBValue;
+    friend class SBSourceManager_impl;
 
     //------------------------------------------------------------------
     // Constructors are private, use static Target::Create function to

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Mon Sep 12 19:29:56 2011
@@ -223,6 +223,8 @@
     public UserID,
     public DebuggerInstanceSettings
 {
+friend class SourceManager;  // For GetSourceFileCache.
+
 public:
 
     class SettingsController : public UserSettingsController
@@ -342,16 +344,17 @@
         return m_listener;
     }
 
+    // This returns the Debugger's scratch source manager.  It won't be able to look up files in debug
+    // information, but it can look up files by absolute path and display them to you.
+    // To get the target's source manager, call GetSourceManager on the target instead.
     SourceManager &
     GetSourceManager ()
     {
-        lldb::TargetSP selected_target = GetSelectedTarget();
-        if (selected_target)
-            return selected_target->GetSourceManager();
-        else
-            return m_source_manager;
+        return m_source_manager;
     }
 
+public:
+    
     lldb::TargetSP
     GetSelectedTarget ()
     {
@@ -455,6 +458,12 @@
         m_input_comm.Clear ();
     }
 
+    SourceManager::SourceFileCache &
+    GetSourceFileCache ()
+    {
+        return m_source_file_cache;
+    }
+
     Communication m_input_comm;
     StreamFile m_input_file;
     StreamFile m_output_file;
@@ -463,6 +472,8 @@
     PlatformList m_platform_list;
     Listener m_listener;
     SourceManager m_source_manager;    // This is a scratch source manager that we return if we have no targets.
+    SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
+                                                        // source file cache.
     std::auto_ptr<CommandInterpreter> m_command_interpreter_ap;
 
     InputReaderStack m_input_reader_stack;

Modified: lldb/trunk/include/lldb/Core/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/SourceManager.h?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/SourceManager.h (original)
+++ lldb/trunk/include/lldb/Core/SourceManager.h Mon Sep 12 19:29:56 2011
@@ -26,9 +26,12 @@
 {
 public:
 #ifndef SWIG
+    
     class File
     {
+    friend bool operator== (const SourceManager::File &lhs, const SourceManager::File &rhs);
     public:
+    
         File (const FileSpec &file_spec, Target *target);
         ~File();
 
@@ -52,7 +55,7 @@
         {
             return m_file_spec;
         }
-
+        
     protected:
 
         bool
@@ -65,6 +68,28 @@
         typedef std::vector<uint32_t> LineOffsets;
         LineOffsets m_offsets;
     };
+
+#endif // SWIG
+
+    typedef lldb::SharedPtr<File>::Type FileSP;
+
+#ifndef SWIG
+
+   // The SourceFileCache class separates the source manager from the cache of source files, so the 
+   // cache can be stored in the Debugger, but the source managers can be per target.     
+    class SourceFileCache
+    {
+    public:
+        SourceFileCache () {};
+        ~SourceFileCache() {};
+        
+        void AddSourceFile (const FileSP &file_sp);
+        FileSP FindSourceFile (const FileSpec &file_spec) const;
+        
+    protected:
+        typedef std::map <FileSpec, FileSP> FileCache;
+        FileCache m_file_cache;
+    };
 #endif
 
 
@@ -73,11 +98,11 @@
     //------------------------------------------------------------------
     // A source manager can be made with a non-null target, in which case it can use the path remappings to find 
     // source files that are not in their build locations.  With no target it won't be able to do this.
-    SourceManager(Target *target);
+    SourceManager (Debugger &debugger);
+    SourceManager (Target &target);
 
     ~SourceManager();
 
-    typedef lldb::SharedPtr<File>::Type FileSP;
 
     FileSP
     GetLastFile () 
@@ -134,13 +159,13 @@
     //------------------------------------------------------------------
     // Classes that inherit from SourceManager can see and modify these
     //------------------------------------------------------------------
-    typedef std::map <FileSpec, FileSP> FileCache;
-    FileCache m_file_cache;
     FileSP m_last_file_sp;
     uint32_t m_last_file_line;
     uint32_t m_last_file_context_before;
     uint32_t m_last_file_context_after;
     Target *m_target;
+    Debugger *m_debugger;
+    
 private:
     //------------------------------------------------------------------
     // For SourceManager only
@@ -148,6 +173,7 @@
     DISALLOW_COPY_AND_ASSIGN (SourceManager);
 };
 
+bool operator== (const SourceManager::File &lhs, const SourceManager::File &rhs);
 } // namespace lldb_private
 
 #endif  // liblldb_SourceManager_h_

Modified: lldb/trunk/scripts/Python/interface/SBDebugger.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBDebugger.i?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBDebugger.i (original)
+++ lldb/trunk/scripts/Python/interface/SBDebugger.i Mon Sep 12 19:29:56 2011
@@ -206,7 +206,7 @@
     lldb::SBTarget
     GetSelectedTarget ();
 
-    lldb::SBSourceManager &
+    lldb::SBSourceManager
     GetSourceManager ();
 
     // REMOVE: just for a quick fix, need to expose platforms through

Modified: lldb/trunk/scripts/Python/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/Python/interface/SBTarget.i Mon Sep 12 19:29:56 2011
@@ -327,6 +327,9 @@
     lldb::SBTypeList
     FindTypes (const char* type);
 
+    lldb::SBSourceManager
+    GetSourceManager ();
+
     %feature("docstring", "
     //------------------------------------------------------------------
     /// Find global and static variables by name.

Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Mon Sep 12 19:29:56 2011
@@ -18,7 +18,6 @@
 #include "lldb/API/SBBroadcaster.h"
 #include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBCommandReturnObject.h"
-#include "lldb/API/SBSourceManager.h"
 #include "lldb/API/SBCommandInterpreter.h"
 #include "lldb/API/SBProcess.h"
 #include "lldb/API/SBTarget.h"

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Mon Sep 12 19:29:56 2011
@@ -357,12 +357,11 @@
     }
 }
 
-SBSourceManager &
+SBSourceManager
 SBDebugger::GetSourceManager ()
 {
-    static SourceManager g_lldb_source_manager(NULL);
-    static SBSourceManager g_sb_source_manager (&g_lldb_source_manager);
-    return g_sb_source_manager;
+    SBSourceManager sb_source_manager (*this);
+    return sb_source_manager;
 }
 
 

Modified: lldb/trunk/source/API/SBSourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSourceManager.cpp?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/source/API/SBSourceManager.cpp (original)
+++ lldb/trunk/source/API/SBSourceManager.cpp Mon Sep 12 19:29:56 2011
@@ -7,41 +7,110 @@
 //
 //===----------------------------------------------------------------------===//
 
-
+#include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBSourceManager.h"
+#include "lldb/API/SBTarget.h"
 #include "lldb/API/SBStream.h"
 
 #include "lldb/API/SBFileSpec.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/SourceManager.h"
 
+#include "lldb/Target/Target.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
+class lldb::SBSourceManager_impl
+{
+public:
+    SBSourceManager_impl (const SBDebugger &debugger)
+    {
+        m_debugger_sp = debugger.m_opaque_sp;
+    }
+    
+    SBSourceManager_impl (const SBTarget &target)
+    {
+        m_target_sp = target.m_opaque_sp;
+    }
+    
+    SBSourceManager_impl (const SBSourceManager_impl &rhs)
+    {
+        if (&rhs == this)
+            return;
+        m_debugger_sp = rhs.m_debugger_sp;
+        m_target_sp   = rhs.m_target_sp;
+    }
+
+    size_t
+    DisplaySourceLinesWithLineNumbers
+    (
+        const SBFileSpec &file,
+        uint32_t line,
+        uint32_t context_before,
+        uint32_t context_after,
+        const char* current_line_cstr,
+        SBStream &s
+    )
+    {
+        if (!file.IsValid())
+            return 0;
+            
+        if (m_debugger_sp)
+            return m_debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (*file,
+                                                                                        line,
+                                                                                        context_before,
+                                                                                        context_after,
+                                                                                        current_line_cstr,
+                                                                                        s.m_opaque_ap.get());
+        else if (m_target_sp)
+            return m_target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (*file,
+                                                                                      line,
+                                                                                      context_before,
+                                                                                      context_after,
+                                                                                      current_line_cstr,
+                                                                                      s.m_opaque_ap.get());
+        else
+            return 0;
+    }
+    
+private:
+    lldb::DebuggerSP m_debugger_sp;
+    lldb::TargetSP   m_target_sp;
+    
+};
 
-SBSourceManager::SBSourceManager (SourceManager* source_manager) :
-    m_opaque_ptr (source_manager)
+SBSourceManager::SBSourceManager (const SBDebugger &debugger)
 {
+    m_opaque_ap.reset(new SBSourceManager_impl (debugger));
 }
 
-SBSourceManager::~SBSourceManager()
+SBSourceManager::SBSourceManager (const SBTarget &target)
 {
+    m_opaque_ap.reset(new SBSourceManager_impl (target));
 }
 
-SBSourceManager::SBSourceManager(const SBSourceManager &rhs) :
-    m_opaque_ptr (rhs.m_opaque_ptr)
+SBSourceManager::SBSourceManager (const SBSourceManager &rhs)
 {
+    if (&rhs == this)
+        return;
+        
+    m_opaque_ap.reset(new SBSourceManager_impl (*(rhs.m_opaque_ap.get())));
 }
 
-const SBSourceManager &
-SBSourceManager::operator = (const SBSourceManager &rhs)
+const lldb::SBSourceManager &
+SBSourceManager::operator = (const lldb::SBSourceManager &rhs)
 {
-    m_opaque_ptr = rhs.m_opaque_ptr;
+    m_opaque_ap.reset (new SBSourceManager_impl (*(rhs.m_opaque_ap.get())));
     return *this;
 }
 
+SBSourceManager::~SBSourceManager()
+{
+}
+
 size_t
 SBSourceManager::DisplaySourceLinesWithLineNumbers
 (
@@ -53,20 +122,13 @@
     SBStream &s
 )
 {
-    if (m_opaque_ptr == NULL)
-        return 0;
-
-    if (s.m_opaque_ap.get() == NULL)
+    if (m_opaque_ap.get() == NULL)
         return 0;
 
-    if (file.IsValid())
-    {
-        return m_opaque_ptr->DisplaySourceLinesWithLineNumbers (*file,
-                                                                line,
-                                                                context_before,
-                                                                context_after,
-                                                                current_line_cstr,
-                                                                s.m_opaque_ap.get());
-    }
-    return 0;
+    return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file,
+                                                           line,
+                                                           context_before,
+                                                           context_after,
+                                                           current_line_cstr,
+                                                           s);
 }

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Mon Sep 12 19:29:56 2011
@@ -16,6 +16,7 @@
 #include "lldb/API/SBFileSpec.h"
 #include "lldb/API/SBListener.h"
 #include "lldb/API/SBModule.h"
+#include "lldb/API/SBSourceManager.h"
 #include "lldb/API/SBProcess.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/API/SBSymbolContextList.h"
@@ -958,3 +959,9 @@
     return sb_value_list;
 }
 
+SBSourceManager
+SBTarget::GetSourceManager()
+{
+    SBSourceManager source_manager (*this);
+    return source_manager;
+}

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Mon Sep 12 19:29:56 2011
@@ -237,7 +237,8 @@
     m_target_list (),
     m_platform_list (),
     m_listener ("lldb.Debugger"),
-    m_source_manager(NULL),
+    m_source_manager(*this),
+    m_source_file_cache(),
     m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
     m_input_reader_stack (),
     m_input_reader_data ()

Modified: lldb/trunk/source/Core/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SourceManager.cpp?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/source/Core/SourceManager.cpp (original)
+++ lldb/trunk/source/Core/SourceManager.cpp Mon Sep 12 19:29:56 2011
@@ -14,6 +14,7 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Core/DataBuffer.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Target/Target.h"
@@ -29,13 +30,24 @@
 //----------------------------------------------------------------------
 // SourceManager constructor
 //----------------------------------------------------------------------
-SourceManager::SourceManager(Target *target) :
-    m_file_cache (),
+SourceManager::SourceManager(Target &target) :
     m_last_file_sp (),
     m_last_file_line (0),
     m_last_file_context_before (0),
     m_last_file_context_after (10),
-    m_target (target)
+    m_target (&target),
+    m_debugger(NULL)
+{
+    m_debugger = &(m_target->GetDebugger());
+}
+
+SourceManager::SourceManager(Debugger &debugger) :
+    m_last_file_sp (),
+    m_last_file_line (0),
+    m_last_file_context_before (0),
+    m_last_file_context_after (10),
+    m_target (NULL),
+    m_debugger (&debugger)
 {
 }
 
@@ -70,13 +82,12 @@
 SourceManager::GetFile (const FileSpec &file_spec)
 {
     FileSP file_sp;
-    FileCache::iterator pos = m_file_cache.find(file_spec);
-    if (pos != m_file_cache.end())
-        file_sp = pos->second;
-    else
+    file_sp = m_debugger->GetSourceFileCache().FindSourceFile (file_spec);
+    if (!file_sp)
     {
         file_sp.reset (new File (file_spec, m_target));
-        m_file_cache[file_spec] = file_sp;
+
+        m_debugger->GetSourceFileCache().AddSourceFile(file_sp);
     }
     return file_sp;
 }
@@ -92,6 +103,7 @@
     const SymbolContextList *bp_locs
 )
 {
+    size_t return_value = 0;
     if (line == 0)
     {
         if (m_last_file_line != 0
@@ -134,18 +146,21 @@
                     ::snprintf (prefix, sizeof (prefix), "    ");
             }
 
-            s->Printf("%s%2.2s %-4u\t", 
+            return_value += s->Printf("%s%2.2s %-4u\t", 
                       prefix,
                       curr_line == line ? current_line_cstr : "", 
                       curr_line);
-            if (m_last_file_sp->DisplaySourceLines (curr_line, 0, 0, s) == 0)
+            size_t this_line_size = m_last_file_sp->DisplaySourceLines (curr_line, 0, 0, s); 
+            if (this_line_size == 0)
             {
                 m_last_file_line = UINT32_MAX;
                 break;
             }
+            else
+                return_value += this_line_size;
         }
     }
-    return 0;
+    return return_value;
 }
 
 size_t
@@ -181,7 +196,7 @@
     {
         if (m_last_file_line == UINT32_MAX)
             return 0;
-        DisplaySourceLinesWithLineNumbersUsingLastFile (0, m_last_file_context_before, m_last_file_context_after, "", s, bp_locs);
+        return DisplaySourceLinesWithLineNumbersUsingLastFile (0, m_last_file_context_before, m_last_file_context_after, "", s, bp_locs);
     }
     return 0;
 }
@@ -226,8 +241,57 @@
 {
     if (!m_mod_time.IsValid())
     {
-        if (target && target->GetSourcePathMap().RemapPath(file_spec.GetDirectory(), m_file_spec.GetDirectory()))
-            m_mod_time = file_spec.GetModificationTime();
+        if (target)
+        {
+            if (!file_spec.GetDirectory() && file_spec.GetFilename())
+            {
+                // If this is just a file name, lets see if we can find it in the target:
+                bool check_inlines = false;
+                SymbolContextList sc_list;
+                size_t num_matches = target->GetImages().ResolveSymbolContextForFilePath (file_spec.GetFilename().AsCString(),
+                                                                                          0,
+                                                                                          check_inlines,
+                                                                                          lldb::eSymbolContextModule | lldb::eSymbolContextCompUnit,
+                                                                                          sc_list);
+                bool got_multiple = false;
+                if (num_matches != 0)
+                {
+                    if (num_matches > 1)
+                    {
+                        SymbolContext sc;
+                        FileSpec *test_cu_spec = NULL;
+
+                        for (unsigned i = 0; i < num_matches; i++)
+                        {
+                            sc_list.GetContextAtIndex(i, sc);
+                            if (sc.comp_unit)
+                            {
+                                if (test_cu_spec)
+                                {
+                                    if (test_cu_spec != static_cast<FileSpec *> (sc.comp_unit))
+                                        got_multiple = true;
+                                        break;
+                                }
+                                else
+                                    test_cu_spec = sc.comp_unit;
+                            }
+                        }
+                    }
+                    if (!got_multiple)
+                    {
+                        SymbolContext sc;
+                        sc_list.GetContextAtIndex (0, sc);
+                        m_file_spec = static_cast<FileSpec *>(sc.comp_unit);
+                        m_mod_time = m_file_spec.GetModificationTime();
+                    }
+                }
+            }
+            else
+            {
+                if (target->GetSourcePathMap().RemapPath(file_spec.GetDirectory(), m_file_spec.GetDirectory()))
+                   m_mod_time = file_spec.GetModificationTime();
+            }
+        }
     }
     
     if (m_mod_time.IsValid())
@@ -310,6 +374,26 @@
     return FileSpec::Equal (m_file_spec, file_spec, false);
 }
 
+bool
+lldb_private::operator== (const SourceManager::File &lhs, const SourceManager::File &rhs)
+{
+    if (lhs.m_file_spec == rhs.m_file_spec)
+    {
+        if (lhs.m_mod_time.IsValid())
+        {
+            if (rhs.m_mod_time.IsValid())
+                return lhs.m_mod_time == rhs.m_mod_time;
+            else
+                return false;
+        }
+        else if (rhs.m_mod_time.IsValid())
+            return false;
+        else
+            return true;
+    }
+    else
+        return false;
+}
 
 bool
 SourceManager::File::CalculateLineOffsets (uint32_t line)
@@ -372,3 +456,28 @@
     }
     return false;
 }
+
+void 
+SourceManager::SourceFileCache::AddSourceFile (const FileSP &file_sp)
+{
+    FileSpec file_spec;
+    FileCache::iterator pos = m_file_cache.find(file_spec);
+    if (pos == m_file_cache.end())
+        m_file_cache[file_spec] = file_sp;
+    else
+    {
+        if (file_sp != pos->second)
+            m_file_cache[file_spec] = file_sp;
+    }
+}
+
+SourceManager::FileSP 
+SourceManager::SourceFileCache::FindSourceFile (const FileSpec &file_spec) const
+{
+    FileSP file_sp;
+    FileCache::const_iterator pos = m_file_cache.find(file_spec);
+    if (pos != m_file_cache.end())
+        file_sp = pos->second;
+    return file_sp;
+}
+

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Sep 12 19:29:56 2011
@@ -59,7 +59,7 @@
     m_image_search_paths (ImageSearchPathsChanged, this),
     m_scratch_ast_context_ap (NULL),
     m_persistent_variables (),
-    m_source_manager(this),
+    m_source_manager(*this),
     m_stop_hooks (),
     m_stop_hook_next_id (0),
     m_suppress_stop_hooks (false)

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=139564&r1=139563&r2=139564&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Mon Sep 12 19:29:56 2011
@@ -29,7 +29,6 @@
 #include "lldb/API/SBEvent.h"
 #include "lldb/API/SBHostOS.h"
 #include "lldb/API/SBListener.h"
-#include "lldb/API/SBSourceManager.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/API/SBTarget.h"
 #include "lldb/API/SBThread.h"





More information about the lldb-commits mailing list