disassemble with no arguments disassembles at the pc.  Also got "disassemble -f" to work, that had gotten broken at some point in the past.

git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@138929 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectDisassemble.cpp b/source/Commands/CommandObjectDisassemble.cpp
index 90554ea..8115a87 100644
--- a/source/Commands/CommandObjectDisassemble.cpp
+++ b/source/Commands/CommandObjectDisassemble.cpp
@@ -37,12 +37,14 @@
     num_lines_context(0),
     num_instructions (0),
     func_name(),
+    cur_function (false),
     start_addr(),
     end_addr (),
     at_pc (false),
     frame_line (false),
     plugin_name (),
-    arch() 
+    arch(),
+    some_location_specified (false) 
 {
     OptionParsingStarting();
 }
@@ -89,6 +91,7 @@
 
         if (start_addr == LLDB_INVALID_ADDRESS)
             error.SetErrorStringWithFormat ("Invalid start address string '%s'.\n", option_arg);
+        some_location_specified = true;
         break;
     case 'e':
         end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
@@ -98,13 +101,15 @@
         if (end_addr == LLDB_INVALID_ADDRESS)
             error.SetErrorStringWithFormat ("Invalid end address string '%s'.\n", option_arg);
         break;
-
+        some_location_specified = true;
     case 'n':
         func_name.assign (option_arg);
+        some_location_specified = true;
         break;
 
     case 'p':
         at_pc = true;
+        some_location_specified = true;
         break;
 
     case 'l':
@@ -112,6 +117,7 @@
         // Disassemble the current source line kind of implies showing mixed
         // source code context. 
         show_mixed = true;
+        some_location_specified = true;
         break;
 
     case 'P':
@@ -123,8 +129,8 @@
         break;
 
     case 'f':
-        // The default action is to disassemble the function for the current frame.
-        // There's no need to set any flag.
+        cur_function = true;
+        some_location_specified = true;
         break;
 
     case 'a':
@@ -147,6 +153,7 @@
     num_lines_context = 0;
     num_instructions = 0;
     func_name.clear();
+    cur_function = false;
     at_pc = false;
     frame_line = false;
     start_addr = LLDB_INVALID_ADDRESS;
@@ -154,6 +161,16 @@
     raw = false;
     plugin_name.clear();
     arch.Clear();
+    some_location_specified = false;
+}
+
+Error
+CommandObjectDisassemble::CommandOptions::OptionParsingFinished ()
+{
+    if (!some_location_specified)
+        at_pc = true;
+    return Error();
+    
 }
 
 const OptionDefinition*
@@ -178,10 +195,10 @@
   LLDB_OPT_SET_3 |
   LLDB_OPT_SET_4 |
   LLDB_OPT_SET_5    , false , "count",          'c', required_argument  , NULL, 0, eArgTypeNumLines,    "Number of instructions to display."},
-{ LLDB_OPT_SET_3    , true  , "name",           'n', required_argument  , NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,             "Disassemble entire contents of the given function name."},
-{ LLDB_OPT_SET_4    , true  , "frame",          'f', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble from the start of the current frame's function."},
-{ LLDB_OPT_SET_5    , true  , "pc",             'p', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble around the current pc."},
-{ LLDB_OPT_SET_6    , true  , "line",           'l', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble the current frame's current source line instructions if there debug line table information, else disasemble around the pc."},
+{ LLDB_OPT_SET_3    , false  , "name",           'n', required_argument  , NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,             "Disassemble entire contents of the given function name."},
+{ LLDB_OPT_SET_4    , false  , "frame",          'f', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble from the start of the current frame's function."},
+{ LLDB_OPT_SET_5    , false  , "pc",             'p', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble around the current pc."},
+{ LLDB_OPT_SET_6    , false  , "line",           'l', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble the current frame's current source line instructions if there debug line table information, else disasemble around the pc."},
 { 0                 , false , NULL,             0,   0                  , NULL, 0, eArgTypeNone,        NULL }
 };
 
@@ -299,6 +316,12 @@
         AddressRange range;
         if (m_options.frame_line)
         {
+            if (exe_ctx.frame == NULL)
+            {
+                result.AppendError ("Cannot disassemble around the current line without a selected frame.\n");
+                result.SetStatus (eReturnStatusFailed);
+                return false;
+            }
             LineEntry pc_line_entry (exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry).line_entry);
             if (pc_line_entry.IsValid())
             {
@@ -310,6 +333,18 @@
                 m_options.show_mixed = false;
             }
         }
+        else if (m_options.cur_function)
+        {
+            if (exe_ctx.frame == NULL)
+            {
+                result.AppendError ("Cannot disassemble around the current function without a selected frame.\n");
+                result.SetStatus (eReturnStatusFailed);
+                return false;
+            }
+            Symbol *symbol = exe_ctx.frame->GetSymbolContext(eSymbolContextSymbol).symbol;
+            if (symbol)
+                range = symbol->GetAddressRangeRef();
+        }
 
         // Did the "m_options.frame_line" find a valid range already? If so
         // skip the rest...