This revision was automatically updated to reflect the committed changes. Closed by commit rGe1cd7cac8a36: [lldb] Tab completion for process load/unload (authored by MrHate, committed by teemperor). Herald added a subscriber: lldb-commits.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79887/new/ https://reviews.llvm.org/D79887 Files: lldb/include/lldb/Target/Process.h lldb/source/Commands/CommandObjectProcess.cpp lldb/test/API/functionalities/completion/Makefile lldb/test/API/functionalities/completion/TestCompletion.py lldb/test/API/functionalities/completion/shared.cpp
Index: lldb/test/API/functionalities/completion/shared.cpp =================================================================== --- /dev/null +++ lldb/test/API/functionalities/completion/shared.cpp @@ -0,0 +1,3 @@ +int foo() { + return 123; +} Index: lldb/test/API/functionalities/completion/TestCompletion.py =================================================================== --- lldb/test/API/functionalities/completion/TestCompletion.py +++ lldb/test/API/functionalities/completion/TestCompletion.py @@ -85,6 +85,31 @@ ['mips', 'arm64']) + def test_process_load(self): + self.build() + lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) + self.complete_from_to('process load Makef', 'process load Makefile') + + @skipUnlessPlatform(["linux"]) + def test_process_unload(self): + """Test the completion for "process unload <index>" """ + # This tab completion should not work without a running process. + self.complete_from_to('process unload ', + 'process unload ') + + self.build() + lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) + err = lldb.SBError() + self.process().LoadImage(lldb.SBFileSpec(self.getBuildArtifact("libshared.so")), err) + self.assertSuccess(err) + + self.complete_from_to('process unload ', + 'process unload 0') + + self.process().UnloadImage(0) + self.complete_from_to('process unload ', + 'process unload ') + def test_process_plugin_completion(self): subcommands = ['attach -P', 'connect -p', 'launch -p'] Index: lldb/test/API/functionalities/completion/Makefile =================================================================== --- lldb/test/API/functionalities/completion/Makefile +++ lldb/test/API/functionalities/completion/Makefile @@ -1,3 +1,10 @@ CXX_SOURCES := main.cpp +USE_LIBDL := 1 + +a.out: lib_shared + +lib_shared: + $(MAKE) -f $(MAKEFILE_RULES) \ + DYLIB_ONLY=YES DYLIB_CXX_SOURCES=shared.cpp DYLIB_NAME=shared include Makefile.rules Index: lldb/source/Commands/CommandObjectProcess.cpp =================================================================== --- lldb/source/Commands/CommandObjectProcess.cpp +++ lldb/source/Commands/CommandObjectProcess.cpp @@ -923,6 +923,17 @@ ~CommandObjectProcessLoad() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + if (!m_exe_ctx.HasProcessScope()) + return; + + CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion, + request, nullptr); + } + Options *GetOptions() override { return &m_options; } protected: @@ -988,6 +999,24 @@ ~CommandObjectProcessUnload() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + + if (request.GetCursorIndex() || !m_exe_ctx.HasProcessScope()) + return; + + Process *process = m_exe_ctx.GetProcessPtr(); + + const std::vector<lldb::addr_t> &tokens = process->GetImageTokens(); + const size_t token_num = tokens.size(); + for (size_t i = 0; i < token_num; ++i) { + if (tokens[i] == LLDB_INVALID_IMAGE_TOKEN) + continue; + request.TryCompleteCurrentArg(std::to_string(i)); + } + } + protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Process *process = m_exe_ctx.GetProcessPtr(); Index: lldb/include/lldb/Target/Process.h =================================================================== --- lldb/include/lldb/Target/Process.h +++ lldb/include/lldb/Target/Process.h @@ -739,6 +739,12 @@ void SetShouldDetach(bool b) { m_should_detach = b; } + /// Get the image vector for the current process. + /// + /// \return + /// The constant reference to the member m_image_tokens. + const std::vector<lldb::addr_t>& GetImageTokens() { return m_image_tokens; } + /// Get the image information address for the current process. /// /// Some runtimes have system functions that can help dynamic loaders locate
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits