forked from OSchip/llvm-project
[lldb] stop-hook ID common completion for commands `target stop-hook enable/disable/delete'
1. Added a common completion StopHookIDs to provide completion with a list of stop hook ids; 2. Applied the common completion to commands: `target stop-hook delete/enable/disable'; 3. Added an related test case. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D84123
This commit is contained in:
parent
1de173c049
commit
b2b7dbb47a
|
@ -41,10 +41,11 @@ public:
|
|||
eTypeLanguageCompletion = (1u << 13),
|
||||
eFrameIndexCompletion = (1u << 14),
|
||||
eModuleUUIDCompletion = (1u << 15),
|
||||
eStopHookIDCompletion = (1u << 16),
|
||||
// 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 << 16)
|
||||
eCustomCompletion = (1u << 17)
|
||||
};
|
||||
|
||||
static bool InvokeCommonCompletionCallbacks(
|
||||
|
@ -111,6 +112,9 @@ public:
|
|||
|
||||
static void FrameIndexes(CommandInterpreter &interpreter,
|
||||
CompletionRequest &request, SearchFilter *searcher);
|
||||
|
||||
static void StopHookIDs(CommandInterpreter &interpreter,
|
||||
CompletionRequest &request, SearchFilter *searcher);
|
||||
};
|
||||
|
||||
} // namespace lldb_private
|
||||
|
|
|
@ -65,6 +65,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
|
|||
{eDisassemblyFlavorCompletion, CommandCompletions::DisassemblyFlavors},
|
||||
{eTypeLanguageCompletion, CommandCompletions::TypeLanguages},
|
||||
{eFrameIndexCompletion, CommandCompletions::FrameIndexes},
|
||||
{eStopHookIDCompletion, CommandCompletions::StopHookIDs},
|
||||
{eNoCompletion, nullptr} // This one has to be last in the list.
|
||||
};
|
||||
|
||||
|
@ -656,3 +657,24 @@ void CommandCompletions::FrameIndexes(CommandInterpreter &interpreter,
|
|||
request.TryCompleteCurrentArg(std::to_string(i), strm.GetString());
|
||||
}
|
||||
}
|
||||
|
||||
void CommandCompletions::StopHookIDs(CommandInterpreter &interpreter,
|
||||
CompletionRequest &request,
|
||||
SearchFilter *searcher) {
|
||||
const lldb::TargetSP target_sp =
|
||||
interpreter.GetExecutionContext().GetTargetSP();
|
||||
if (!target_sp)
|
||||
return;
|
||||
|
||||
const size_t num = target_sp->GetNumStopHooks();
|
||||
for (size_t idx = 0; idx < num; ++idx) {
|
||||
StreamString strm;
|
||||
// The value 11 is an offset to make the completion description looks
|
||||
// neater.
|
||||
strm.SetIndentLevel(11);
|
||||
const Target::StopHookSP stophook_sp = target_sp->GetStopHookAtIndex(idx);
|
||||
stophook_sp->GetDescription(&strm, lldb::eDescriptionLevelInitial);
|
||||
request.TryCompleteCurrentArg(std::to_string(stophook_sp->GetID()),
|
||||
strm.GetString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4722,6 +4722,16 @@ public:
|
|||
|
||||
~CommandObjectTargetStopHookDelete() override = default;
|
||||
|
||||
void
|
||||
HandleArgumentCompletion(CompletionRequest &request,
|
||||
OptionElementVector &opt_element_vector) override {
|
||||
if (request.GetCursorIndex())
|
||||
return;
|
||||
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||
GetCommandInterpreter(), CommandCompletions::eStopHookIDCompletion,
|
||||
request, nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||
Target &target = GetSelectedOrDummyTarget();
|
||||
|
@ -4770,6 +4780,16 @@ public:
|
|||
|
||||
~CommandObjectTargetStopHookEnableDisable() override = default;
|
||||
|
||||
void
|
||||
HandleArgumentCompletion(CompletionRequest &request,
|
||||
OptionElementVector &opt_element_vector) override {
|
||||
if (request.GetCursorIndex())
|
||||
return;
|
||||
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||
GetCommandInterpreter(), CommandCompletions::eStopHookIDCompletion,
|
||||
request, nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||
Target &target = GetSelectedOrDummyTarget();
|
||||
|
|
|
@ -548,6 +548,26 @@ class CommandLineCompletionTestCase(TestBase):
|
|||
self.complete_from_to('register write rbx ',
|
||||
[])
|
||||
|
||||
def test_common_completion_target_stophook_ids(self):
|
||||
subcommands = ['delete', 'enable', 'disable']
|
||||
|
||||
for subcommand in subcommands:
|
||||
self.complete_from_to('target stop-hook ' + subcommand + ' ',
|
||||
'target stop-hook ' + subcommand + ' ')
|
||||
|
||||
self.build()
|
||||
self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
|
||||
self.runCmd('target stop-hook add test DONE')
|
||||
|
||||
for subcommand in subcommands:
|
||||
self.complete_from_to('target stop-hook ' + subcommand + ' ',
|
||||
'target stop-hook ' + subcommand + ' 1')
|
||||
|
||||
# Completion should work only on the first argument.
|
||||
for subcommand in subcommands:
|
||||
self.complete_from_to('target stop-hook ' + subcommand + ' 1 ',
|
||||
'target stop-hook ' + subcommand + ' 1 ')
|
||||
|
||||
def test_common_completion_type_language(self):
|
||||
self.complete_from_to('type category -l ', ['c'])
|
||||
|
||||
|
|
Loading…
Reference in New Issue