Index: lldb/source/Commands/CommandObjectTarget.cpp =================================================================== --- lldb/source/Commands/CommandObjectTarget.cpp +++ lldb/source/Commands/CommandObjectTarget.cpp @@ -1167,6 +1167,24 @@ ~CommandObjectTargetModulesSearchPathsInsert() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + if (!m_exe_ctx.HasTargetScope() || request.GetCursorIndex()) + return; + + Target *target = m_exe_ctx.GetTargetPtr(); + const PathMappingList &list = target->GetImageSearchPathList(); + const size_t num = list.GetSize(); + ConstString old_path, new_path; + for (size_t i = 0; i < num; ++i) + if (list.GetPathsAtIndex(i, old_path, new_path)) { + StreamString strm; + strm << old_path << " -> " << new_path; + request.TryCompleteCurrentArg(std::to_string(i), strm.GetString()); + } + } + protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); Index: lldb/test/API/functionalities/completion/TestCompletion.py =================================================================== --- lldb/test/API/functionalities/completion/TestCompletion.py +++ lldb/test/API/functionalities/completion/TestCompletion.py @@ -342,6 +342,18 @@ self.complete_from_to('target modules load a.ou', ['a.out']) + def test_target_modules_search_paths_insert(self): + # Completion won't work without a valid target. + self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") + self.build() + target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) + self.assertTrue(target, VALID_TARGET) + self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") + self.runCmd("target modules search-paths add a b") + self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert 0") + # Completion only works for the first arg. + self.complete_from_to("target modules search-paths insert 0 ", "target modules search-paths insert 0 ") + def test_target_create_dash_co(self): """Test that 'target create --co' completes to 'target variable --core '.""" self.complete_from_to('target create --co', 'target create --core ')