[Lldb-commits] [lldb] r262912 - A few more improvements on the way to the command alias refactoring

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 7 21:37:16 PST 2016


Author: enrico
Date: Mon Mar  7 23:37:15 2016
New Revision: 262912

URL: http://llvm.org/viewvc/llvm-project?rev=262912&view=rev
Log:
A few more improvements on the way to the command alias refactoring

- move alias help generation to CommandAlias, out of CommandInterpreter
- make alias creation use argument strings instead of OptionArgVectorSP; the former is a more reasonable currency than the latter
- remove m_is_alias from CommandObject, it wasn't actually being used


Modified:
    lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
    lldb/trunk/include/lldb/Interpreter/CommandObject.h
    lldb/trunk/source/Commands/CommandObjectCommands.cpp
    lldb/trunk/source/Commands/CommandObjectHelp.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/source/Interpreter/CommandObject.cpp

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=262912&r1=262911&r2=262912&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Mon Mar  7 23:37:15 2016
@@ -208,6 +208,9 @@ public:
         CommandAlias (lldb::CommandObjectSP cmd_sp = nullptr,
                       OptionArgVectorSP args_sp = nullptr);
         
+        void
+        GetAliasHelp (StreamString &help_string);
+        
         static bool
         ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
                                  const char *options_args,
@@ -302,11 +305,11 @@ public:
     bool
     UserCommandExists (const char *cmd);
 
-    void
-    AddAlias (const char *alias_name, 
+    bool
+    AddAlias (const char *alias_name,
               lldb::CommandObjectSP& command_obj_sp,
-              OptionArgVectorSP args_sp);
-
+              const char *args_string = nullptr);
+    
     // Remove a command if it is removable (python or regex command)
     bool
     RemoveCommand (const char *cmd);
@@ -436,7 +439,6 @@ public:
 
     void
     GetAliasHelp (const char *alias_name, 
-                  const char *command_name, 
                   StreamString &help_string);
 
     void

Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=262912&r1=262911&r2=262912&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Mon Mar  7 23:37:15 2016
@@ -190,12 +190,6 @@ public:
     virtual bool
     IsRemovable () const { return false; }
     
-    bool
-    IsAlias () { return m_is_alias; }
-    
-    void
-    SetIsAlias (bool value) { m_is_alias = value; }
-
     virtual bool
     IsMultiwordObject () { return false; }
 
@@ -527,7 +521,6 @@ protected:
     std::string m_cmd_help_short;
     std::string m_cmd_help_long;
     std::string m_cmd_syntax;
-    bool m_is_alias;
     Flags m_flags;
     std::vector<CommandArgumentEntry> m_arguments;
     lldb::CommandOverrideCallback m_deprecated_command_override_callback;

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=262912&r1=262911&r2=262912&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Mon Mar  7 23:37:15 2016
@@ -621,33 +621,31 @@ protected:
             
             OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector);
         
-            CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj.GetCommandName(), false);
-
-            if (!CommandInterpreter::CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, raw_command_string.c_str(), option_arg_vector_sp))
-            {
-                result.AppendError ("Unable to create requested alias.\n");
-                result.SetStatus (eReturnStatusFailed);
-                return false;
-            }
-            
-            // Create the alias
-            if (m_interpreter.AliasExists (alias_command.c_str())
-                || m_interpreter.UserCommandExists (alias_command.c_str()))
-            {
-                result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n",
-                                                alias_command.c_str());
-            }
-            
-            if (cmd_obj_sp)
+            if (CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj.GetCommandName(), false))
             {
-                m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp, option_arg_vector_sp);
-                result.SetStatus (eReturnStatusSuccessFinishNoResult);
+                if (m_interpreter.AliasExists (alias_command.c_str())
+                    || m_interpreter.UserCommandExists (alias_command.c_str()))
+                {
+                    result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n",
+                                                    alias_command.c_str());
+                }
+                if (m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp, raw_command_string.c_str()))
+                {
+                    result.SetStatus (eReturnStatusSuccessFinishNoResult);
+                }
+                else
+                {
+                    result.AppendError ("Unable to create requested alias.\n");
+                    result.SetStatus (eReturnStatusFailed);
+                }
+
             }
             else
             {
                 result.AppendError ("Unable to create requested alias.\n");
                 result.SetStatus (eReturnStatusFailed);
             }
+
             return result.Succeeded ();
     }
     
@@ -715,37 +713,36 @@ protected:
 
                  // Verify & handle any options/arguments passed to the alias command
 
+                 std::string args_string;
+                 
                  if (args.GetArgumentCount () > 0)
                  {
                     CommandObjectSP tmp_sp = m_interpreter.GetCommandSPExact (cmd_obj->GetCommandName(), false);
                     if (use_subcommand)
                         tmp_sp = m_interpreter.GetCommandSPExact (sub_cmd_obj->GetCommandName(), false);
                         
-                    std::string args_string;
                     args.GetCommandString (args_string);
-                    
-                    if (!CommandInterpreter::CommandAlias::ProcessAliasOptionsArgs (tmp_sp, args_string.c_str(), option_arg_vector_sp))
-                    {
-                        result.AppendError ("Unable to create requested alias.\n");
-                        result.SetStatus (eReturnStatusFailed);
-                        return false;
-                    }
                  }
-
-                 // Create the alias.
-
+                 
                  if (m_interpreter.AliasExists (alias_command.c_str())
                      || m_interpreter.UserCommandExists (alias_command.c_str()))
                  {
-                     result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n", 
+                     result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n",
                                                      alias_command.c_str());
                  }
-
-                 if (use_subcommand)
-                     m_interpreter.AddAlias (alias_command.c_str(), subcommand_obj_sp, option_arg_vector_sp);
+                 
+                 if (m_interpreter.AddAlias(alias_command.c_str(),
+                                            use_subcommand ? subcommand_obj_sp : command_obj_sp,
+                                            args_string.c_str()))
+                 {
+                     result.SetStatus (eReturnStatusSuccessFinishNoResult);
+                 }
                  else
-                     m_interpreter.AddAlias (alias_command.c_str(), command_obj_sp, option_arg_vector_sp);
-                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
+                 {
+                     result.AppendError ("Unable to create requested alias.\n");
+                     result.SetStatus (eReturnStatusFailed);
+                     return false;
+                 }
              }
              else
              {

Modified: lldb/trunk/source/Commands/CommandObjectHelp.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.cpp?rev=262912&r1=262911&r2=262912&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectHelp.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectHelp.cpp Mon Mar  7 23:37:15 2016
@@ -189,7 +189,7 @@ CommandObjectHelp::DoExecute (Args& comm
             if (is_alias_command)
             {
                 StreamString sstr;
-                m_interpreter.GetAliasHelp (alias_name.c_str(), cmd_obj->GetCommandName(), sstr);
+                m_interpreter.GetAlias(alias_name.c_str()).GetAliasHelp(sstr);
                 result.GetOutputStream().Printf ("\n'%s' is an abbreviation for %s\n", alias_name.c_str(), sstr.GetData());
             }
         }

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=262912&r1=262911&r2=262912&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Mon Mar  7 23:37:15 2016
@@ -104,6 +104,40 @@ CommandInterpreter::CommandAlias::Comman
 {
 }
 
+void
+CommandInterpreter::CommandAlias::GetAliasHelp (StreamString &help_string)
+{
+    const char* command_name = m_underlying_command_sp->GetCommandName();
+    help_string.Printf ("'%s", command_name);
+    
+    if (m_option_args_sp)
+    {
+        OptionArgVector *options = m_option_args_sp.get();
+        for (size_t i = 0; i < options->size(); ++i)
+        {
+            OptionArgPair cur_option = (*options)[i];
+            std::string opt = cur_option.first;
+            OptionArgValue value_pair = cur_option.second;
+            std::string value = value_pair.second;
+            if (opt.compare("<argument>") == 0)
+            {
+                help_string.Printf (" %s", value.c_str());
+            }
+            else
+            {
+                help_string.Printf (" %s", opt.c_str());
+                if ((value.compare ("<no-argument>") != 0)
+                    && (value.compare ("<need-argument") != 0))
+                {
+                    help_string.Printf (" %s", value.c_str());
+                }
+            }
+        }
+    }
+    
+    help_string.Printf ("'");
+}
+
 bool
 CommandInterpreter::CommandAlias::ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
                                                            const char *options_args,
@@ -252,149 +286,145 @@ CommandInterpreter::Initialize ()
     CommandObjectSP cmd_obj_sp = GetCommandSPExact ("quit", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("q", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("exit", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("q", cmd_obj_sp);
+        AddAlias ("exit", cmd_obj_sp);
     }
     
     cmd_obj_sp = GetCommandSPExact ("_regexp-attach",false);
     if (cmd_obj_sp)
     {
-        AddAlias ("attach", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("attach", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("process detach",false);
     if (cmd_obj_sp)
     {
-        AddAlias ("detach", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("detach", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("process continue", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("c", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("continue", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("c", cmd_obj_sp);
+        AddAlias ("continue", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-break",false);
     if (cmd_obj_sp)
-        AddAlias ("b", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("b", cmd_obj_sp);
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-tbreak",false);
     if (cmd_obj_sp)
-        AddAlias ("tbreak", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("tbreak", cmd_obj_sp);
 
     cmd_obj_sp = GetCommandSPExact ("thread step-inst", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("stepi", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("si", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("stepi", cmd_obj_sp);
+        AddAlias ("si", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("thread step-inst-over", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("nexti", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("ni", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("nexti", cmd_obj_sp);
+        AddAlias ("ni", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("thread step-in", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("s", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("step", cmd_obj_sp, alias_arguments_vector_sp);
-        
-        alias_arguments_vector_sp.reset (new OptionArgVector);
-        CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, "--end-linenumber block --step-in-target %1", alias_arguments_vector_sp);
-        AddAlias ("sif", cmd_obj_sp, alias_arguments_vector_sp);
-        alias_arguments_vector_sp.reset(new OptionArgVector);
+        AddAlias ("s", cmd_obj_sp);
+        AddAlias ("step", cmd_obj_sp);
+        AddAlias ("sif", cmd_obj_sp, "--end-linenumber block --step-in-target %1");
     }
 
     cmd_obj_sp = GetCommandSPExact ("thread step-over", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("n", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("next", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("n", cmd_obj_sp);
+        AddAlias ("next", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("thread step-out", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("finish", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("finish", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("frame select", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("f", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("f", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("thread select", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("t", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("t", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-jump",false);
     if (cmd_obj_sp)
     {
-        AddAlias ("j", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("jump", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("j", cmd_obj_sp);
+        AddAlias ("jump", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-list", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("l", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("list", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("l", cmd_obj_sp);
+        AddAlias ("list", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-env", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("env", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("env", cmd_obj_sp);
     }
 
     cmd_obj_sp = GetCommandSPExact ("memory read", false);
     if (cmd_obj_sp)
-        AddAlias ("x", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("x", cmd_obj_sp);
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-up", false);
     if (cmd_obj_sp)
-        AddAlias ("up", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("up", cmd_obj_sp);
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-down", false);
     if (cmd_obj_sp)
-        AddAlias ("down", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("down", cmd_obj_sp);
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-display", false);
     if (cmd_obj_sp)
-        AddAlias ("display", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("display", cmd_obj_sp);
         
     cmd_obj_sp = GetCommandSPExact ("disassemble", false);
     if (cmd_obj_sp)
-        AddAlias ("dis", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("dis", cmd_obj_sp);
 
     cmd_obj_sp = GetCommandSPExact ("disassemble", false);
     if (cmd_obj_sp)
-        AddAlias ("di", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("di", cmd_obj_sp);
 
 
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-undisplay", false);
     if (cmd_obj_sp)
-        AddAlias ("undisplay", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("undisplay", cmd_obj_sp);
 
     cmd_obj_sp = GetCommandSPExact ("_regexp-bt", false);
     if (cmd_obj_sp)
-        AddAlias ("bt", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("bt", cmd_obj_sp);
 
     cmd_obj_sp = GetCommandSPExact ("target create", false);
     if (cmd_obj_sp)
-        AddAlias ("file", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("file", cmd_obj_sp);
 
     cmd_obj_sp = GetCommandSPExact ("target modules", false);
     if (cmd_obj_sp)
-        AddAlias ("image", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("image", cmd_obj_sp);
 
 
     alias_arguments_vector_sp.reset(new OptionArgVector);
@@ -402,20 +432,16 @@ CommandInterpreter::Initialize ()
     cmd_obj_sp = GetCommandSPExact ("expression", false);
     if (cmd_obj_sp)
     {        
-        CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp);
-        AddAlias ("p", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("print", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("call", cmd_obj_sp, alias_arguments_vector_sp);
-        alias_arguments_vector_sp.reset (new OptionArgVector);
-        CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, "-O -- ", alias_arguments_vector_sp);
-        AddAlias ("po", cmd_obj_sp, alias_arguments_vector_sp);
-        alias_arguments_vector_sp.reset(new OptionArgVector);
+        AddAlias ("p", cmd_obj_sp, "--");
+        AddAlias ("print", cmd_obj_sp, "--");
+        AddAlias ("call", cmd_obj_sp, "--");
+        AddAlias ("po", cmd_obj_sp, "-O --");
     }
     
     cmd_obj_sp = GetCommandSPExact ("process kill", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("kill", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("kill", cmd_obj_sp);
     }
     
     cmd_obj_sp = GetCommandSPExact ("process launch", false);
@@ -423,40 +449,35 @@ CommandInterpreter::Initialize ()
     {
         alias_arguments_vector_sp.reset (new OptionArgVector);
 #if defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
-        ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp);
+        AddAlias ("r", cmd_obj_sp, "--");
+        AddAlias ("run", cmd_obj_sp, "--");
 #else
     #if defined(__APPLE__)
         std::string shell_option;
         shell_option.append("--shell-expand-args");
         shell_option.append(" true");
         shell_option.append(" --");
-        CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, shell_option.c_str(), alias_arguments_vector_sp);
+        AddAlias ("r", cmd_obj_sp, "--shell-expand-args true --");
+        AddAlias ("run", cmd_obj_sp, "--shell-expand-args true --");
     #else
-        std::string shell_option;
-        shell_option.append("--shell=");
-        shell_option.append(HostInfo::GetDefaultShell().GetPath());
-        shell_option.append(" --");
-        CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, shell_option.c_str(), alias_arguments_vector_sp);
+        StreamString defaultshell;
+        defaultshell.Printf("--shell=%s --", HostInfo::GetDefaultShell().GetPath());
+        AddAlias ("r", cmd_obj_sp, defaultshell.GetData());
+        AddAlias ("run", cmd_obj_sp, defaultshell.GetData());
     #endif
 #endif
-        AddAlias ("r", cmd_obj_sp, alias_arguments_vector_sp);
-        AddAlias ("run", cmd_obj_sp, alias_arguments_vector_sp);
-        alias_arguments_vector_sp.reset(new OptionArgVector);
     }
     
     cmd_obj_sp = GetCommandSPExact ("target symbols add", false);
     if (cmd_obj_sp)
     {
-        AddAlias ("add-dsym", cmd_obj_sp, alias_arguments_vector_sp);
+        AddAlias ("add-dsym", cmd_obj_sp);
     }
     
     cmd_obj_sp = GetCommandSPExact ("breakpoint set", false);
     if (cmd_obj_sp)
     {
-        alias_arguments_vector_sp.reset (new OptionArgVector);
-        CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, "--func-regex %1", alias_arguments_vector_sp);
-        AddAlias ("rbreak", cmd_obj_sp, alias_arguments_vector_sp);
-        alias_arguments_vector_sp.reset(new OptionArgVector);
+        AddAlias ("rbreak", cmd_obj_sp, "--func-regex %1");
     }
 }
 
@@ -1122,16 +1143,21 @@ CommandInterpreter::UserCommandExists (c
     return m_user_dict.find(cmd) != m_user_dict.end();
 }
 
-void
+bool
 CommandInterpreter::AddAlias (const char *alias_name,
-                              CommandObjectSP& command_obj_sp,
-                              OptionArgVectorSP args_sp)
+                              lldb::CommandObjectSP& command_obj_sp,
+                              const char *args_string)
 {
     if (command_obj_sp.get())
         assert((this == &command_obj_sp->GetCommandInterpreter()) && "tried to add a CommandObject from a different interpreter");
-
-    command_obj_sp->SetIsAlias (true);
-    m_alias_dict[alias_name] = {command_obj_sp,args_sp};
+    
+    OptionArgVectorSP args_sp(new OptionArgVector);
+    if (CommandAlias::ProcessAliasOptionsArgs(command_obj_sp, args_string, args_sp))
+    {
+        m_alias_dict[alias_name] = CommandAlias(command_obj_sp,args_sp);
+        return true;
+    }
+    return false;
 }
 
 bool
@@ -1174,40 +1200,6 @@ CommandInterpreter::RemoveUser (const ch
 }
 
 void
-CommandInterpreter::GetAliasHelp (const char *alias_name, const char *command_name, StreamString &help_string)
-{
-    help_string.Printf ("'%s", command_name);
-    OptionArgVectorSP option_arg_vector_sp = GetAlias(alias_name).m_option_args_sp;
-
-    if (option_arg_vector_sp)
-    {
-        OptionArgVector *options = option_arg_vector_sp.get();
-        for (size_t i = 0; i < options->size(); ++i)
-        {
-            OptionArgPair cur_option = (*options)[i];
-            std::string opt = cur_option.first;
-            OptionArgValue value_pair = cur_option.second;
-            std::string value = value_pair.second;
-            if (opt.compare("<argument>") == 0)
-            {
-                help_string.Printf (" %s", value.c_str());
-            }
-            else
-            {
-                help_string.Printf (" %s", opt.c_str());
-                if ((value.compare ("<no-argument>") != 0)
-                    && (value.compare ("<need-argument") != 0))
-                {
-                    help_string.Printf (" %s", value.c_str());
-                }
-            }
-        }
-    }
-
-    help_string.Printf ("'");
-}
-
-void
 CommandInterpreter::GetHelp (CommandReturnObject &result,
                              uint32_t cmd_types)
 {
@@ -1251,7 +1243,7 @@ CommandInterpreter::GetHelp (CommandRetu
             StreamString translation_and_help;
             std::string entry_name = alias_pos->first;
             std::string second_entry = alias_pos->second.m_underlying_command_sp->GetCommandName();
-            GetAliasHelp (alias_pos->first.c_str(), alias_pos->second.m_underlying_command_sp->GetCommandName(), sstr);
+            alias_pos->second.GetAliasHelp(sstr);
             
             translation_and_help.Printf ("(%s)  %s", sstr.GetData(), alias_pos->second.m_underlying_command_sp->GetHelp());
             OutputFormattedHelpText (result.GetOutputStream(), alias_pos->first.c_str(), "--",

Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=262912&r1=262911&r2=262912&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Mon Mar  7 23:37:15 2016
@@ -53,7 +53,6 @@ CommandObject::CommandObject
     m_cmd_help_short (),
     m_cmd_help_long (),
     m_cmd_syntax (),
-    m_is_alias (false),
     m_flags (flags),
     m_arguments(),
     m_deprecated_command_override_callback (nullptr),




More information about the lldb-commits mailing list