diff --git a/lldb/include/lldb/Interpreter/CommandCompletions.h b/lldb/include/lldb/Interpreter/CommandCompletions.h index 4392e335061ec2..60d42a8c990fe6 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 590a0d2dfad84e..de0e07eb36b92f 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 927070f3d3bad3..3cd4ad88afc70f 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 d41139947b815d..c420f32cc3a164 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'])