This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2b7dbb47aa9: [lldb] stop-hook ID common completion for 
commands `target stop-hook… (authored by MrHate, committed by teemperor).
Herald added a subscriber: lldb-commits.

Changed prior to commit:
  https://reviews.llvm.org/D84123?vs=283570&id=284645#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84123/new/

https://reviews.llvm.org/D84123

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

Index: lldb/test/API/functionalities/completion/TestCompletion.py
===================================================================
--- lldb/test/API/functionalities/completion/TestCompletion.py
+++ lldb/test/API/functionalities/completion/TestCompletion.py
@@ -548,6 +548,26 @@
         self.complete_from_to('register write rbx ',
                               [])
 
+    def test_common_completion_target_stophook_ids(self):
+        subcommands = ['delete', 'enable', 'disable']
+
+        for subcommand in subcommands:
+            self.complete_from_to('target stop-hook ' + subcommand + ' ',
+                                  'target stop-hook ' + subcommand + ' ')
+
+        self.build()
+        self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+        self.runCmd('target stop-hook add test DONE')
+
+        for subcommand in subcommands:
+            self.complete_from_to('target stop-hook ' + subcommand + ' ',
+                                  'target stop-hook ' + subcommand + ' 1')
+
+        # Completion should work only on the first argument.
+        for subcommand in subcommands:
+            self.complete_from_to('target stop-hook ' + subcommand + ' 1 ',
+                                  'target stop-hook ' + subcommand + ' 1 ')
+
     def test_common_completion_type_language(self):
         self.complete_from_to('type category -l ', ['c'])
 
Index: lldb/source/Commands/CommandObjectTarget.cpp
===================================================================
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -4722,6 +4722,16 @@
 
   ~CommandObjectTargetStopHookDelete() override = default;
 
+  void
+  HandleArgumentCompletion(CompletionRequest &request,
+                           OptionElementVector &opt_element_vector) override {
+    if (request.GetCursorIndex())
+      return;
+    CommandCompletions::InvokeCommonCompletionCallbacks(
+        GetCommandInterpreter(), CommandCompletions::eStopHookIDCompletion,
+        request, nullptr);
+  }
+
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetSelectedOrDummyTarget();
@@ -4770,6 +4780,16 @@
 
   ~CommandObjectTargetStopHookEnableDisable() override = default;
 
+  void
+  HandleArgumentCompletion(CompletionRequest &request,
+                           OptionElementVector &opt_element_vector) override {
+    if (request.GetCursorIndex())
+      return;
+    CommandCompletions::InvokeCommonCompletionCallbacks(
+        GetCommandInterpreter(), CommandCompletions::eStopHookIDCompletion,
+        request, nullptr);
+  }
+
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetSelectedOrDummyTarget();
Index: lldb/source/Commands/CommandCompletions.cpp
===================================================================
--- lldb/source/Commands/CommandCompletions.cpp
+++ lldb/source/Commands/CommandCompletions.cpp
@@ -65,6 +65,7 @@
       {eDisassemblyFlavorCompletion, CommandCompletions::DisassemblyFlavors},
       {eTypeLanguageCompletion, CommandCompletions::TypeLanguages},
       {eFrameIndexCompletion, CommandCompletions::FrameIndexes},
+      {eStopHookIDCompletion, CommandCompletions::StopHookIDs},
       {eNoCompletion, nullptr} // This one has to be last in the list.
   };
 
@@ -656,3 +657,24 @@
     request.TryCompleteCurrentArg(std::to_string(i), strm.GetString());
   }
 }
+
+void CommandCompletions::StopHookIDs(CommandInterpreter &interpreter,
+                                     CompletionRequest &request,
+                                     SearchFilter *searcher) {
+  const lldb::TargetSP target_sp =
+      interpreter.GetExecutionContext().GetTargetSP();
+  if (!target_sp)
+    return;
+
+  const size_t num = target_sp->GetNumStopHooks();
+  for (size_t idx = 0; idx < num; ++idx) {
+    StreamString strm;
+    // The value 11 is an offset to make the completion description looks
+    // neater.
+    strm.SetIndentLevel(11);
+    const Target::StopHookSP stophook_sp = target_sp->GetStopHookAtIndex(idx);
+    stophook_sp->GetDescription(&strm, lldb::eDescriptionLevelInitial);
+    request.TryCompleteCurrentArg(std::to_string(stophook_sp->GetID()),
+                                  strm.GetString());
+  }
+}
Index: lldb/include/lldb/Interpreter/CommandCompletions.h
===================================================================
--- lldb/include/lldb/Interpreter/CommandCompletions.h
+++ lldb/include/lldb/Interpreter/CommandCompletions.h
@@ -41,10 +41,11 @@
     eTypeLanguageCompletion = (1u << 13),
     eFrameIndexCompletion = (1u << 14),
     eModuleUUIDCompletion = (1u << 15),
+    eStopHookIDCompletion = (1u << 16),
     // 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 << 16)
+    eCustomCompletion = (1u << 17)
   };
 
   static bool InvokeCommonCompletionCallbacks(
@@ -111,6 +112,9 @@
 
   static void FrameIndexes(CommandInterpreter &interpreter,
                            CompletionRequest &request, SearchFilter *searcher);
+
+  static void StopHookIDs(CommandInterpreter &interpreter,
+                          CompletionRequest &request, SearchFilter *searcher);
 };
 
 } // namespace lldb_private
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to