[Lldb-commits] [lldb] r178348 - <rdar://problem/12022060>

Greg Clayton gclayton at apple.com
Fri Mar 29 10:03:23 PDT 2013


Author: gclayton
Date: Fri Mar 29 12:03:23 2013
New Revision: 178348

URL: http://llvm.org/viewvc/llvm-project?rev=178348&view=rev
Log:
<rdar://problem/12022060>

Enable tab completion for regular expression commands.


Modified:
    lldb/trunk/include/lldb/Interpreter/CommandObjectRegexCommand.h
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp

Modified: lldb/trunk/include/lldb/Interpreter/CommandObjectRegexCommand.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObjectRegexCommand.h?rev=178348&r1=178347&r2=178348&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObjectRegexCommand.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObjectRegexCommand.h Fri Mar 29 12:03:23 2013
@@ -33,7 +33,8 @@ public:
                                const char *name, 
                                const char *help, 
                                const char *syntax, 
-                               uint32_t max_matches);
+                               uint32_t max_matches,
+                               uint32_t completion_type_mask = 0);
     
     virtual
     ~CommandObjectRegexCommand ();
@@ -46,6 +47,15 @@ public:
     {
         return !m_entries.empty();
     }
+    
+    virtual int
+    HandleCompletion (Args &input,
+                      int &cursor_index,
+                      int &cursor_char_position,
+                      int match_start_point,
+                      int max_return_elements,
+                      bool &word_complete,
+                      StringList &matches);
 
 protected:
     virtual bool
@@ -59,6 +69,7 @@ protected:
 
     typedef std::list<Entry> EntryCollection;
     const uint32_t m_max_matches;
+    const uint32_t m_completion_type_mask;
     EntryCollection m_entries;
 
 private:

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=178348&r1=178347&r2=178348&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Fri Mar 29 12:03:23 2013
@@ -42,6 +42,7 @@
 #include "../Commands/CommandObjectVersion.h"
 #include "../Commands/CommandObjectWatchpoint.h"
 
+
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/InputReader.h"
 #include "lldb/Core/Log.h"
@@ -51,8 +52,9 @@
 #include "lldb/Host/Host.h"
 
 #include "lldb/Interpreter/Args.h"
-#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/CommandCompletions.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/Options.h"
 #include "lldb/Interpreter/ScriptInterpreterNone.h"
 #include "lldb/Interpreter/ScriptInterpreterPython.h"
@@ -395,7 +397,10 @@ CommandInterpreter::LoadCommandDictionar
     break_regex_cmd_ap(new CommandObjectRegexCommand (*this,
                                                       "_regexp-break",
                                                       "Set a breakpoint using a regular expression to specify the location, where <linenum> is in decimal and <address> is in hex.",
-                                                      "_regexp-break [<filename>:<linenum>]\n_regexp-break [<linenum>]\n_regexp-break [<address>]\n_regexp-break <...>", 2));
+                                                      "_regexp-break [<filename>:<linenum>]\n_regexp-break [<linenum>]\n_regexp-break [<address>]\n_regexp-break <...>",
+                                                      2,
+                                                      CommandCompletions::eSymbolCompletion |
+                                                      CommandCompletions::eSourceFileCompletion));
 
     if (break_regex_cmd_ap.get())
     {
@@ -419,7 +424,10 @@ CommandInterpreter::LoadCommandDictionar
     tbreak_regex_cmd_ap(new CommandObjectRegexCommand (*this,
                                                       "_regexp-tbreak",
                                                       "Set a one shot breakpoint using a regular expression to specify the location, where <linenum> is in decimal and <address> is in hex.",
-                                                      "_regexp-tbreak [<filename>:<linenum>]\n_regexp-break [<linenum>]\n_regexp-break [<address>]\n_regexp-break <...>", 2));
+                                                      "_regexp-tbreak [<filename>:<linenum>]\n_regexp-break [<linenum>]\n_regexp-break [<address>]\n_regexp-break <...>",
+                                                       2,
+                                                       CommandCompletions::eSymbolCompletion |
+                                                       CommandCompletions::eSourceFileCompletion));
 
     if (tbreak_regex_cmd_ap.get())
     {
@@ -447,7 +455,8 @@ CommandInterpreter::LoadCommandDictionar
     attach_regex_cmd_ap(new CommandObjectRegexCommand (*this,
                                                        "_regexp-attach",
                                                        "Attach to a process id if in decimal, otherwise treat the argument as a process name to attach to.",
-                                                       "_regexp-attach [<pid>]\n_regexp-attach [<process-name>]", 2));
+                                                       "_regexp-attach [<pid>]\n_regexp-attach [<process-name>]",
+                                                       2));
     if (attach_regex_cmd_ap.get())
     {
         if (attach_regex_cmd_ap->AddRegexCommand("^([0-9]+)[[:space:]]*$", "process attach --pid %1") &&
@@ -492,9 +501,9 @@ CommandInterpreter::LoadCommandDictionar
 
     std::auto_ptr<CommandObjectRegexCommand>
     display_regex_cmd_ap(new CommandObjectRegexCommand (*this,
-                                                   "_regexp-display",
-                                                   "Add an expression evaluation stop-hook.",
-                                                   "_regexp-display expression", 2));
+                                                        "_regexp-display",
+                                                        "Add an expression evaluation stop-hook.",
+                                                        "_regexp-display expression", 2));
     if (display_regex_cmd_ap.get())
     {
         if (display_regex_cmd_ap->AddRegexCommand("^(.+)$", "target stop-hook add -o \"expr -- %1\""))
@@ -506,9 +515,9 @@ CommandInterpreter::LoadCommandDictionar
 
     std::auto_ptr<CommandObjectRegexCommand>
     undisplay_regex_cmd_ap(new CommandObjectRegexCommand (*this,
-                                                   "_regexp-undisplay",
-                                                   "Remove an expression evaluation stop-hook.",
-                                                   "_regexp-undisplay stop-hook-number", 2));
+                                                          "_regexp-undisplay",
+                                                          "Remove an expression evaluation stop-hook.",
+                                                          "_regexp-undisplay stop-hook-number", 2));
     if (undisplay_regex_cmd_ap.get())
     {
         if (undisplay_regex_cmd_ap->AddRegexCommand("^([0-9]+)$", "target stop-hook delete %1"))
@@ -520,9 +529,9 @@ CommandInterpreter::LoadCommandDictionar
 
     std::auto_ptr<CommandObjectRegexCommand>
     connect_gdb_remote_cmd_ap(new CommandObjectRegexCommand (*this,
-                                                      "gdb-remote",
-                                                      "Connect to a remote GDB server.  If no hostname is provided, localhost is assumed.",
-                                                      "gdb-remote [<hostname>:]<portnum>", 2));
+                                                             "gdb-remote",
+                                                             "Connect to a remote GDB server.  If no hostname is provided, localhost is assumed.",
+                                                             "gdb-remote [<hostname>:]<portnum>", 2));
     if (connect_gdb_remote_cmd_ap.get())
     {
         if (connect_gdb_remote_cmd_ap->AddRegexCommand("^([^:]+:[[:digit:]]+)$", "process connect --plugin gdb-remote connect://%1") &&
@@ -572,7 +581,9 @@ CommandInterpreter::LoadCommandDictionar
     list_regex_cmd_ap(new CommandObjectRegexCommand (*this,
                                                      "_regexp-list",
                                                      "Implements the GDB 'list' command in all of its forms except FILE:FUNCTION and maps them to the appropriate 'source list' commands.",
-                                                     "_regexp-list [<line>]\n_regexp-attach [<file>:<line>]\n_regexp-attach [<file>:<line>]", 2));
+                                                     "_regexp-list [<line>]\n_regexp-attach [<file>:<line>]\n_regexp-attach [<file>:<line>]",
+                                                     2,
+                                                     CommandCompletions::eSourceFileCompletion));
     if (list_regex_cmd_ap.get())
     {
         if (list_regex_cmd_ap->AddRegexCommand("^([0-9]+)[[:space:]]*$", "source list --line %1") &&
@@ -590,9 +601,9 @@ CommandInterpreter::LoadCommandDictionar
 
     std::auto_ptr<CommandObjectRegexCommand>
     env_regex_cmd_ap(new CommandObjectRegexCommand (*this,
-                                                     "_regexp-env",
-                                                     "Implements a shortcut to viewing and setting environment variables.",
-                                                     "_regexp-env\n_regexp-env FOO=BAR", 2));
+                                                    "_regexp-env",
+                                                    "Implements a shortcut to viewing and setting environment variables.",
+                                                    "_regexp-env\n_regexp-env FOO=BAR", 2));
     if (env_regex_cmd_ap.get())
     {
         if (env_regex_cmd_ap->AddRegexCommand("^$", "settings show target.env-vars") &&

Modified: lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp?rev=178348&r1=178347&r2=178348&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp Fri Mar 29 12:03:23 2013
@@ -30,11 +30,13 @@ CommandObjectRegexCommand::CommandObject
     const char *name,
     const char *help,
     const char *syntax,
-    uint32_t max_matches
+    uint32_t max_matches,
+    uint32_t completion_type_mask
 ) :
     CommandObjectRaw (interpreter, name, help, syntax),
     m_max_matches (max_matches),
-    m_entries ()
+    m_entries (),
+    m_completion_type_mask (completion_type_mask)
 {
 }
 
@@ -114,3 +116,33 @@ CommandObjectRegexCommand::AddRegexComma
     m_entries.pop_back();
     return false;
 }
+
+int
+CommandObjectRegexCommand::HandleCompletion (Args &input,
+                                             int &cursor_index,
+                                             int &cursor_char_position,
+                                             int match_start_point,
+                                             int max_return_elements,
+                                             bool &word_complete,
+                                             StringList &matches)
+{
+    if (m_completion_type_mask)
+    {
+        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
+        CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
+                                                             m_completion_type_mask,
+                                                             completion_str.c_str(),
+                                                             match_start_point,
+                                                             max_return_elements,
+                                                             NULL,
+                                                             word_complete,
+                                                             matches);
+        return matches.GetSize();
+    }
+    else
+    {
+        matches.Clear();
+        word_complete = false;
+    }
+    return 0;
+}





More information about the lldb-commits mailing list