[Lldb-commits] [lldb] r264108 - Make it so that a command alias can actually remove the help/long help from its parent command by setting itself to an empty help string

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 22 15:13:00 PDT 2016


Author: enrico
Date: Tue Mar 22 17:12:59 2016
New Revision: 264108

URL: http://llvm.org/viewvc/llvm-project?rev=264108&view=rev
Log:
Make it so that a command alias can actually remove the help/long help from its parent command by setting itself to an empty help string


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

Modified: lldb/trunk/include/lldb/Interpreter/CommandAlias.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandAlias.h?rev=264108&r1=264107&r2=264108&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandAlias.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandAlias.h Tue Mar 22 17:12:59 2016
@@ -88,6 +88,12 @@ public:
     const char*
     GetHelpLong () override;
     
+    void
+    SetHelp (const char * str) override;
+    
+    void
+    SetHelpLong (const char * str) override;
+    
     bool
     Execute(const char *args_string, CommandReturnObject &result) override;
     
@@ -105,6 +111,8 @@ private:
     std::string m_option_string;
     OptionArgVectorSP m_option_args_sp ;
     LazyBool m_is_dashdash_alias;
+    bool m_did_set_help : 1;
+    bool m_did_set_help_long : 1;
 };
 } // namespace lldb_private
 

Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=264108&r1=264107&r2=264108&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Tue Mar 22 17:12:59 2016
@@ -154,19 +154,13 @@ public:
     const char *
     GetCommandName ();
 
-    void
+    virtual void
     SetHelp (const char * str);
 
-    void
-    SetHelp (std::string str);
-    
-    void
+    virtual void
     SetHelpLong (const char * str);
 
     void
-    SetHelpLong (std::string str);
-
-    void
     SetSyntax (const char *str);
     
     // override this to return true if you want to enable the user to delete

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=264108&r1=264107&r2=264108&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Tue Mar 22 17:12:59 2016
@@ -1345,7 +1345,7 @@ public:
                 std::string docstring;
                 m_fetched_help_long = scripter->GetDocumentationForItem(m_function_name.c_str(),docstring);
                 if (!docstring.empty())
-                    SetHelpLong(docstring);
+                    SetHelpLong(docstring.c_str());
             }
         }
         return CommandObjectRaw::GetHelpLong();
@@ -1446,7 +1446,7 @@ public:
                 std::string docstring;
                 m_fetched_help_short = scripter->GetShortHelpForCommandObject(m_cmd_obj_sp,docstring);
                 if (!docstring.empty())
-                    SetHelp(docstring);
+                    SetHelp(docstring.c_str());
             }
         }
         return CommandObjectRaw::GetHelp();
@@ -1463,7 +1463,7 @@ public:
                 std::string docstring;
                 m_fetched_help_long = scripter->GetLongHelpForCommandObject(m_cmd_obj_sp,docstring);
                 if (!docstring.empty())
-                    SetHelpLong(docstring);
+                    SetHelpLong(docstring.c_str());
             }
         }
         return CommandObjectRaw::GetHelpLong();

Modified: lldb/trunk/source/Interpreter/CommandAlias.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandAlias.cpp?rev=264108&r1=264107&r2=264108&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandAlias.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandAlias.cpp Tue Mar 22 17:12:59 2016
@@ -87,7 +87,9 @@ CommandAlias::CommandAlias (CommandInter
 m_underlying_command_sp(),
 m_option_string(options_args ? options_args : ""),
 m_option_args_sp(new OptionArgVector),
-m_is_dashdash_alias(eLazyBoolCalculate)
+m_is_dashdash_alias(eLazyBoolCalculate),
+m_did_set_help(false),
+m_did_set_help_long(false)
 {
     if (ProcessAliasOptionsArgs(cmd_sp, options_args, m_option_args_sp))
     {
@@ -259,10 +261,24 @@ CommandAlias::Desugar ()
 
 // allow CommandAlias objects to provide their own help, but fallback to the info
 // for the underlying command if no customization has been provided
+void
+CommandAlias::SetHelp (const char * str)
+{
+    this->CommandObject::SetHelp(str);
+    m_did_set_help = true;
+}
+
+void
+CommandAlias::SetHelpLong (const char * str)
+{
+    this->CommandObject::SetHelpLong(str);
+    m_did_set_help_long = true;
+}
+
 const char*
 CommandAlias::GetHelp ()
 {
-    if (!m_cmd_help_short.empty())
+    if (!m_cmd_help_short.empty() || m_did_set_help)
         return m_cmd_help_short.c_str();
     if (IsValid())
         return m_underlying_command_sp->GetHelp();
@@ -272,7 +288,7 @@ CommandAlias::GetHelp ()
 const char*
 CommandAlias::GetHelpLong ()
 {
-    if (!m_cmd_help_long.empty())
+    if (!m_cmd_help_long.empty() || m_did_set_help_long)
         return m_cmd_help_long.c_str();
     if (IsValid())
         return m_underlying_command_sp->GetHelpLong();

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=264108&r1=264107&r2=264108&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue Mar 22 17:12:59 2016
@@ -344,10 +344,14 @@ CommandInterpreter::Initialize ()
     cmd_obj_sp = GetCommandSPExact ("expression", false);
     if (cmd_obj_sp)
     {        
-        AddAlias ("p", cmd_obj_sp, "--");
-        AddAlias ("print", cmd_obj_sp, "--");
-        AddAlias ("call", cmd_obj_sp, "--");
-        AddAlias ("po", cmd_obj_sp, "-O --");
+        AddAlias ("p", cmd_obj_sp, "--")->SetHelpLong("");
+        AddAlias ("print", cmd_obj_sp, "--")->SetHelpLong("");
+        AddAlias ("call", cmd_obj_sp, "--")->SetHelpLong("");
+        if (auto po = AddAlias ("po", cmd_obj_sp, "-O --"))
+        {
+            po->SetHelp("Evaluate an expression in the current program context, using user defined variables and variables currently in scope, and display the result of evaluation in a language-specific manner.");
+            po->SetHelpLong("");
+        }
     }
     
     cmd_obj_sp = GetCommandSPExact ("process kill", false);

Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=264108&r1=264107&r2=264108&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Tue Mar 22 17:12:59 2016
@@ -118,25 +118,19 @@ CommandObject::SetCommandName (const cha
 void
 CommandObject::SetHelp (const char *cstr)
 {
-    m_cmd_help_short = cstr;
-}
-
-void
-CommandObject::SetHelp (std::string str)
-{
-    m_cmd_help_short = str;
+    if (cstr)
+        m_cmd_help_short = cstr;
+    else
+        m_cmd_help_short.assign("");
 }
 
 void
 CommandObject::SetHelpLong (const char *cstr)
 {
-    m_cmd_help_long = cstr;
-}
-
-void
-CommandObject::SetHelpLong (std::string str)
-{
-    m_cmd_help_long = str;
+    if (cstr)
+        m_cmd_help_long = cstr;
+    else
+        m_cmd_help_long.assign("");
 }
 
 void
@@ -932,23 +926,26 @@ CommandObject::GenerateHelpText (Stream
         if ((long_help != nullptr)
             && (strlen (long_help) > 0))
             FormatLongHelpText (output_strm, long_help);
-        if (WantsRawCommandString() && !WantsCompletion())
+        if (!IsDashDashCommand())
         {
-            // Emit the message about using ' -- ' between the end of the command options and the raw input
-            // conditionally, i.e., only if the command object does not want completion.
-            interpreter.OutputFormattedHelpText (output_strm, "", "",
-                                                 "\nIMPORTANT NOTE:  Because this command takes 'raw' input, if you use any command options"
-                                                 " you must use ' -- ' between the end of the command options and the beginning of the raw input.", 1);
-        }
-        else if (GetNumArgumentEntries() > 0
-                 && GetOptions()
-                 && GetOptions()->NumCommandOptions() > 0)
-        {
-            // Also emit a warning about using "--" in case you are using a command that takes options and arguments.
-            interpreter.OutputFormattedHelpText (output_strm, "", "",
-                                                 "\nThis command takes options and free-form arguments.  If your arguments resemble"
-                                                 " option specifiers (i.e., they start with a - or --), you must use ' -- ' between"
-                                                 " the end of the command options and the beginning of the arguments.", 1);
+            if (WantsRawCommandString() && !WantsCompletion())
+            {
+                // Emit the message about using ' -- ' between the end of the command options and the raw input
+                // conditionally, i.e., only if the command object does not want completion.
+                interpreter.OutputFormattedHelpText (output_strm, "", "",
+                                                     "\nIMPORTANT NOTE:  Because this command takes 'raw' input, if you use any command options"
+                                                     " you must use ' -- ' between the end of the command options and the beginning of the raw input.", 1);
+            }
+            else if (GetNumArgumentEntries() > 0
+                     && GetOptions()
+                     && GetOptions()->NumCommandOptions() > 0)
+            {
+                // Also emit a warning about using "--" in case you are using a command that takes options and arguments.
+                interpreter.OutputFormattedHelpText (output_strm, "", "",
+                                                     "\nThis command takes options and free-form arguments.  If your arguments resemble"
+                                                     " option specifiers (i.e., they start with a - or --), you must use ' -- ' between"
+                                                     " the end of the command options and the beginning of the arguments.", 1);
+            }
         }
     }
     else if (IsMultiwordObject())




More information about the lldb-commits mailing list