Index: lldb/include/lldb/Interpreter/CommandCompletions.h =================================================================== --- lldb/include/lldb/Interpreter/CommandCompletions.h +++ lldb/include/lldb/Interpreter/CommandCompletions.h @@ -43,10 +43,11 @@ eThreadIndexCompletion = (1u << 15), eWatchPointIDCompletion = (1u << 16), eModuleUUIDCompletion = (1u << 17), + eStopHookIDCompletion = (1u << 18), // 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 << 18) + eCustomCompletion = (1u << 19) }; static bool InvokeCommonCompletionCallbacks( @@ -119,6 +120,9 @@ static void WatchPointIDs(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher); + + static void StopHookIDs(CommandInterpreter &interpreter, + CompletionRequest &request, SearchFilter *searcher); }; } // namespace lldb_private Index: lldb/source/Commands/CommandCompletions.cpp =================================================================== --- lldb/source/Commands/CommandCompletions.cpp +++ lldb/source/Commands/CommandCompletions.cpp @@ -68,6 +68,7 @@ {eFrameIndexCompletion, CommandCompletions::FrameIndexes}, {eThreadIndexCompletion, CommandCompletions::ThreadIndexes}, {eWatchPointIDCompletion, CommandCompletions::WatchPointIDs}, + {eStopHookIDCompletion, CommandCompletions::StopHookIDs}, {eNoCompletion, nullptr} // This one has to be last in the list. }; @@ -708,3 +709,22 @@ 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; + 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/source/Commands/CommandObjectTarget.cpp =================================================================== --- lldb/source/Commands/CommandObjectTarget.cpp +++ lldb/source/Commands/CommandObjectTarget.cpp @@ -4710,6 +4710,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(); @@ -4758,6 +4768,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/test/API/functionalities/completion/TestCompletion.py =================================================================== --- lldb/test/API/functionalities/completion/TestCompletion.py +++ lldb/test/API/functionalities/completion/TestCompletion.py @@ -384,6 +384,26 @@ """Test that 'target va' completes to 'target variable '.""" self.complete_from_to('target va', 'target variable ') + 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_thread_index(self): subcommands = ['continue', 'info', 'exception', 'select', 'step-in', 'step-inst', 'step-inst-over', 'step-out', 'step-over', 'step-script']