[Lldb-commits] [lldb] r139377 - in /lldb/trunk: include/lldb/Interpreter/CommandInterpreter.h source/Commands/CommandObjectHelp.cpp source/Commands/CommandObjectHelp.h source/Interpreter/CommandInterpreter.cpp test/functionalities/alias/TestAliases.py test/functionalities/command_python/TestCommandPython.py test/help/TestHelp.py

Enrico Granata granata.enrico at gmail.com
Fri Sep 9 10:49:36 PDT 2011


Author: enrico
Date: Fri Sep  9 12:49:36 2011
New Revision: 139377

URL: http://llvm.org/viewvc/llvm-project?rev=139377&view=rev
Log:
Adding two new options to the 'help' command:
 --show-aliases (-a) shows aliases for commands, as well as built-in commands
 --hide-user-defined (-u) hides user defined commands
by default 'help' without arguments does not show aliases anymore. to see them, add --show-aliases
to have only built-in commands appear, use 'help --hide-user-defined' ; there is currently no way to hide
built-in commands from the help output
'help command' is not changed by this commit, and help is shown even if command is an alias and -a is not specified

Modified:
    lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
    lldb/trunk/source/Commands/CommandObjectHelp.cpp
    lldb/trunk/source/Commands/CommandObjectHelp.h
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/test/functionalities/alias/TestAliases.py
    lldb/trunk/test/functionalities/command_python/TestCommandPython.py
    lldb/trunk/test/help/TestHelp.py

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=139377&r1=139376&r2=139377&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Fri Sep  9 12:49:36 2011
@@ -259,7 +259,7 @@
 
     void
     GetHelp (CommandReturnObject &result,
-             CommandTypes types = eCommandTypesAllThem);
+             uint32_t types = eCommandTypesAllThem);
 
     void
     GetAliasHelp (const char *alias_name, 

Modified: lldb/trunk/source/Commands/CommandObjectHelp.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.cpp?rev=139377&r1=139376&r2=139377&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectHelp.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectHelp.cpp Fri Sep  9 12:49:36 2011
@@ -29,7 +29,7 @@
     CommandObject (interpreter,
                    "help",
                    "Show a list of all debugger commands, or give details about specific commands.",
-                   "help [<cmd-name>]")
+                   "help [<cmd-name>]"), m_options (interpreter)
 {
     CommandArgumentEntry arg;
     CommandArgumentData command_arg;
@@ -49,6 +49,14 @@
 {
 }
 
+OptionDefinition
+CommandObjectHelp::CommandOptions::g_option_table[] =
+{
+    { LLDB_OPT_SET_ALL, false, "show-aliases", 'a', no_argument, NULL, 0, eArgTypeNone,         "Show aliases in the command list."},
+    { LLDB_OPT_SET_ALL, false, "hide-user-commands", 'u', no_argument, NULL, 0, eArgTypeNone,         "Hide user-defined commands from the list."},
+    { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
+};
+
 bool
 CommandObjectHelp::Execute (Args& command, CommandReturnObject &result)
 {
@@ -56,12 +64,18 @@
     CommandObject *cmd_obj;
     const int argc = command.GetArgumentCount ();
     
-    // 'help' doesn't take any options or arguments, other than command names.  If argc is 0, we show the user
-    // all commands and aliases.  Otherwise every argument must be the name of a command or a sub-command.
+    // 'help' doesn't take any arguments, other than command names.  If argc is 0, we show the user
+    // all commands (aliases and user commands if asked for).  Otherwise every argument must be the name of a command or a sub-command.
     if (argc == 0)
     {
+        uint32_t cmd_types = CommandInterpreter::eCommandTypesBuiltin;
+        if (m_options.m_show_aliases)
+            cmd_types |= CommandInterpreter::eCommandTypesAliases;
+        if (m_options.m_show_user_defined)
+            cmd_types |= CommandInterpreter::eCommandTypesUserDef;
+
         result.SetStatus (eReturnStatusSuccessFinishNoResult);
-        m_interpreter.GetHelp (result);  // General help, for ALL commands.
+        m_interpreter.GetHelp (result, cmd_types);  // General help
     }
     else
     {

Modified: lldb/trunk/source/Commands/CommandObjectHelp.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.h?rev=139377&r1=139376&r2=139377&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectHelp.h (original)
+++ lldb/trunk/source/Commands/CommandObjectHelp.h Fri Sep  9 12:49:36 2011
@@ -15,6 +15,7 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Interpreter/CommandObject.h"
+#include "lldb/Interpreter/Options.h"
 
 namespace lldb_private {
 
@@ -43,6 +44,71 @@
                       int max_return_elements,
                       bool &word_complete,
                       StringList &matches);
+    
+    class CommandOptions : public Options
+    {
+    public:
+        
+        CommandOptions (CommandInterpreter &interpreter) :
+        Options (interpreter)
+        {
+        }
+        
+        virtual
+        ~CommandOptions (){}
+        
+        virtual Error
+        SetOptionValue (uint32_t option_idx, const char *option_arg)
+        {
+            Error error;
+            char short_option = (char) m_getopt_table[option_idx].val;
+            
+            switch (short_option)
+            {
+                case 'a':
+                    m_show_aliases = true;
+                    break;
+                case 'u':
+                    m_show_user_defined = false;
+                    break;
+                default:
+                    error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
+                    break;
+            }
+            
+            return error;
+        }
+        
+        void
+        OptionParsingStarting ()
+        {
+            m_show_aliases = false;
+            m_show_user_defined = true;
+        }
+        
+        const OptionDefinition*
+        GetDefinitions ()
+        {
+            return g_option_table;
+        }
+        
+        // Options table: Required for subclasses of Options.
+        
+        static OptionDefinition g_option_table[];
+        
+        // Instance variables to hold the values for command options.
+        
+        bool m_show_aliases;
+        bool m_show_user_defined;        
+    };
+    
+    CommandOptions m_options;
+    
+    virtual Options *
+    GetOptions ()
+    {
+        return &m_options;
+    }
 
 };
 

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=139377&r1=139376&r2=139377&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Fri Sep  9 12:49:36 2011
@@ -701,7 +701,7 @@
 
 void
 CommandInterpreter::GetHelp (CommandReturnObject &result,
-                             CommandTypes cmd_types)
+                             uint32_t cmd_types)
 {
     CommandObject::CommandMap::const_iterator pos;
     uint32_t max_len = FindLongestCommandWord (m_command_dict);

Modified: lldb/trunk/test/functionalities/alias/TestAliases.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/alias/TestAliases.py?rev=139377&r1=139376&r2=139377&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/alias/TestAliases.py (original)
+++ lldb/trunk/test/functionalities/alias/TestAliases.py Fri Sep  9 12:49:36 2011
@@ -90,6 +90,14 @@
         self.expect ("help run",
                      substrs = [ "'run' is an abbreviation for 'process launch --'" ])
 
+        self.expect ("help -a run",
+                     substrs = [ "'run' is an abbreviation for 'process launch --'" ])
+
+        self.expect ("help -a",
+                     substrs = [ 'run', 'process launch' ])
+
+        self.expect ("help", matching=False,
+                     substrs = [ "'run'", 'process launch' ])
 
         self.expect ("run",
                      patterns = [ "Process .* launched: .*a.out" ])

Modified: lldb/trunk/test/functionalities/command_python/TestCommandPython.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_python/TestCommandPython.py?rev=139377&r1=139376&r2=139377&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/command_python/TestCommandPython.py (original)
+++ lldb/trunk/test/functionalities/command_python/TestCommandPython.py Fri Sep  9 12:49:36 2011
@@ -38,6 +38,18 @@
                     substrs = ['Just a docstring for welcome_impl',
                                'A command that says hello to LLDB users'])
 
+        self.expect("help",
+                    substrs = ['Run Python function welcome.welcome_impl',
+                               'welcome'])
+
+        self.expect("help -a",
+                    substrs = ['Run Python function welcome.welcome_impl',
+                               'welcome'])
+
+        self.expect("help -u", matching=False,
+                    substrs = ['Run Python function welcome.welcome_impl',
+                               'welcome'])
+
         self.runCmd("command script delete welcome");
 
         self.expect('welcome Enrico', matching=False, error=True,

Modified: lldb/trunk/test/help/TestHelp.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=139377&r1=139376&r2=139377&view=diff
==============================================================================
--- lldb/trunk/test/help/TestHelp.py (original)
+++ lldb/trunk/test/help/TestHelp.py Fri Sep  9 12:49:36 2011
@@ -18,6 +18,18 @@
         self.expect("help",
             startstr = 'The following is a list of built-in, permanent debugger commands')
 
+        self.expect("help", matching=False,
+                    substrs = ['next'])
+        
+        self.expect("help -a", matching=True,
+                    substrs = ['next'])
+    
+    def test_help_on_help(self):
+        """Testing the help on the help facility."""
+        self.expect("help help", matching=True,
+                    substrs = ['--show-aliases',
+                               '--hide-user-commands'])
+
     def version_number_string(self):
         """Helper function to find the version number string of lldb."""
         plist = os.path.join(os.environ["LLDB_SRC"], "resources", "LLDB-Info.plist")





More information about the lldb-commits mailing list