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/Commands/CommandObjectBreakpoint.cpp b/source/Commands/CommandObjectBreakpoint.cpp
index 2e894ed..20641ac 100644
--- a/source/Commands/CommandObjectBreakpoint.cpp
+++ b/source/Commands/CommandObjectBreakpoint.cpp
@@ -321,31 +321,37 @@
                 FileSpec file;
                 if (m_options.m_filename.empty())
                 {
-                    StackFrame *cur_frame = m_interpreter.GetExecutionContext().frame;
-                    if (cur_frame == NULL)
+                    uint32_t default_line;
+                    // First use the Source Manager's default file. 
+                    // Then use the current stack frame's file.
+                    if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
                     {
-                        result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
-                        result.SetStatus (eReturnStatusFailed);
-                        break;
-                    }
-                    else if (!cur_frame->HasDebugInformation())
-                    {
-                        result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
-                        result.SetStatus (eReturnStatusFailed);
-                        break;
-                    }
-                    else
-                    {
-                        const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
-                        if (sc.line_entry.file)
+                        StackFrame *cur_frame = m_interpreter.GetExecutionContext().frame;
+                        if (cur_frame == NULL)
                         {
-                            file = sc.line_entry.file;
+                            result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
+                            result.SetStatus (eReturnStatusFailed);
+                            break;
+                        }
+                        else if (!cur_frame->HasDebugInformation())
+                        {
+                            result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
+                            result.SetStatus (eReturnStatusFailed);
+                            break;
                         }
                         else
                         {
-                            result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
-                            result.SetStatus (eReturnStatusFailed);
-                            break;
+                            const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
+                            if (sc.line_entry.file)
+                            {
+                                file = sc.line_entry.file;
+                            }
+                            else
+                            {
+                                result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
+                                result.SetStatus (eReturnStatusFailed);
+                                break;
+                            }
                         }
                     }
                 }
diff --git a/source/Commands/CommandObjectSource.cpp b/source/Commands/CommandObjectSource.cpp
index d534338..e6b98fa 100644
--- a/source/Commands/CommandObjectSource.cpp
+++ b/source/Commands/CommandObjectSource.cpp
@@ -280,18 +280,23 @@
         }
 
         ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
-        
+        Target *target = NULL;
+
+        if (exe_ctx.target)
+            target = exe_ctx.target;
+        else
+            target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+            
+        if (target == NULL)
+        {
+            result.AppendError ("invalid target, create a debug target using the 'target create' command");
+            result.SetStatus (eReturnStatusFailed);
+            return false;
+        }
+
         if (!m_options.symbol_name.empty())
         {
             // Displaying the source for a symbol:
-            Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
-            if (target == NULL)
-            {
-                result.AppendError ("invalid target, create a debug target using the 'target create' command");
-                result.SetStatus (eReturnStatusFailed);
-                return false;
-            }
-            
             SymbolContextList sc_list;
             ConstString name(m_options.symbol_name.c_str());
             bool include_symbols = false;
@@ -418,7 +423,7 @@
             char path_buf[PATH_MAX];
             start_file.GetPath(path_buf, sizeof(path_buf));
             
-            if (m_options.show_bp_locs && exe_ctx.target)
+            if (m_options.show_bp_locs)
             {
                 const bool show_inlines = true;
                 m_breakpoint_locations.Reset (start_file, 0, show_inlines);
@@ -429,14 +434,13 @@
                 m_breakpoint_locations.Clear();
 
             result.AppendMessageWithFormat("File: %s.\n", path_buf);
-            m_interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (target,
-                                                                                              start_file,
-                                                                                              line_no,
-                                                                                              0,
-                                                                                              m_options.num_lines,
-                                                                                              "",
-                                                                                              &result.GetOutputStream(),
-                                                                                              GetBreakpointLocations ());
+            target->GetSourceManager().DisplaySourceLinesWithLineNumbers (start_file,
+                                                                          line_no,
+                                                                          0,
+                                                                          m_options.num_lines,
+                                                                          "",
+                                                                          &result.GetOutputStream(),
+                                                                          GetBreakpointLocations ());
             
             result.SetStatus (eReturnStatusSuccessFinishResult);
             return true;
@@ -458,21 +462,21 @@
             }
             else
             {
-                if (m_options.show_bp_locs && exe_ctx.target)
+                if (m_options.show_bp_locs)
                 {
-                    SourceManager::FileSP last_file_sp (m_interpreter.GetDebugger().GetSourceManager().GetLastFile ());
+                    SourceManager::FileSP last_file_sp (target->GetSourceManager().GetLastFile ());
                     if (last_file_sp)
                     {
                         const bool show_inlines = true;
                         m_breakpoint_locations.Reset (last_file_sp->GetFileSpec(), 0, show_inlines);
-                        SearchFilter target_search_filter (exe_ctx.target->GetSP());
+                        SearchFilter target_search_filter (target->GetSP());
                         target_search_filter.Search (m_breakpoint_locations);
                     }
                 }
                 else
                     m_breakpoint_locations.Clear();
 
-                if (m_interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbersUsingLastFile(
+                if (target->GetSourceManager().DisplaySourceLinesWithLineNumbersUsingLastFile(
                             m_options.start_line,   // Line to display
                             0,                      // Lines before line to display
                             m_options.num_lines,    // Lines after line to display
@@ -488,14 +492,6 @@
         else
         {
             const char *filename = m_options.file_name.c_str();
-            Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
-            if (target == NULL)
-            {
-                result.AppendError ("invalid target, create a debug target using the 'target create' command");
-                result.SetStatus (eReturnStatusFailed);
-                return false;
-            }
-
 
             bool check_inlines = false;
             SymbolContextList sc_list;
@@ -571,24 +567,23 @@
             {
                 if (sc.comp_unit)
                 {
-                    if (m_options.show_bp_locs && exe_ctx.target)
+                    if (m_options.show_bp_locs)
                     {
                         const bool show_inlines = true;
                         m_breakpoint_locations.Reset (*sc.comp_unit, 0, show_inlines);
-                        SearchFilter target_search_filter (exe_ctx.target->GetSP());
+                        SearchFilter target_search_filter (target->GetSP());
                         target_search_filter.Search (m_breakpoint_locations);
                     }
                     else
                         m_breakpoint_locations.Clear();
 
-                    m_interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (target,
-                                                                                                      sc.comp_unit,
-                                                                                                      m_options.start_line,
-                                                                                                      0,
-                                                                                                      m_options.num_lines,
-                                                                                                      "",
-                                                                                                      &result.GetOutputStream(),
-                                                                                                      GetBreakpointLocations ());
+                    target->GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.comp_unit,
+                                                                                  m_options.start_line,
+                                                                                  0,
+                                                                                  m_options.num_lines,
+                                                                                  "",
+                                                                                  &result.GetOutputStream(),
+                                                                                  GetBreakpointLocations ());
 
                     result.SetStatus (eReturnStatusSuccessFinishResult);
                 }