[Lldb-commits] [lldb] 24bc8af - [lldb] tab completion for `target modules search-paths insert`
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 11 02:58:33 PDT 2020
Author: Gongyu Deng
Date: 2020-08-11T11:58:14+02:00
New Revision: 24bc8afd4baf703be7f4f4d70745d7680ceb54e2
URL: https://github.com/llvm/llvm-project/commit/24bc8afd4baf703be7f4f4d70745d7680ceb54e2
DIFF: https://github.com/llvm/llvm-project/commit/24bc8afd4baf703be7f4f4d70745d7680ceb54e2.diff
LOG: [lldb] tab completion for `target modules search-paths insert`
Dedicated completion for the command `target modules search-paths insert` with a test case.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D83309
Added:
Modified:
lldb/source/Commands/CommandObjectTarget.cpp
lldb/test/API/functionalities/completion/TestCompletion.py
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 84b7c988353a..927070f3d3ba 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1157,6 +1157,25 @@ class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed {
~CommandObjectTargetModulesSearchPathsInsert() override = default;
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
+ if (!m_exe_ctx.HasTargetScope() || request.GetCursorIndex() != 0)
+ 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))
+ break;
+ 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();
diff --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py
index 2a757638cd82..436a464aa645 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -368,6 +368,18 @@ def test_target_modules_load_aout(self):
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 ')
More information about the lldb-commits
mailing list