[Lldb-commits] [lldb] b2b7dbb - [lldb] stop-hook ID common completion for commands `target stop-hook enable/disable/delete'

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 11 04:14:48 PDT 2020


Author: Gongyu Deng
Date: 2020-08-11T13:14:27+02:00
New Revision: b2b7dbb47aa9aff1252d4440bb9986df5a7e67cb

URL: https://github.com/llvm/llvm-project/commit/b2b7dbb47aa9aff1252d4440bb9986df5a7e67cb
DIFF: https://github.com/llvm/llvm-project/commit/b2b7dbb47aa9aff1252d4440bb9986df5a7e67cb.diff

LOG: [lldb] stop-hook ID common completion for commands `target stop-hook enable/disable/delete'

1. Added a common completion StopHookIDs to provide completion with a list of stop hook ids;
2. Applied the common completion to commands: `target stop-hook delete/enable/disable';
3. Added an related test case.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D84123

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Interpreter/CommandCompletions.h b/lldb/include/lldb/Interpreter/CommandCompletions.h
index 4392e335061e..60d42a8c990f 100644
--- a/lldb/include/lldb/Interpreter/CommandCompletions.h
+++ b/lldb/include/lldb/Interpreter/CommandCompletions.h
@@ -41,10 +41,11 @@ class CommandCompletions {
     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 @@ class CommandCompletions {
 
   static void FrameIndexes(CommandInterpreter &interpreter,
                            CompletionRequest &request, SearchFilter *searcher);
+
+  static void StopHookIDs(CommandInterpreter &interpreter,
+                          CompletionRequest &request, SearchFilter *searcher);
 };
 
 } // namespace lldb_private

diff  --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp
index 590a0d2dfad8..de0e07eb36b9 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -65,6 +65,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
       {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 @@ void CommandCompletions::FrameIndexes(CommandInterpreter &interpreter,
     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());
+  }
+}

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 927070f3d3ba..3cd4ad88afc7 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -4722,6 +4722,16 @@ class CommandObjectTargetStopHookDelete : public CommandObjectParsed {
 
   ~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 @@ class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed {
 
   ~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();

diff  --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py
index d41139947b81..c420f32cc3a1 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -548,6 +548,26 @@ def test_register_read_and_write_on_x86(self):
         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'])
 


        


More information about the lldb-commits mailing list