Move the SourceManager from the Debugger to the Target.  That way it can store the per-Target default Source File & Line.
Set the default Source File & line to main (if it can be found.) at startup.  Selecting the current thread & or frame resets 
the current source file & line, and "source list" as well as the breakpoint command "break set -l <NUM>" will use the 
current source file.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@139323 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/ObjCLanguageRuntime.cpp b/source/Target/ObjCLanguageRuntime.cpp
index 4326910..a9e692d 100644
--- a/source/Target/ObjCLanguageRuntime.cpp
+++ b/source/Target/ObjCLanguageRuntime.cpp
@@ -111,7 +111,7 @@
     if (method_name) { method_name->Clear(); }
     if (base_name) { base_name->Clear(); }
     
-    if (name && (name[0] == '-' || name[0] == '+') && name[1] == '[')
+    if (IsPossibleObjCMethodName (name))
     {
         int name_len = strlen (name);
         // Objective C methods must have at least:
diff --git a/source/Target/StackFrame.cpp b/source/Target/StackFrame.cpp
index 0e6b02f..862e4c9 100644
--- a/source/Target/StackFrame.cpp
+++ b/source/Target/StackFrame.cpp
@@ -1282,8 +1282,7 @@
         if (m_sc.comp_unit && m_sc.line_entry.IsValid())
         {
             Target &target = GetThread().GetProcess().GetTarget();
-            target.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (
-                &target,
+            target.GetSourceManager().DisplaySourceLinesWithLineNumbers (
                 m_sc.line_entry.file,
                 m_sc.line_entry.line,
                 3,
diff --git a/source/Target/StackFrameList.cpp b/source/Target/StackFrameList.cpp
index 660bdcc..a19106e 100644
--- a/source/Target/StackFrameList.cpp
+++ b/source/Target/StackFrameList.cpp
@@ -14,11 +14,14 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Core/StreamFile.h"
+#include "lldb/Core/SourceManager.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/Symbol.h"
+#include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/Unwind.h"
 
@@ -401,15 +404,16 @@
     const_iterator pos;
     const_iterator begin = m_frames.begin();
     const_iterator end = m_frames.end();
+    m_selected_frame_idx = 0;
     for (pos = begin; pos != end; ++pos)
     {
         if (pos->get() == frame)
         {
             m_selected_frame_idx = std::distance (begin, pos);
-            return m_selected_frame_idx;
+            break;
         }
     }
-    m_selected_frame_idx = 0;
+    SetDefaultFileAndLineToSelectedFrame();
     return m_selected_frame_idx;
 }
 
@@ -419,6 +423,22 @@
 {
     Mutex::Locker locker (m_mutex);
     m_selected_frame_idx = idx;
+    SetDefaultFileAndLineToSelectedFrame();
+}
+
+void
+StackFrameList::SetDefaultFileAndLineToSelectedFrame()
+{
+    if (m_thread.GetID() == m_thread.GetProcess().GetThreadList().GetSelectedThread()->GetID())
+    {
+        StackFrameSP frame_sp = m_frames[m_selected_frame_idx];
+        if (frame_sp)
+        {
+            SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
+            if (sc.line_entry.file)
+            m_thread.GetProcess().GetTarget().GetSourceManager().SetDefaultFileAndLine (sc.line_entry.file, sc.line_entry.line);
+        }
+    }
 }
 
 // The thread has been run, reset the number stack frames to zero so we can
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index 00192a5..a236d71 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -59,6 +59,7 @@
     m_image_search_paths (ImageSearchPathsChanged, this),
     m_scratch_ast_context_ap (NULL),
     m_persistent_variables (),
+    m_source_manager(this),
     m_stop_hooks (),
     m_stop_hook_next_id (0),
     m_suppress_stop_hooks (false)
@@ -469,6 +470,26 @@
         
         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)
         {
diff --git a/source/Target/Thread.cpp b/source/Target/Thread.cpp
index 13d2193..babb2dd 100644
--- a/source/Target/Thread.cpp
+++ b/source/Target/Thread.cpp
@@ -925,15 +925,6 @@
     return *m_curr_frames_sp;
 }
 
-
-
-uint32_t
-Thread::GetStackFrameCount()
-{
-    return GetStackFrameList().GetNumFrames();
-}
-
-
 void
 Thread::ClearStackFrames ()
 {
@@ -943,48 +934,11 @@
 }
 
 lldb::StackFrameSP
-Thread::GetStackFrameAtIndex (uint32_t idx)
-{
-    return GetStackFrameList().GetFrameAtIndex(idx);
-}
-
-uint32_t
-Thread::GetSelectedFrameIndex ()
-{
-    return GetStackFrameList().GetSelectedFrameIndex();
-}
-
-lldb::StackFrameSP
 Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
 {
     return GetStackFrameList().GetFrameWithConcreteFrameIndex (unwind_idx);
 }
 
-lldb::StackFrameSP
-Thread::GetFrameWithStackID(StackID &stack_id)
-{
-    return GetStackFrameList().GetFrameWithStackID (stack_id);
-}
-
-
-lldb::StackFrameSP
-Thread::GetSelectedFrame ()
-{
-    return GetStackFrameAtIndex (GetStackFrameList().GetSelectedFrameIndex());
-}
-
-uint32_t
-Thread::SetSelectedFrame (lldb_private::StackFrame *frame)
-{
-    return GetStackFrameList().SetSelectedFrame(frame);
-}
-
-void
-Thread::SetSelectedFrameByIndex (uint32_t idx)
-{
-    GetStackFrameList().SetSelectedFrameByIndex(idx);
-}
-
 void
 Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
 {
diff --git a/source/Target/ThreadList.cpp b/source/Target/ThreadList.cpp
index 79df0f2..12d78b5 100644
--- a/source/Target/ThreadList.cpp
+++ b/source/Target/ThreadList.cpp
@@ -558,8 +558,12 @@
 ThreadList::SetSelectedThreadByID (lldb::tid_t tid)
 {
     Mutex::Locker locker(m_threads_mutex);
-    if  (FindThreadByID(tid).get())
+    ThreadSP selected_thread_sp(FindThreadByID(tid));
+    if  (selected_thread_sp)
+    {
         m_selected_tid = tid;
+        selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
+    }
     else
         m_selected_tid = LLDB_INVALID_THREAD_ID;
 
@@ -570,9 +574,12 @@
 ThreadList::SetSelectedThreadByIndexID (uint32_t index_id)
 {
     Mutex::Locker locker(m_threads_mutex);
-    ThreadSP thread_sp (FindThreadByIndexID(index_id));
-    if  (thread_sp.get())
-        m_selected_tid = thread_sp->GetID();
+    ThreadSP selected_thread_sp (FindThreadByIndexID(index_id));
+    if  (selected_thread_sp.get())
+    {
+        m_selected_tid = selected_thread_sp->GetID();
+        selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
+    }
     else
         m_selected_tid = LLDB_INVALID_THREAD_ID;