[Lldb-commits] [lldb] a952fe2 - [lldb] thread index common completion for commands like `thread select/step-over`
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 11 04:27:31 PDT 2020
Author: Gongyu Deng
Date: 2020-08-11T13:27:13+02:00
New Revision: a952fe236f993b531eceb89e0a18d25bba048185
URL: https://github.com/llvm/llvm-project/commit/a952fe236f993b531eceb89e0a18d25bba048185
DIFF: https://github.com/llvm/llvm-project/commit/a952fe236f993b531eceb89e0a18d25bba048185.diff
LOG: [lldb] thread index common completion for commands like `thread select/step-over`
1. Added a common completion completing with a list of the threads of the current process;
2. Apply the common completion above to these commands: thread
continue/info/exception/select/step-in/step-inst/step-inst-over/step-out/step-over/step-script​
3. Correlated test case test_common_completion_thread_index.
Reviewed By: teemperor
Differential Revision: https://reviews.llvm.org/D84088
Added:
Modified:
lldb/include/lldb/Interpreter/CommandCompletions.h
lldb/source/Commands/CommandCompletions.cpp
lldb/source/Commands/CommandObjectThread.cpp
lldb/test/API/functionalities/completion/TestCompletion.py
Removed:
################################################################################
diff --git a/lldb/include/lldb/Interpreter/CommandCompletions.h b/lldb/include/lldb/Interpreter/CommandCompletions.h
index 60d42a8c990f..105c43528bec 100644
--- a/lldb/include/lldb/Interpreter/CommandCompletions.h
+++ b/lldb/include/lldb/Interpreter/CommandCompletions.h
@@ -42,10 +42,11 @@ class CommandCompletions {
eFrameIndexCompletion = (1u << 14),
eModuleUUIDCompletion = (1u << 15),
eStopHookIDCompletion = (1u << 16),
+ eThreadIndexCompletion = (1u << 17),
// 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 << 17)
+ eCustomCompletion = (1u << 18)
};
static bool InvokeCommonCompletionCallbacks(
@@ -115,6 +116,9 @@ class CommandCompletions {
static void StopHookIDs(CommandInterpreter &interpreter,
CompletionRequest &request, SearchFilter *searcher);
+
+ static void ThreadIndexes(CommandInterpreter &interpreter,
+ CompletionRequest &request, SearchFilter *searcher);
};
} // namespace lldb_private
diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp
index de0e07eb36b9..526efe32fb48 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -19,6 +19,7 @@
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/Language.h"
+#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/FileSpec.h"
@@ -66,6 +67,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
{eTypeLanguageCompletion, CommandCompletions::TypeLanguages},
{eFrameIndexCompletion, CommandCompletions::FrameIndexes},
{eStopHookIDCompletion, CommandCompletions::StopHookIDs},
+ {eThreadIndexCompletion, CommandCompletions::ThreadIndexes},
{eNoCompletion, nullptr} // This one has to be last in the list.
};
@@ -678,3 +680,20 @@ void CommandCompletions::StopHookIDs(CommandInterpreter &interpreter,
strm.GetString());
}
}
+
+void CommandCompletions::ThreadIndexes(CommandInterpreter &interpreter,
+ CompletionRequest &request,
+ SearchFilter *searcher) {
+ const ExecutionContext &exe_ctx = interpreter.GetExecutionContext();
+ if (!exe_ctx.HasProcessScope())
+ return;
+
+ ThreadList &threads = exe_ctx.GetProcessPtr()->GetThreadList();
+ lldb::ThreadSP thread_sp;
+ for (uint32_t idx = 0; (thread_sp = threads.GetThreadAtIndex(idx)); ++idx) {
+ StreamString strm;
+ thread_sp->GetStatus(strm, 0, 1, 1, true);
+ request.TryCompleteCurrentArg(std::to_string(thread_sp->GetIndexID()),
+ strm.GetString());
+ }
+}
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index c2fd86aa8cba..f0392264bff7 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -549,6 +549,17 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
~CommandObjectThreadStepWithTypeAndScope() override = default;
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
+ if (request.GetCursorIndex())
+ return;
+
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
+ request, nullptr);
+ }
+
Options *GetOptions() override { return &m_all_options; }
protected:
@@ -815,6 +826,14 @@ class CommandObjectThreadContinue : public CommandObjectParsed {
~CommandObjectThreadContinue() override = default;
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
+ request, nullptr);
+ }
+
bool DoExecute(Args &command, CommandReturnObject &result) override {
bool synchronous_execution = m_interpreter.GetSynchronous();
@@ -1307,6 +1326,17 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
~CommandObjectThreadSelect() override = default;
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
+ if (request.GetCursorIndex())
+ return;
+
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
+ request, nullptr);
+ }
+
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
Process *process = m_exe_ctx.GetProcessPtr();
@@ -1438,6 +1468,14 @@ class CommandObjectThreadInfo : public CommandObjectIterateOverThreads {
~CommandObjectThreadInfo() override = default;
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
+ request, nullptr);
+ }
+
Options *GetOptions() override { return &m_options; }
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
@@ -1482,6 +1520,14 @@ class CommandObjectThreadException : public CommandObjectIterateOverThreads {
~CommandObjectThreadException() override = default;
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
+ request, nullptr);
+ }
+
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
ThreadSP thread_sp =
m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
diff --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py
index c420f32cc3a1..f4be62f48e25 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -388,6 +388,22 @@ def test_target_va(self):
"""Test that 'target va' completes to 'target variable '."""
self.complete_from_to('target va', 'target variable ')
+ 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']
+
+ # Completion should do nothing without threads.
+ for subcommand in subcommands:
+ self.complete_from_to('thread ' + subcommand + ' ',
+ 'thread ' + subcommand + ' ')
+
+ self.build()
+ lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp"))
+
+ # At least we have the thread at the index of 1 now.
+ for subcommand in subcommands:
+ self.complete_from_to('thread ' + subcommand + ' ', ['1'])
+
def test_command_argument_completion(self):
"""Test completion of command arguments"""
self.complete_from_to("watchpoint set variable -", ["-w", "-s"])
More information about the lldb-commits
mailing list