Skip to content

Commit b2b7dbb

Browse files
MrHateTeemperor
authored andcommitted
[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
1 parent 1de173c commit b2b7dbb

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

lldb/include/lldb/Interpreter/CommandCompletions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ class CommandCompletions {
4141
eTypeLanguageCompletion = (1u << 13),
4242
eFrameIndexCompletion = (1u << 14),
4343
eModuleUUIDCompletion = (1u << 15),
44+
eStopHookIDCompletion = (1u << 16),
4445
// This item serves two purposes. It is the last element in the enum, so
4546
// you can add custom enums starting from here in your Option class. Also
4647
// if you & in this bit the base code will not process the option.
47-
eCustomCompletion = (1u << 16)
48+
eCustomCompletion = (1u << 17)
4849
};
4950

5051
static bool InvokeCommonCompletionCallbacks(
@@ -111,6 +112,9 @@ class CommandCompletions {
111112

112113
static void FrameIndexes(CommandInterpreter &interpreter,
113114
CompletionRequest &request, SearchFilter *searcher);
115+
116+
static void StopHookIDs(CommandInterpreter &interpreter,
117+
CompletionRequest &request, SearchFilter *searcher);
114118
};
115119

116120
} // namespace lldb_private

lldb/source/Commands/CommandCompletions.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
6565
{eDisassemblyFlavorCompletion, CommandCompletions::DisassemblyFlavors},
6666
{eTypeLanguageCompletion, CommandCompletions::TypeLanguages},
6767
{eFrameIndexCompletion, CommandCompletions::FrameIndexes},
68+
{eStopHookIDCompletion, CommandCompletions::StopHookIDs},
6869
{eNoCompletion, nullptr} // This one has to be last in the list.
6970
};
7071

@@ -656,3 +657,24 @@ void CommandCompletions::FrameIndexes(CommandInterpreter &interpreter,
656657
request.TryCompleteCurrentArg(std::to_string(i), strm.GetString());
657658
}
658659
}
660+
661+
void CommandCompletions::StopHookIDs(CommandInterpreter &interpreter,
662+
CompletionRequest &request,
663+
SearchFilter *searcher) {
664+
const lldb::TargetSP target_sp =
665+
interpreter.GetExecutionContext().GetTargetSP();
666+
if (!target_sp)
667+
return;
668+
669+
const size_t num = target_sp->GetNumStopHooks();
670+
for (size_t idx = 0; idx < num; ++idx) {
671+
StreamString strm;
672+
// The value 11 is an offset to make the completion description looks
673+
// neater.
674+
strm.SetIndentLevel(11);
675+
const Target::StopHookSP stophook_sp = target_sp->GetStopHookAtIndex(idx);
676+
stophook_sp->GetDescription(&strm, lldb::eDescriptionLevelInitial);
677+
request.TryCompleteCurrentArg(std::to_string(stophook_sp->GetID()),
678+
strm.GetString());
679+
}
680+
}

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4722,6 +4722,16 @@ class CommandObjectTargetStopHookDelete : public CommandObjectParsed {
47224722

47234723
~CommandObjectTargetStopHookDelete() override = default;
47244724

4725+
void
4726+
HandleArgumentCompletion(CompletionRequest &request,
4727+
OptionElementVector &opt_element_vector) override {
4728+
if (request.GetCursorIndex())
4729+
return;
4730+
CommandCompletions::InvokeCommonCompletionCallbacks(
4731+
GetCommandInterpreter(), CommandCompletions::eStopHookIDCompletion,
4732+
request, nullptr);
4733+
}
4734+
47254735
protected:
47264736
bool DoExecute(Args &command, CommandReturnObject &result) override {
47274737
Target &target = GetSelectedOrDummyTarget();
@@ -4770,6 +4780,16 @@ class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed {
47704780

47714781
~CommandObjectTargetStopHookEnableDisable() override = default;
47724782

4783+
void
4784+
HandleArgumentCompletion(CompletionRequest &request,
4785+
OptionElementVector &opt_element_vector) override {
4786+
if (request.GetCursorIndex())
4787+
return;
4788+
CommandCompletions::InvokeCommonCompletionCallbacks(
4789+
GetCommandInterpreter(), CommandCompletions::eStopHookIDCompletion,
4790+
request, nullptr);
4791+
}
4792+
47734793
protected:
47744794
bool DoExecute(Args &command, CommandReturnObject &result) override {
47754795
Target &target = GetSelectedOrDummyTarget();

lldb/test/API/functionalities/completion/TestCompletion.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,26 @@ def test_register_read_and_write_on_x86(self):
548548
self.complete_from_to('register write rbx ',
549549
[])
550550

551+
def test_common_completion_target_stophook_ids(self):
552+
subcommands = ['delete', 'enable', 'disable']
553+
554+
for subcommand in subcommands:
555+
self.complete_from_to('target stop-hook ' + subcommand + ' ',
556+
'target stop-hook ' + subcommand + ' ')
557+
558+
self.build()
559+
self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
560+
self.runCmd('target stop-hook add test DONE')
561+
562+
for subcommand in subcommands:
563+
self.complete_from_to('target stop-hook ' + subcommand + ' ',
564+
'target stop-hook ' + subcommand + ' 1')
565+
566+
# Completion should work only on the first argument.
567+
for subcommand in subcommands:
568+
self.complete_from_to('target stop-hook ' + subcommand + ' 1 ',
569+
'target stop-hook ' + subcommand + ' 1 ')
570+
551571
def test_common_completion_type_language(self):
552572
self.complete_from_to('type category -l ', ['c'])
553573

0 commit comments

Comments
 (0)