forked from OSchip/llvm-project
[lldb] watchpoint ID common completion for commands `watchpoint delete/enable/disable/modify/ignore`
1. Added a common completion WatchPointIDs to complete with a list of the IDs of the current watchpoints; 2. Applied the completion to these commands: watchpoint delete/enable/disable/modify/ignore; 3. Added a correlated test case. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D84104
This commit is contained in:
parent
3483c28c5b
commit
4f3559db1f
lldb
include/lldb/Interpreter
source/Commands
test/API/functionalities/completion
|
@ -43,10 +43,11 @@ public:
|
||||||
eModuleUUIDCompletion = (1u << 15),
|
eModuleUUIDCompletion = (1u << 15),
|
||||||
eStopHookIDCompletion = (1u << 16),
|
eStopHookIDCompletion = (1u << 16),
|
||||||
eThreadIndexCompletion = (1u << 17),
|
eThreadIndexCompletion = (1u << 17),
|
||||||
|
eWatchPointIDCompletion = (1u << 18),
|
||||||
// This item serves two purposes. It is the last element in the enum, so
|
// 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
|
// 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.
|
// if you & in this bit the base code will not process the option.
|
||||||
eCustomCompletion = (1u << 18)
|
eCustomCompletion = (1u << 19)
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool InvokeCommonCompletionCallbacks(
|
static bool InvokeCommonCompletionCallbacks(
|
||||||
|
@ -119,6 +120,9 @@ public:
|
||||||
|
|
||||||
static void ThreadIndexes(CommandInterpreter &interpreter,
|
static void ThreadIndexes(CommandInterpreter &interpreter,
|
||||||
CompletionRequest &request, SearchFilter *searcher);
|
CompletionRequest &request, SearchFilter *searcher);
|
||||||
|
|
||||||
|
static void WatchPointIDs(CommandInterpreter &interpreter,
|
||||||
|
CompletionRequest &request, SearchFilter *searcher);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lldb_private
|
} // namespace lldb_private
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/StringSet.h"
|
#include "llvm/ADT/StringSet.h"
|
||||||
|
|
||||||
|
#include "lldb/Breakpoint/Watchpoint.h"
|
||||||
#include "lldb/Core/FileSpecList.h"
|
#include "lldb/Core/FileSpecList.h"
|
||||||
#include "lldb/Core/Module.h"
|
#include "lldb/Core/Module.h"
|
||||||
#include "lldb/Core/PluginManager.h"
|
#include "lldb/Core/PluginManager.h"
|
||||||
|
@ -68,6 +69,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||||
{eFrameIndexCompletion, CommandCompletions::FrameIndexes},
|
{eFrameIndexCompletion, CommandCompletions::FrameIndexes},
|
||||||
{eStopHookIDCompletion, CommandCompletions::StopHookIDs},
|
{eStopHookIDCompletion, CommandCompletions::StopHookIDs},
|
||||||
{eThreadIndexCompletion, CommandCompletions::ThreadIndexes},
|
{eThreadIndexCompletion, CommandCompletions::ThreadIndexes},
|
||||||
|
{eWatchPointIDCompletion, CommandCompletions::WatchPointIDs},
|
||||||
{eNoCompletion, nullptr} // This one has to be last in the list.
|
{eNoCompletion, nullptr} // This one has to be last in the list.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -697,3 +699,21 @@ void CommandCompletions::ThreadIndexes(CommandInterpreter &interpreter,
|
||||||
strm.GetString());
|
strm.GetString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommandCompletions::WatchPointIDs(CommandInterpreter &interpreter,
|
||||||
|
CompletionRequest &request,
|
||||||
|
SearchFilter *searcher) {
|
||||||
|
const ExecutionContext &exe_ctx = interpreter.GetExecutionContext();
|
||||||
|
if (!exe_ctx.HasTargetScope())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const WatchpointList &wp_list = exe_ctx.GetTargetPtr()->GetWatchpointList();
|
||||||
|
const size_t wp_num = wp_list.GetSize();
|
||||||
|
for (size_t idx = 0; idx < wp_num; ++idx) {
|
||||||
|
const lldb::WatchpointSP wp_sp = wp_list.GetByIndex(idx);
|
||||||
|
StreamString strm;
|
||||||
|
wp_sp->Dump(&strm);
|
||||||
|
request.TryCompleteCurrentArg(std::to_string(wp_sp->GetID()),
|
||||||
|
strm.GetString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -292,6 +292,14 @@ public:
|
||||||
|
|
||||||
~CommandObjectWatchpointEnable() override = default;
|
~CommandObjectWatchpointEnable() override = default;
|
||||||
|
|
||||||
|
void
|
||||||
|
HandleArgumentCompletion(CompletionRequest &request,
|
||||||
|
OptionElementVector &opt_element_vector) override {
|
||||||
|
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||||
|
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
|
||||||
|
request, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||||
Target *target = &GetSelectedTarget();
|
Target *target = &GetSelectedTarget();
|
||||||
|
@ -362,6 +370,14 @@ public:
|
||||||
|
|
||||||
~CommandObjectWatchpointDisable() override = default;
|
~CommandObjectWatchpointDisable() override = default;
|
||||||
|
|
||||||
|
void
|
||||||
|
HandleArgumentCompletion(CompletionRequest &request,
|
||||||
|
OptionElementVector &opt_element_vector) override {
|
||||||
|
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||||
|
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
|
||||||
|
request, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||||
Target *target = &GetSelectedTarget();
|
Target *target = &GetSelectedTarget();
|
||||||
|
@ -439,6 +455,14 @@ public:
|
||||||
|
|
||||||
~CommandObjectWatchpointDelete() override = default;
|
~CommandObjectWatchpointDelete() override = default;
|
||||||
|
|
||||||
|
void
|
||||||
|
HandleArgumentCompletion(CompletionRequest &request,
|
||||||
|
OptionElementVector &opt_element_vector) override {
|
||||||
|
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||||
|
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
|
||||||
|
request, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
Options *GetOptions() override { return &m_options; }
|
Options *GetOptions() override { return &m_options; }
|
||||||
|
|
||||||
class CommandOptions : public Options {
|
class CommandOptions : public Options {
|
||||||
|
@ -557,6 +581,14 @@ public:
|
||||||
|
|
||||||
~CommandObjectWatchpointIgnore() override = default;
|
~CommandObjectWatchpointIgnore() override = default;
|
||||||
|
|
||||||
|
void
|
||||||
|
HandleArgumentCompletion(CompletionRequest &request,
|
||||||
|
OptionElementVector &opt_element_vector) override {
|
||||||
|
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||||
|
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
|
||||||
|
request, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
Options *GetOptions() override { return &m_options; }
|
Options *GetOptions() override { return &m_options; }
|
||||||
|
|
||||||
class CommandOptions : public Options {
|
class CommandOptions : public Options {
|
||||||
|
@ -677,6 +709,14 @@ public:
|
||||||
|
|
||||||
~CommandObjectWatchpointModify() override = default;
|
~CommandObjectWatchpointModify() override = default;
|
||||||
|
|
||||||
|
void
|
||||||
|
HandleArgumentCompletion(CompletionRequest &request,
|
||||||
|
OptionElementVector &opt_element_vector) override {
|
||||||
|
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||||
|
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
|
||||||
|
request, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
Options *GetOptions() override { return &m_options; }
|
Options *GetOptions() override { return &m_options; }
|
||||||
|
|
||||||
class CommandOptions : public Options {
|
class CommandOptions : public Options {
|
||||||
|
|
|
@ -232,6 +232,22 @@ class CommandLineCompletionTestCase(TestBase):
|
||||||
"""Test that 'help watchpoint s' completes to 'help watchpoint set '."""
|
"""Test that 'help watchpoint s' completes to 'help watchpoint set '."""
|
||||||
self.complete_from_to('help watchpoint s', 'help watchpoint set ')
|
self.complete_from_to('help watchpoint s', 'help watchpoint set ')
|
||||||
|
|
||||||
|
def test_common_complete_watchpoint_ids(self):
|
||||||
|
subcommands = ['enable', 'disable', 'delete', 'modify', 'ignore']
|
||||||
|
|
||||||
|
# Completion should not work without a target.
|
||||||
|
for subcommand in subcommands:
|
||||||
|
self.complete_from_to('watchpoint ' + subcommand + ' ',
|
||||||
|
'watchpoint ' + subcommand + ' ')
|
||||||
|
|
||||||
|
# Create a process to provide a target and enable watchpoint setting.
|
||||||
|
self.build()
|
||||||
|
lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp"))
|
||||||
|
|
||||||
|
self.runCmd('watchpoint set variable ptr_fooo')
|
||||||
|
for subcommand in subcommands:
|
||||||
|
self.complete_from_to('watchpoint ' + subcommand + ' ', ['1'])
|
||||||
|
|
||||||
def test_settings_append_target_er(self):
|
def test_settings_append_target_er(self):
|
||||||
"""Test that 'settings append target.er' completes to 'settings append target.error-path'."""
|
"""Test that 'settings append target.er' completes to 'settings append target.error-path'."""
|
||||||
self.complete_from_to(
|
self.complete_from_to(
|
||||||
|
|
Loading…
Reference in New Issue