<div dir="ltr">Hello,<div><br></div><div>This introduced an error with test_nonrunning_command_abbreviations test from test/functionalities/abbreviation/TestAbbreviations.py.</div><div><br></div><div>See <a href="http://reviews.llvm.org/D7066">http://reviews.llvm.org/D7066</a><br></div><div><br></div><div>Thanks,</div><div>Ilia</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 15, 2015 at 3:52 AM, Kate Stone <span dir="ltr"><<a href="mailto:katherine.stone@apple.com" target="_blank">katherine.stone@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kate<br>
Date: Wed Jan 14 18:52:41 2015<br>
New Revision: 226068<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=226068&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=226068&view=rev</a><br>
Log:<br>
Three related changes to help:<br>
<br>
The default help display now shows the alias collection by default, and hides commands whose named begin with an underscore.  Help is primarily useful to those unfamiliar with LLDB and should aim to answer typical questions while still being able to provide more esoteric answers when required.  To that latter end an argument to include the hidden commands in help has been added, and instead of having a help flag to show aliases there is now one to hide them.  This final change might be controversial as it repurposes the -a shorthand as the opposite of its original meaning.<br>
<br>
The previous implementation of OutputFormattedHelpText was easily confused by embedded newlines.  The new algorithm correctly breaks on the FIRST newline or LAST space/tab before the target column count rather than treating all whitespace interchangeably.<br>
<br>
Command interpreters now have the ability to specify help prologue text and a command prefix string.  Neither are used in the current LLDB sources but are required to support REPL-like extensions where LLDB commands must be prefixed and additional help text is required to explain how to access traditional debugging commands.<br>
<br>
<rdar://problem/17751929><br>
<rdar://problem/16953815><br>
<rdar://problem/16953841><br>
<rdar://problem/16930173><br>
<rdar://problem/16879028><br>
<br>
Modified:<br>
    lldb/trunk/include/lldb/Core/Debugger.h<br>
    lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h<br>
    lldb/trunk/source/Commands/CommandObjectHelp.cpp<br>
    lldb/trunk/source/Commands/CommandObjectHelp.h<br>
    lldb/trunk/source/Core/Debugger.cpp<br>
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp<br>
<br>
Modified: lldb/trunk/include/lldb/Core/Debugger.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=226068&r1=226067&r2=226068&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=226068&r1=226067&r2=226068&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Core/Debugger.h (original)<br>
+++ lldb/trunk/include/lldb/Core/Debugger.h Wed Jan 14 18:52:41 2015<br>
@@ -158,8 +158,6 @@ public:<br>
     // To get the target's source manager, call GetSourceManager on the target instead.<br>
     SourceManager &<br>
     GetSourceManager ();<br>
-<br>
-public:<br>
<br>
     lldb::TargetSP<br>
     GetSelectedTarget ()<br>
@@ -224,6 +222,12 @@ public:<br>
     ConstString<br>
     GetTopIOHandlerControlSequence(char ch);<br>
<br>
+    const char *<br>
+    GetIOHandlerCommandPrefix();<br>
+<br>
+    const char *<br>
+    GetIOHandlerHelpPrologue();<br>
+<br>
     bool<br>
     HideTopIOHandler();<br>
<br>
@@ -352,7 +356,6 @@ public:<br>
<br>
     bool<br>
     GetNotifyVoid () const;<br>
-<br>
<br>
     const ConstString &<br>
     GetInstanceName()<br>
<br>
Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=226068&r1=226067&r2=226068&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=226068&r1=226067&r2=226068&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)<br>
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Wed Jan 14 18:52:41 2015<br>
@@ -224,6 +224,7 @@ public:<br>
         eCommandTypesBuiltin = 0x0001,  // native commands such as "frame"<br>
         eCommandTypesUserDef = 0x0002,  // scripted commands<br>
         eCommandTypesAliases = 0x0004,  // aliases such as "po"<br>
+        eCommandTypesHidden  = 0x0008,  // commands prefixed with an underscore<br>
         eCommandTypesAllThem = 0xFFFF   // all commands<br>
     };<br>
<br>
@@ -431,6 +432,11 @@ public:<br>
                   StreamString &help_string);<br>
<br>
     void<br>
+    OutputFormattedHelpText (Stream &strm,<br>
+                             const char *prefix,<br>
+                             const char *help_text);<br>
+<br>
+    void<br>
     OutputFormattedHelpText (Stream &stream,<br>
                              const char *command_word,<br>
                              const char *separator,<br>
@@ -607,6 +613,9 @@ public:<br>
                                     bool asynchronously,<br>
                                     void *baton);<br>
<br>
+    const char *<br>
+    GetCommandPrefix ();<br>
+<br>
     //------------------------------------------------------------------<br>
     // Properties<br>
     //------------------------------------------------------------------<br>
<br>
Modified: lldb/trunk/source/Commands/CommandObjectHelp.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.cpp?rev=226068&r1=226067&r2=226068&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.cpp?rev=226068&r1=226067&r2=226068&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Commands/CommandObjectHelp.cpp (original)<br>
+++ lldb/trunk/source/Commands/CommandObjectHelp.cpp Wed Jan 14 18:52:41 2015<br>
@@ -54,9 +54,10 @@ CommandObjectHelp::~CommandObjectHelp()<br>
 OptionDefinition<br>
 CommandObjectHelp::CommandOptions::g_option_table[] =<br>
 {<br>
-    { LLDB_OPT_SET_ALL, false, "show-aliases", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,         "Show aliases in the command list."},<br>
+    { LLDB_OPT_SET_ALL, false, "hide-aliases", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,         "Hide aliases in the command list."},<br>
     { LLDB_OPT_SET_ALL, false, "hide-user-commands", 'u', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,         "Hide user-defined commands from the list."},<br>
-    { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }<br>
+    { LLDB_OPT_SET_ALL, false, "show-hidden-commands", 'h', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,         "Include commands prefixed with an underscore."},<br>
+    { 0, false, NULL, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }<br>
 };<br>
<br>
 bool<br>
@@ -75,6 +76,8 @@ CommandObjectHelp::DoExecute (Args& comm<br>
             cmd_types |= CommandInterpreter::eCommandTypesAliases;<br>
         if (m_options.m_show_user_defined)<br>
             cmd_types |= CommandInterpreter::eCommandTypesUserDef;<br>
+        if (m_options.m_show_hidden)<br>
+            cmd_types |= CommandInterpreter::eCommandTypesHidden;<br>
<br>
         result.SetStatus (eReturnStatusSuccessFinishNoResult);<br>
         m_interpreter.GetHelp (result, cmd_types);  // General help<br>
@@ -136,17 +139,19 @@ CommandObjectHelp::DoExecute (Args& comm<br>
                 else if (!sub_cmd_obj)<br>
                 {<br>
                     result.AppendErrorWithFormat("'%s' is not a known command.\n"<br>
-                                                 "Try 'help' to see a current list of commands.\n",<br>
-                                                 cmd_string.c_str());<br>
+                                                 "Try '%shelp' to see a current list of commands.\n",<br>
+                                                 cmd_string.c_str(),<br>
+                                                 m_interpreter.GetCommandPrefix());<br>
                     result.SetStatus (eReturnStatusFailed);<br>
                     return false;<br>
                 }<br>
                 else<br>
                 {<br>
                     result.GetOutputStream().Printf("'%s' is not a known command.\n"<br>
-                                                   "Try 'help' to see a current list of commands.\n"<br>
+                                                   "Try '%shelp' to see a current list of commands.\n"<br>
                                                     "The closest match is '%s'. Help on it follows.\n\n",<br>
                                                    cmd_string.c_str(),<br>
+                                                   m_interpreter.GetCommandPrefix(),<br>
                                                    sub_cmd_obj->GetCommandName());<br>
                 }<br>
             }<br>
@@ -183,8 +188,9 @@ CommandObjectHelp::DoExecute (Args& comm<br>
             else<br>
             {<br>
                 result.AppendErrorWithFormat<br>
-                    ("'%s' is not a known command.\nTry 'help' to see a current list of commands.\n",<br>
-                     command.GetArgumentAtIndex(0));<br>
+                    ("'%s' is not a known command.\nTry '%shelp' to see a current list of commands.\n",<br>
+                     command.GetArgumentAtIndex(0),<br>
+                     m_interpreter.GetCommandPrefix());<br>
                 result.SetStatus (eReturnStatusFailed);<br>
             }<br>
         }<br>
<br>
Modified: lldb/trunk/source/Commands/CommandObjectHelp.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.h?rev=226068&r1=226067&r2=226068&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.h?rev=226068&r1=226067&r2=226068&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Commands/CommandObjectHelp.h (original)<br>
+++ lldb/trunk/source/Commands/CommandObjectHelp.h Wed Jan 14 18:52:41 2015<br>
@@ -62,11 +62,14 @@ public:<br>
             switch (short_option)<br>
             {<br>
                 case 'a':<br>
-                    m_show_aliases = true;<br>
+                    m_show_aliases = false;<br>
                     break;<br>
                 case 'u':<br>
                     m_show_user_defined = false;<br>
                     break;<br>
+                case 'h':<br>
+                    m_show_hidden = true;<br>
+                    break;<br>
                 default:<br>
                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);<br>
                     break;<br>
@@ -78,8 +81,9 @@ public:<br>
         void<br>
         OptionParsingStarting ()<br>
         {<br>
-            m_show_aliases = false;<br>
+            m_show_aliases = true;<br>
             m_show_user_defined = true;<br>
+            m_show_hidden = false;<br>
         }<br>
<br>
         const OptionDefinition*<br>
@@ -95,7 +99,8 @@ public:<br>
         // Instance variables to hold the values for command options.<br>
<br>
         bool m_show_aliases;<br>
-        bool m_show_user_defined;<br>
+        bool m_show_user_defined;<br>
+        bool m_show_hidden;<br>
     };<br>
<br>
     virtual Options *<br>
<br>
Modified: lldb/trunk/source/Core/Debugger.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=226068&r1=226067&r2=226068&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=226068&r1=226067&r2=226068&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Core/Debugger.cpp (original)<br>
+++ lldb/trunk/source/Core/Debugger.cpp Wed Jan 14 18:52:41 2015<br>
@@ -927,6 +927,18 @@ Debugger::GetTopIOHandlerControlSequence<br>
     return m_input_reader_stack.GetTopIOHandlerControlSequence (ch);<br>
 }<br>
<br>
+const char *<br>
+Debugger::GetIOHandlerCommandPrefix()<br>
+{<br>
+    return m_input_reader_stack.GetTopIOHandlerCommandPrefix();<br>
+}<br>
+<br>
+const char *<br>
+Debugger::GetIOHandlerHelpPrologue()<br>
+{<br>
+    return m_input_reader_stack.GetTopIOHandlerHelpPrologue();<br>
+}<br>
+<br>
 void<br>
 Debugger::RunIOHandler (const IOHandlerSP& reader_sp)<br>
 {<br>
<br>
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=226068&r1=226067&r2=226068&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=226068&r1=226067&r2=226068&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)<br>
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Jan 14 18:52:41 2015<br>
@@ -1170,17 +1170,25 @@ void<br>
 CommandInterpreter::GetHelp (CommandReturnObject &result,<br>
                              uint32_t cmd_types)<br>
 {<br>
+    const char * help_prologue = GetDebugger().GetIOHandlerHelpPrologue();<br>
+    if (help_prologue != NULL)<br>
+    {<br>
+        OutputFormattedHelpText(result.GetOutputStream(), NULL, help_prologue);<br>
+    }<br>
+<br>
     CommandObject::CommandMap::const_iterator pos;<br>
     size_t max_len = FindLongestCommandWord (m_command_dict);<br>
<br>
     if ( (cmd_types & eCommandTypesBuiltin) == eCommandTypesBuiltin )<br>
     {<br>
-<br>
-        result.AppendMessage("The following is a list of built-in, permanent debugger commands:");<br>
+        result.AppendMessage("Debugger commands:");<br>
         result.AppendMessage("");<br>
<br>
         for (pos = m_command_dict.begin(); pos != m_command_dict.end(); ++pos)<br>
         {<br>
+            if (!(cmd_types & eCommandTypesHidden) && (pos->first.compare(0, 1, "_") == 0))<br>
+                continue;<br>
+<br>
             OutputFormattedHelpText (result.GetOutputStream(), pos->first.c_str(), "--", pos->second->GetHelp(),<br>
                                      max_len);<br>
         }<br>
@@ -1190,8 +1198,9 @@ CommandInterpreter::GetHelp (CommandRetu<br>
<br>
     if (!m_alias_dict.empty() && ( (cmd_types & eCommandTypesAliases) == eCommandTypesAliases ))<br>
     {<br>
-        result.AppendMessage("The following is a list of your current command abbreviations "<br>
-                             "(see 'help command alias' for more info):");<br>
+        result.AppendMessageWithFormat("Current command abbreviations "<br>
+                                       "(type '%shelp command alias' for more info):\n",<br>
+                                       GetCommandPrefix());<br>
         result.AppendMessage("");<br>
         max_len = FindLongestCommandWord (m_alias_dict);<br>
<br>
@@ -1212,7 +1221,7 @@ CommandInterpreter::GetHelp (CommandRetu<br>
<br>
     if (!m_user_dict.empty() && ( (cmd_types & eCommandTypesUserDef) == eCommandTypesUserDef ))<br>
     {<br>
-        result.AppendMessage ("The following is a list of your current user-defined commands:");<br>
+        result.AppendMessage ("Current user-defined commands:");<br>
         result.AppendMessage("");<br>
         max_len = FindLongestCommandWord (m_user_dict);<br>
         for (pos = m_user_dict.begin(); pos != m_user_dict.end(); ++pos)<br>
@@ -1223,7 +1232,8 @@ CommandInterpreter::GetHelp (CommandRetu<br>
         result.AppendMessage("");<br>
     }<br>
<br>
-    result.AppendMessage("For more information on any particular command, try 'help <command-name>'.");<br>
+    result.AppendMessageWithFormat("For more information on any command, type '%shelp <command-name>'.\n",<br>
+                                   GetCommandPrefix());<br>
 }<br>
<br>
 CommandObject *<br>
@@ -2496,6 +2506,13 @@ CommandInterpreter::SourceInitFile (bool<br>
     }<br>
 }<br>
<br>
+const char *<br>
+CommandInterpreter::GetCommandPrefix()<br>
+{<br>
+    const char * prefix = GetDebugger().GetIOHandlerCommandPrefix();<br>
+    return prefix == NULL ? "" : prefix;<br>
+}<br>
+<br>
 PlatformSP<br>
 CommandInterpreter::GetPlatform (bool prefer_target_platform)<br>
 {<br>
@@ -2887,84 +2904,74 @@ CommandInterpreter::SetSynchronous (bool<br>
<br>
 void<br>
 CommandInterpreter::OutputFormattedHelpText (Stream &strm,<br>
-                                             const char *word_text,<br>
-                                             const char *separator,<br>
-                                             const char *help_text,<br>
-                                             size_t max_word_len)<br>
+                                             const char *prefix,<br>
+                                             const char *help_text)<br>
 {<br>
     const uint32_t max_columns = m_debugger.GetTerminalWidth();<br>
+    if (prefix == NULL)<br>
+        prefix = "";<br>
<br>
-    int indent_size = max_word_len + strlen (separator) + 2;<br>
-<br>
-    strm.IndentMore (indent_size);<br>
-<br>
-    StreamString text_strm;<br>
-    text_strm.Printf ("%-*s %s %s",  (int)max_word_len, word_text, separator, help_text);<br>
-<br>
-    size_t len = text_strm.GetSize();<br>
-    const char *text = text_strm.GetData();<br>
-    if (text[len - 1] == '\n')<br>
-    {<br>
-        text_strm.EOL();<br>
-        len = text_strm.GetSize();<br>
-    }<br>
-<br>
-    if (len  < max_columns)<br>
-    {<br>
-        // Output it as a single line.<br>
-        strm.Printf ("%s", text);<br>
-    }<br>
-    else<br>
-    {<br>
-        // We need to break it up into multiple lines.<br>
-        bool first_line = true;<br>
-        int text_width;<br>
-        size_t start = 0;<br>
-        size_t end = start;<br>
-        const size_t final_end = strlen (text);<br>
-<br>
-        while (end < final_end)<br>
-        {<br>
-            if (first_line)<br>
-                text_width = max_columns - 1;<br>
-            else<br>
-                text_width = max_columns - indent_size - 1;<br>
-<br>
-            // Don't start the 'text' on a space, since we're already outputting the indentation.<br>
-            if (!first_line)<br>
+    size_t prefix_width = strlen(prefix);<br>
+    size_t line_width_max = max_columns - prefix_width;<br>
+    const char *help_text_end = help_text + strlen(help_text);<br>
+    const char *line_start = help_text;<br>
+    if (line_width_max < 16)<br>
+        line_width_max = help_text_end - help_text + prefix_width;<br>
+<br>
+    strm.IndentMore (prefix_width);<br>
+    while (line_start < help_text_end)<br>
+    {<br>
+        // Break each line at the first newline or last space/tab before<br>
+        // the maximum number of characters that fit on a line.  Lines with no<br>
+        // natural break are left unbroken to wrap.<br>
+        const char *line_end = help_text_end;<br>
+        const char *line_scan = line_start;<br>
+        const char *line_scan_end = help_text_end;<br>
+        while (line_scan < line_scan_end)<br>
+        {<br>
+            char next = *line_scan;<br>
+            if (next == '\t' || next == ' ')<br>
             {<br>
-                while ((start < final_end) && (text[start] == ' '))<br>
-                  start++;<br>
+                line_end = line_scan;<br>
+                line_scan_end = line_start + line_width_max;<br>
             }<br>
-<br>
-            end = start + text_width;<br>
-            if (end > final_end)<br>
-                end = final_end;<br>
-            else<br>
+            else if (next == '\n' || next == '\0')<br>
             {<br>
-                // If we're not at the end of the text, make sure we break the line on white space.<br>
-                while (end > start<br>
-                       && text[end] != ' ' && text[end] != '\t' && text[end] != '\n')<br>
-                    end--;<br>
-                assert (end > 0);<br>
+                line_end = line_scan;<br>
+                break;<br>
             }<br>
-<br>
-            const size_t sub_len = end - start;<br>
-            if (start != 0)<br>
-              strm.EOL();<br>
-            if (!first_line)<br>
-                strm.Indent();<br>
-            else<br>
-                first_line = false;<br>
-            assert (start <= final_end);<br>
-            assert (start + sub_len <= final_end);<br>
-            if (sub_len > 0)<br>
-                strm.Write (text + start, sub_len);<br>
-            start = end + 1;<br>
+            ++line_scan;<br>
         }<br>
+<br>
+        // Prefix the first line, indent subsequent lines to line up<br>
+        if (line_start == help_text)<br>
+            strm.Write (prefix, prefix_width);<br>
+        else<br>
+            strm.Indent();<br>
+        strm.Write (line_start, line_end - line_start);<br>
+        strm.EOL();<br>
+<br>
+        // When a line breaks at whitespace consume it before continuing<br>
+        line_start = line_end;<br>
+        char next = *line_start;<br>
+        if (next == '\n')<br>
+            ++line_start;<br>
+        else while (next == ' ' || next == '\t')<br>
+            next = *(++line_start);<br>
     }<br>
-    strm.EOL();<br>
-    strm.IndentLess(indent_size);<br>
+    strm.IndentLess (prefix_width);<br>
+}<br>
+<br>
+void<br>
+CommandInterpreter::OutputFormattedHelpText (Stream &strm,<br>
+                                             const char *word_text,<br>
+                                             const char *separator,<br>
+                                             const char *help_text,<br>
+                                             size_t max_word_len)<br>
+{<br>
+    StreamString prefix_stream;<br>
+    prefix_stream.Printf ("  %-*s %s ",  (int)max_word_len, word_text, separator);<br>
+    OutputFormattedHelpText (strm, prefix_stream.GetData(), help_text);<br>
 }<br>
<br>
 void<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
</blockquote></div><br></div>