[Lldb-commits] [lldb] f99a18b - [lldb] tab completion for `thread plan discard`
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 11 01:08:45 PDT 2020
Author: Gongyu Deng
Date: 2020-08-11T10:08:16+02:00
New Revision: f99a18bbaa02037b8f2e9fc066d50e2373b5017e
URL: https://github.com/llvm/llvm-project/commit/f99a18bbaa02037b8f2e9fc066d50e2373b5017e
DIFF: https://github.com/llvm/llvm-project/commit/f99a18bbaa02037b8f2e9fc066d50e2373b5017e.diff
LOG: [lldb] tab completion for `thread plan discard`
Dedicated completion for the command `thread plan discard` with a corresponding
test case.
Reviewed By: teemperor
Differential Revision: https://reviews.llvm.org/D83234
Added:
lldb/test/API/functionalities/completion/thread_plan_script.py
Modified:
lldb/include/lldb/Target/Thread.h
lldb/source/Commands/CommandObjectThread.cpp
lldb/source/Target/Thread.cpp
lldb/test/API/functionalities/completion/TestCompletion.py
Removed:
################################################################################
diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h
index 066b8e1845c0..59e4d8a8f872 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -19,6 +19,7 @@
#include "lldb/Target/RegisterCheckpoint.h"
#include "lldb/Target/StackFrameList.h"
#include "lldb/Utility/Broadcaster.h"
+#include "lldb/Utility/CompletionRequest.h"
#include "lldb/Utility/Event.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/UserID.h"
@@ -911,6 +912,12 @@ class Thread : public std::enable_shared_from_this<Thread>,
// Thread Plan accessors:
+ /// Format the thread plan information for auto completion.
+ ///
+ /// \param[in] request
+ /// The reference to the completion handler.
+ void AutoCompleteThreadPlans(CompletionRequest &request) const;
+
/// Gets the plan which will execute next on the plan stack.
///
/// \return
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index 666c208c3206..c2fd86aa8cba 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -1985,6 +1985,15 @@ class CommandObjectThreadPlanDiscard : public CommandObjectParsed {
~CommandObjectThreadPlanDiscard() override = default;
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override {
+ if (!m_exe_ctx.HasThreadScope() || request.GetCursorIndex())
+ return;
+
+ m_exe_ctx.GetThreadPtr()->AutoCompleteThreadPlans(request);
+ }
+
bool DoExecute(Args &args, CommandReturnObject &result) override {
Thread *thread = m_exe_ctx.GetThreadPtr();
if (args.GetArgumentCount() != 1) {
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index fdf60f96f983..bc5d31190a61 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -1103,6 +1103,22 @@ void Thread::DiscardPlan() {
discarded_plan_sp->GetThread().GetID());
}
+void Thread::AutoCompleteThreadPlans(CompletionRequest &request) const {
+ const ThreadPlanStack &plans = GetPlans();
+ if (!plans.AnyPlans())
+ return;
+
+ // Iterate from the second plan (index: 1) to skip the base plan.
+ ThreadPlanSP p;
+ uint32_t i = 1;
+ while (p = plans.GetPlanByIndex(i, false)) {
+ StreamString strm;
+ p->GetDescription(&strm, eDescriptionLevelInitial);
+ request.TryCompleteCurrentArg(std::to_string(i), strm.GetString());
+ i++;
+ }
+}
+
ThreadPlan *Thread::GetCurrentPlan() const {
return GetPlans().GetCurrentPlan().get();
}
diff --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py
index 030bd25d3454..3e7878dcbdaa 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -329,6 +329,19 @@ def test_settings_set_target_process_thread_dot(self):
['target.process.thread.step-avoid-regexp',
'target.process.thread.trace-thread'])
+ def test_thread_plan_discard(self):
+ self.build()
+ (_, _, thread, _) = lldbutil.run_to_source_breakpoint(self,
+ 'ptr_foo', lldb.SBFileSpec("main.cpp"))
+ self.assertTrue(thread)
+ self.complete_from_to('thread plan discard ', 'thread plan discard ')
+
+ source_path = os.path.join(self.getSourceDir(), "thread_plan_script.py")
+ self.runCmd("command script import '%s'"%(source_path))
+ self.runCmd("thread step-scripted -C thread_plan_script.PushPlanStack")
+ self.complete_from_to('thread plan discard ', 'thread plan discard 1')
+ self.runCmd('thread plan discard 1')
+
def test_target_space(self):
"""Test that 'target ' completes to ['create', 'delete', 'list',
'modules', 'select', 'stop-hook', 'variable']."""
diff --git a/lldb/test/API/functionalities/completion/thread_plan_script.py b/lldb/test/API/functionalities/completion/thread_plan_script.py
new file mode 100644
index 000000000000..3226d50f1bdb
--- /dev/null
+++ b/lldb/test/API/functionalities/completion/thread_plan_script.py
@@ -0,0 +1,20 @@
+#############################################################################
+# This script is just to provide a thread plan which won't be popped instantly
+# for the completion test. The thread plan class below won't really do anything
+# itself.
+
+import lldb
+
+class PushPlanStack:
+
+ def __init__(self, thread_plan, dict):
+ pass
+
+ def explains_stop(self, event):
+ return False
+
+ def should_stop(self, event):
+ return True
+
+ def should_step(self):
+ return True
More information about the lldb-commits
mailing list