Index: lldb/include/lldb/Interpreter/CommandCompletions.h =================================================================== --- lldb/include/lldb/Interpreter/CommandCompletions.h +++ lldb/include/lldb/Interpreter/CommandCompletions.h @@ -41,10 +41,11 @@ eProcessIDCompletion = (1u << 13), eFrameIndexCompletion = (1u << 14), eThreadIndexCompletion = (1u << 15), + eWatchPointIDCompletion = (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 ThreadIndexes(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher); + + static void WatchPointIDs(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 @@ -9,6 +9,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSet.h" +#include "lldb/Breakpoint/Watchpoint.h" #include "lldb/Core/FileSpecList.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" @@ -65,6 +66,7 @@ {eProcessIDCompletion, CommandCompletions::ProcessIDs}, {eFrameIndexCompletion, CommandCompletions::FrameIndexes}, {eThreadIndexCompletion, CommandCompletions::ThreadIndexes}, + {eWatchPointIDCompletion, CommandCompletions::WatchPointIDs}, {eNoCompletion, nullptr} // This one has to be last in the list. }; @@ -669,3 +671,21 @@ strm.GetString()); } } + +void CommandCompletions::WatchPointIDs(CommandInterpreter &interpreter, + CompletionRequest &request, + SearchFilter *searcher) { + const ExecutionContext &exe_ctx = interpreter.GetExecutionContext(); + if (!exe_ctx.HasTargetScope()) + return; + + const WatchpointList &wp_list = exe_ctx.GetTargetPtr()->GetWatchpointList(); + const size_t wp_num = wp_list.GetSize(); + for (size_t idx = 0; idx < wp_num; ++idx) { + const lldb::WatchpointSP wp_sp = wp_list.GetByIndex(idx); + StreamString strm; + wp_sp->Dump(&strm); + request.TryCompleteCurrentArg(std::to_string(wp_sp->GetID()), + strm.GetString()); + } +} Index: lldb/source/Commands/CommandObjectWatchpoint.cpp =================================================================== --- lldb/source/Commands/CommandObjectWatchpoint.cpp +++ lldb/source/Commands/CommandObjectWatchpoint.cpp @@ -292,6 +292,14 @@ ~CommandObjectWatchpointEnable() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, + request, nullptr); + } + protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); @@ -362,6 +370,14 @@ ~CommandObjectWatchpointDisable() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, + request, nullptr); + } + protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); @@ -439,6 +455,14 @@ ~CommandObjectWatchpointDelete() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, + request, nullptr); + } + Options *GetOptions() override { return &m_options; } class CommandOptions : public Options { @@ -557,6 +581,14 @@ ~CommandObjectWatchpointIgnore() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, + request, nullptr); + } + Options *GetOptions() override { return &m_options; } class CommandOptions : public Options { @@ -677,6 +709,14 @@ ~CommandObjectWatchpointModify() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, + request, nullptr); + } + Options *GetOptions() override { return &m_options; } class CommandOptions : public Options { Index: lldb/test/API/functionalities/completion/TestCompletion.py =================================================================== --- lldb/test/API/functionalities/completion/TestCompletion.py +++ lldb/test/API/functionalities/completion/TestCompletion.py @@ -232,6 +232,22 @@ """Test that 'help watchpoint s' completes to 'help watchpoint set '.""" self.complete_from_to('help watchpoint s', 'help watchpoint set ') + def test_common_complete_watchpoint_ids(self): + subcommands = ['enable', 'disable', 'delete', 'modify', 'ignore'] + + # Completion should not work without a target. + for subcommand in subcommands: + self.complete_from_to('watchpoint ' + subcommand + ' ', + 'watchpoint ' + subcommand + ' ') + + # Create a process to provide a target and enable watchpoint setting. + self.build() + lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) + + self.runCmd('watchpoint set variable ptr_fooo') + for subcommand in subcommands: + self.complete_from_to('watchpoint ' + subcommand + ' ', ['1']) + def test_settings_append_target_er(self): """Test that 'settings append target.er' completes to 'settings append target.error-path'.""" self.complete_from_to(