[lldb] tab completion for `disassemble -F`
authorGongyu Deng <gy_deng@icloud.com>
Tue, 11 Aug 2020 07:59:30 +0000 (09:59 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Tue, 11 Aug 2020 08:01:45 +0000 (10:01 +0200)
1.Added a new common completion DisassemblyFlavors;

2. Bound DisassemblyFlavors to argument of type eArgTypeDisassemblyFlavor in
CommandObject.cpp;

3. Added a related test case.

lldb/include/lldb/Interpreter/CommandCompletions.h
lldb/source/Commands/CommandCompletions.cpp
lldb/source/Interpreter/CommandObject.cpp
lldb/test/API/functionalities/completion/TestCompletion.py

index 39d1c98..55ab5d8 100644 (file)
@@ -37,10 +37,11 @@ public:
     eRegisterCompletion = (1u << 9),
     eBreakpointCompletion = (1u << 10),
     eProcessPluginCompletion = (1u << 11),
+    eDisassemblyFlavorCompletion = (1u << 12),
     // This item serves two purposes.  It is the last element in the enum, so
     // you can add custom enums starting from here in your Option class. Also
     // if you & in this bit the base code will not process the option.
-    eCustomCompletion = (1u << 12)
+    eCustomCompletion = (1u << 13)
   };
 
   static bool InvokeCommonCompletionCallbacks(
@@ -94,6 +95,10 @@ public:
   static void ProcessPluginNames(CommandInterpreter &interpreter,
                                  CompletionRequest &request,
                                  SearchFilter *searcher);
+
+  static void DisassemblyFlavors(CommandInterpreter &interpreter,
+                                 CompletionRequest &request,
+                                 SearchFilter *searcher);
 };
 
 } // namespace lldb_private
index 48df773..69d7f78 100644 (file)
@@ -59,6 +59,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
       {eRegisterCompletion, CommandCompletions::Registers},
       {eBreakpointCompletion, CommandCompletions::Breakpoints},
       {eProcessPluginCompletion, CommandCompletions::ProcessPluginNames},
+      {eDisassemblyFlavorCompletion, CommandCompletions::DisassemblyFlavors},
       {eNoCompletion, nullptr} // This one has to be last in the list.
   };
 
@@ -593,4 +594,15 @@ void CommandCompletions::ProcessPluginNames(CommandInterpreter &interpreter,
                                             SearchFilter *searcher) {
   PluginManager::AutoCompleteProcessName(request.GetCursorArgumentPrefix(),
                                          request);
-}
\ No newline at end of file
+}
+
+void CommandCompletions::DisassemblyFlavors(CommandInterpreter &interpreter,
+                                            CompletionRequest &request,
+                                            SearchFilter *searcher) {
+  // Currently the only valid options for disassemble -F are default, and for
+  // Intel architectures, att and intel.
+  static const char *flavors[] = {"default", "att", "intel"};
+  for (const char *flavor : flavors) {
+    request.TryCompleteCurrentArg(flavor);
+  }
+}
index 6f58b8b..946ea81 100644 (file)
@@ -1047,7 +1047,7 @@ CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = {
     { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A debugger command (may be multiple words), without any options or arguments." },
     { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." },
     { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { nullptr, false }, "A directory name." },
-    { eArgTypeDisassemblyFlavor, "disassembly-flavor", CommandCompletions::eNoCompletion, { nullptr, false }, "A disassembly flavor recognized by your disassembly plugin.  Currently the only valid options are \"att\" and \"intel\" for Intel targets" },
+    { eArgTypeDisassemblyFlavor, "disassembly-flavor", CommandCompletions::eDisassemblyFlavorCompletion, { nullptr, false }, "A disassembly flavor recognized by your disassembly plugin.  Currently the only valid options are \"att\" and \"intel\" for Intel targets" },
     { eArgTypeDescriptionVerbosity, "description-verbosity", CommandCompletions::eNoCompletion, { nullptr, false }, "How verbose the output of 'po' should be." },
     { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
     { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
index a57dbdb..030bd25 100644 (file)
@@ -115,6 +115,12 @@ class CommandLineCompletionTestCase(TestBase):
                                 '--thread-index',
                                 '--thread-name'])
 
+    def test_disassemble_dash_f(self):
+        self.completions_match('disassemble -F ',
+                               ['default',
+                                'intel',
+                                'att'])
+
     def test_plugin_load(self):
         self.complete_from_to('plugin load ', [])