Skip to content

Commit e30a155

Browse files
committed
Code review changes -- update help text and usage text, fix format specifier, add thread ID completion
1 parent 3ef88cd commit e30a155

File tree

7 files changed

+31
-6
lines changed

7 files changed

+31
-6
lines changed

lldb/include/lldb/Interpreter/CommandCompletions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ class CommandCompletions {
120120
CompletionRequest &request,
121121
SearchFilter *searcher);
122122

123+
static void ThreadIDs(CommandInterpreter &interpreter,
124+
CompletionRequest &request, SearchFilter *searcher);
125+
123126
/// This completer works for commands whose only arguments are a command path.
124127
/// It isn't tied to an argument type because it completes not on a single
125128
/// argument but on the sequence of arguments, so you have to invoke it by

lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ static constexpr OptionEnumValueElement g_completion_type[] = {
191191
"Completes to a remote disk directory."},
192192
{lldb::eTypeCategoryNameCompletion, "type-category-name",
193193
"Completes to a type category name."},
194+
{lldb::eThreadIDCompletion, "thread-id", "Completes to a thread ID."},
194195
{lldb::eCustomCompletion, "custom", "Custom completion."},
195196
};
196197

lldb/include/lldb/lldb-enumerations.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,10 +1296,11 @@ enum CompletionType {
12961296
eRemoteDiskFileCompletion = (1u << 22),
12971297
eRemoteDiskDirectoryCompletion = (1u << 23),
12981298
eTypeCategoryNameCompletion = (1u << 24),
1299+
eThreadIDCompletion = (1u << 25),
12991300
// This item serves two purposes. It is the last element in the enum, so
13001301
// you can add custom enums starting from here in your Option class. Also
13011302
// if you & in this bit the base code will not process the option.
1302-
eCustomCompletion = (1u << 25)
1303+
eCustomCompletion = (1u << 26)
13031304
};
13041305

13051306
} // namespace lldb

lldb/source/Commands/CommandCompletions.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
8383
CommandCompletions::RemoteDiskDirectories},
8484
{lldb::eTypeCategoryNameCompletion,
8585
CommandCompletions::TypeCategoryNames},
86+
{lldb::eThreadIDCompletion, CommandCompletions::ThreadIDs},
8687
{lldb::CompletionType::eNoCompletion,
8788
nullptr} // This one has to be last in the list.
8889
};
@@ -807,6 +808,23 @@ void CommandCompletions::TypeCategoryNames(CommandInterpreter &interpreter,
807808
});
808809
}
809810

811+
void CommandCompletions::ThreadIDs(CommandInterpreter &interpreter,
812+
CompletionRequest &request,
813+
SearchFilter *searcher) {
814+
const ExecutionContext &exe_ctx = interpreter.GetExecutionContext();
815+
if (!exe_ctx.HasProcessScope())
816+
return;
817+
818+
ThreadList &threads = exe_ctx.GetProcessPtr()->GetThreadList();
819+
lldb::ThreadSP thread_sp;
820+
for (uint32_t idx = 0; (thread_sp = threads.GetThreadAtIndex(idx)); ++idx) {
821+
StreamString strm;
822+
thread_sp->GetStatus(strm, 0, 1, 1, true);
823+
request.TryCompleteCurrentArg(std::to_string(thread_sp->GetID()),
824+
strm.GetString());
825+
}
826+
}
827+
810828
void CommandCompletions::CompleteModifiableCmdPathArgs(
811829
CommandInterpreter &interpreter, CompletionRequest &request,
812830
OptionElementVector &opt_element_vector) {

lldb/source/Commands/CommandObjectThread.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,8 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
11721172

11731173
CommandObjectThreadSelect(CommandInterpreter &interpreter)
11741174
: CommandObjectParsed(interpreter, "thread select",
1175-
"Change the currently selected thread.", nullptr,
1175+
"Change the currently selected thread.",
1176+
"thread select <thread-index> (or -t <thread-id>)",
11761177
eCommandRequiresProcess | eCommandTryTargetAPILock |
11771178
eCommandProcessMustBeLaunched |
11781179
eCommandProcessMustBePaused) {
@@ -1241,15 +1242,15 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
12411242
}
12421243
new_thread = process->GetThreadList().FindThreadByIndexID(index_id).get();
12431244
if (new_thread == nullptr) {
1244-
result.AppendErrorWithFormat("Invalid thread #%s.\n",
1245+
result.AppendErrorWithFormat("Invalid thread index #%s.\n",
12451246
command.GetArgumentAtIndex(0));
12461247
return;
12471248
}
12481249
} else {
12491250
new_thread =
12501251
process->GetThreadList().FindThreadByID(m_options.m_thread_id).get();
12511252
if (new_thread == nullptr) {
1252-
result.AppendErrorWithFormat("Invalid thread ID %lu.\n",
1253+
result.AppendErrorWithFormat("Invalid thread ID %" PRIu64 ".\n",
12531254
m_options.m_thread_id);
12541255
return;
12551256
}

lldb/source/Commands/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,8 @@ let Command = "thread plan list" in {
11191119

11201120
let Command = "thread select" in {
11211121
def thread_select_thread_id : Option<"thread-id", "t">, Group<2>,
1122-
Arg<"ThreadID">, Desc<"Provide a thread ID instead of a thread index.">;
1122+
Arg<"ThreadID">, Completion<"ThreadID">,
1123+
Desc<"Provide a thread ID instead of a thread index.">;
11231124
}
11241125

11251126
let Command = "thread trace dump function calls" in {

lldb/test/API/commands/thread/select/TestThreadSelect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_invalid_arg(self):
3636
self.expect(
3737
"thread select 0xffffffff",
3838
error=True,
39-
startstr="error: Invalid thread #0xffffffff.",
39+
startstr="error: Invalid thread index #0xffffffff.",
4040
)
4141
self.expect(
4242
"thread select -t 0xffffffff",

0 commit comments

Comments
 (0)