[Lldb-commits] [lldb] r141422 - in /lldb/trunk: include/lldb/Core/SourceManager.h source/Core/SourceManager.cpp source/Target/Target.cpp

Jim Ingham jingham at apple.com
Fri Oct 7 15:16:04 PDT 2011


Author: jingham
Date: Fri Oct  7 17:16:04 2011
New Revision: 141422

URL: http://llvm.org/viewvc/llvm-project?rev=141422&view=rev
Log:
Don't look up main to find the default source file till somebody actually asks for it.

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

Modified: lldb/trunk/include/lldb/Core/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/SourceManager.h?rev=141422&r1=141421&r2=141422&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/SourceManager.h (original)
+++ lldb/trunk/include/lldb/Core/SourceManager.h Fri Oct  7 17:16:04 2011
@@ -178,6 +178,7 @@
     uint32_t m_last_file_line;
     uint32_t m_last_file_context_before;
     uint32_t m_last_file_context_after;
+    bool     m_default_set;
     Target *m_target;
     Debugger *m_debugger;
     

Modified: lldb/trunk/source/Core/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SourceManager.cpp?rev=141422&r1=141421&r2=141422&view=diff
==============================================================================
--- lldb/trunk/source/Core/SourceManager.cpp (original)
+++ lldb/trunk/source/Core/SourceManager.cpp Fri Oct  7 17:16:04 2011
@@ -35,6 +35,7 @@
     m_last_file_line (0),
     m_last_file_context_before (0),
     m_last_file_context_after (10),
+    m_default_set(false),
     m_target (&target),
     m_debugger(NULL)
 {
@@ -46,6 +47,7 @@
     m_last_file_line (0),
     m_last_file_context_before (0),
     m_last_file_context_after (10),
+    m_default_set(false),
     m_target (NULL),
     m_debugger (&debugger)
 {
@@ -206,6 +208,8 @@
 {
     FileSP old_file_sp = m_last_file_sp;
     m_last_file_sp = GetFile (file_spec);
+    
+    m_default_set = true;
     if (m_last_file_sp)
     {
         m_last_file_line = line;
@@ -227,6 +231,35 @@
         line = m_last_file_line;
         return true;
     }
+    else if (!m_default_set)
+    {
+        // If nobody has set the default file and line then try here.  If there's no executable, then we
+        // will try again later when there is one.  Otherwise, if we can't find it we won't look again,
+        // somebody will have to set it (for instance when we stop somewhere...)
+        Module *executable_ptr = m_target->GetExecutableModulePointer();
+        if (executable_ptr)
+        {
+            SymbolContextList sc_list;
+            uint32_t num_matches;
+            ConstString main_name("main");
+            bool symbols_okay = false;  // Force it to be a debug symbol.
+            bool append = false;
+            num_matches = executable_ptr->FindFunctions (main_name, lldb::eFunctionNameTypeBase, symbols_okay, append, sc_list);
+            for (uint32_t idx = 0; idx < num_matches; idx++)
+            {
+                SymbolContext sc;
+                sc_list.GetContextAtIndex(idx, sc);
+                if (sc.line_entry.file)
+                {
+                    SetDefaultFileAndLine(sc.line_entry.file, sc.line_entry.line);
+                    break;
+                }
+            }
+            return GetDefaultFileAndLine (file_spec, line);
+        }
+        else
+            return false;
+    }
     else
         return false;
 }

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=141422&r1=141421&r2=141422&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Fri Oct  7 17:16:04 2011
@@ -811,26 +811,6 @@
         
         FileSpecList dependent_files;
         ObjectFile *executable_objfile = executable_sp->GetObjectFile();
-        // Let's find the file & line for main and set the default source file from there.
-        if (!m_source_manager.DefaultFileAndLineSet())
-        {
-            SymbolContextList sc_list;
-            uint32_t num_matches;
-            ConstString main_name("main");
-            bool symbols_okay = false;  // Force it to be a debug symbol.
-            bool append = false; 
-            num_matches = executable_sp->FindFunctions (main_name, eFunctionNameTypeBase, symbols_okay, append, sc_list);
-            for (uint32_t idx = 0; idx < num_matches; idx++)
-            {
-                SymbolContext sc;
-                sc_list.GetContextAtIndex(idx, sc);
-                if (sc.line_entry.file)
-                {
-                    m_source_manager.SetDefaultFileAndLine(sc.line_entry.file, sc.line_entry.line);
-                    break;
-                }
-            }
-        }
 
         if (executable_objfile && get_dependent_files)
         {





More information about the lldb-commits mailing list