Many GDB users always want to display disassembly when they stop by using 
something like "display/4i $pc" (or something like this). With LLDB we already
were showing 3 lines of source before and 3 lines of source after the current
source line when showing a stop context. We now improve this by allowing the
user to control the number of lines with the new "stop-line-count-before" and
"stop-line-count-after" settings. Also, there is a new setting for how many
disassembly lines to show: "stop-disassembly-count". This will control how many
source lines are shown when there is no source or when we have no source line
info. 

settings set stop-line-count-before 3
settings set stop-line-count-after 3
settings set stop-disassembly-count 4
settings set stop-disassembly-display no-source

The default values are set as shown above and allow 3 lines of source before 
and after (what we used to do) the current stop location, and will display 4 
lines of disassembly if the source is not available or if we have no debug
info. If both "stop-source-context-before" and "stop-source-context-after" are
set to zero, this will disable showing any source when stopped. The 
"stop-disassembly-display" setting is an enumeration that allows you to control
when to display disassembly. It has 3 possible values:

"never" - never show disassembly no matter what
"no-source" - only show disassembly when there is no source line info or the source files are missing
"always" - always show disassembly.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@145050 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/StackFrame.cpp b/source/Target/StackFrame.cpp
index 0d25879..666bc1d 100644
--- a/source/Target/StackFrame.cpp
+++ b/source/Target/StackFrame.cpp
@@ -1270,19 +1270,62 @@
     
     if (show_source)
     {
-        GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
-    
-        if (m_sc.comp_unit && m_sc.line_entry.IsValid())
+        Target &target = GetThread().GetProcess().GetTarget();
+        Debugger &debugger = target.GetDebugger();
+        const uint32_t source_before = debugger.GetStopSourceLineCount(true);
+        const uint32_t source_after = debugger.GetStopSourceLineCount(false);
+        bool have_source = false;
+        if (source_before || source_after)
         {
-            Target &target = GetThread().GetProcess().GetTarget();
-            target.GetSourceManager().DisplaySourceLinesWithLineNumbers (
-                m_sc.line_entry.file,
-                m_sc.line_entry.line,
-                3,
-                3,
-                "->",
-                &strm);
+            GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
+
+            if (m_sc.comp_unit && m_sc.line_entry.IsValid())
+            {
+                if (target.GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
+                                                                                 m_sc.line_entry.line,
+                                                                                 source_before,
+                                                                                 source_after,
+                                                                                 "->",
+                                                                                 &strm))
+                {
+                    have_source = true;
+                }
+            }
+        }
+        DebuggerInstanceSettings::StopDisassemblyType disasm_display = debugger.GetStopDisassemblyDisplay ();
         
+        switch (disasm_display)
+        {
+        case DebuggerInstanceSettings::eStopDisassemblyTypeNever:
+            break;
+
+        case DebuggerInstanceSettings::eStopDisassemblyTypeNoSource:
+            if (have_source)
+                break;
+            // Fall through to next case
+        case DebuggerInstanceSettings::eStopDisassemblyTypeAlways:
+            {
+                const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
+                if (disasm_lines > 0)
+                {
+                    const ArchSpec &target_arch = target.GetArchitecture();
+                    AddressRange pc_range;
+                    pc_range.GetBaseAddress() = GetFrameCodeAddress();
+                    pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
+                    ExecutionContext exe_ctx;
+                    CalculateExecutionContext(exe_ctx);
+                    Disassembler::Disassemble (debugger,
+                                               target_arch,
+                                               NULL,
+                                               exe_ctx,
+                                               pc_range,
+                                               disasm_lines,
+                                               0,
+                                               Disassembler::eOptionMarkPCAddress,
+                                               strm);
+                }
+            }
+            break;
         }
     }
     return true;