@@ -1129,8 +1129,44 @@ class CommandObjectThreadUntil : public CommandObjectParsed {
1129
1129
1130
1130
// CommandObjectThreadSelect
1131
1131
1132
+ #define LLDB_OPTIONS_thread_select
1133
+ #include " CommandOptions.inc"
1134
+
1132
1135
class CommandObjectThreadSelect : public CommandObjectParsed {
1133
1136
public:
1137
+ class CommandOptions : public Options {
1138
+ public:
1139
+ CommandOptions () { OptionParsingStarting (nullptr ); }
1140
+
1141
+ ~CommandOptions () override = default ;
1142
+
1143
+ void OptionParsingStarting (ExecutionContext *execution_context) override {
1144
+ m_thread_id = false ;
1145
+ }
1146
+
1147
+ Status SetOptionValue (uint32_t option_idx, llvm::StringRef option_arg,
1148
+ ExecutionContext *execution_context) override {
1149
+ const int short_option = m_getopt_table[option_idx].val ;
1150
+ switch (short_option) {
1151
+ case ' t' : {
1152
+ m_thread_id = true ;
1153
+ break ;
1154
+ }
1155
+
1156
+ default :
1157
+ llvm_unreachable (" Unimplemented option" );
1158
+ }
1159
+
1160
+ return {};
1161
+ }
1162
+
1163
+ llvm::ArrayRef<OptionDefinition> GetDefinitions () override {
1164
+ return llvm::ArrayRef (g_thread_select_options);
1165
+ }
1166
+
1167
+ bool m_thread_id;
1168
+ };
1169
+
1134
1170
CommandObjectThreadSelect (CommandInterpreter &interpreter)
1135
1171
: CommandObjectParsed(interpreter, " thread select" ,
1136
1172
" Change the currently selected thread." , nullptr ,
@@ -1165,6 +1201,8 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
1165
1201
nullptr );
1166
1202
}
1167
1203
1204
+ Options *GetOptions () override { return &m_options; }
1205
+
1168
1206
protected:
1169
1207
void DoExecute (Args &command, CommandReturnObject &result) override {
1170
1208
Process *process = m_exe_ctx.GetProcessPtr ();
@@ -1173,29 +1211,38 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
1173
1211
return ;
1174
1212
} else if (command.GetArgumentCount () != 1 ) {
1175
1213
result.AppendErrorWithFormat (
1176
- " '%s' takes exactly one thread index argument:\n Usage: %s\n " ,
1177
- m_cmd_name.c_str (), m_cmd_syntax.c_str ());
1214
+ " '%s' takes exactly one thread %s argument:\n Usage: %s\n " ,
1215
+ m_cmd_name.c_str (), m_options.m_thread_id ? " ID" : " index" ,
1216
+ m_cmd_syntax.c_str ());
1178
1217
return ;
1179
1218
}
1180
1219
1181
1220
uint32_t index_id;
1182
1221
if (!llvm::to_integer (command.GetArgumentAtIndex (0 ), index_id)) {
1183
- result.AppendErrorWithFormat (" Invalid thread index '%s'" ,
1222
+ result.AppendErrorWithFormat (" Invalid thread %s '%s'" ,
1223
+ m_options.m_thread_id ? " ID" : " index" ,
1184
1224
command.GetArgumentAtIndex (0 ));
1185
1225
return ;
1186
1226
}
1187
1227
1188
- Thread *new_thread =
1189
- process->GetThreadList ().FindThreadByIndexID (index_id).get ();
1228
+ Thread *new_thread = nullptr ;
1229
+ if (m_options.m_thread_id ) {
1230
+ new_thread = process->GetThreadList ().FindThreadByID (index_id).get ();
1231
+ } else {
1232
+ new_thread = process->GetThreadList ().FindThreadByIndexID (index_id).get ();
1233
+ }
1190
1234
if (new_thread == nullptr ) {
1191
- result.AppendErrorWithFormat (" invalid thread #%s.\n " ,
1235
+ result.AppendErrorWithFormat (" invalid thread %s%s.\n " ,
1236
+ m_options.m_thread_id ? " ID " : " #" ,
1192
1237
command.GetArgumentAtIndex (0 ));
1193
1238
return ;
1194
1239
}
1195
1240
1196
1241
process->GetThreadList ().SetSelectedThreadByID (new_thread->GetID (), true );
1197
1242
result.SetStatus (eReturnStatusSuccessFinishNoResult);
1198
1243
}
1244
+
1245
+ CommandOptions m_options;
1199
1246
};
1200
1247
1201
1248
// CommandObjectThreadList
0 commit comments