@@ -1134,22 +1134,25 @@ class CommandObjectThreadUntil : public CommandObjectParsed {
1134
1134
1135
1135
class CommandObjectThreadSelect : public CommandObjectParsed {
1136
1136
public:
1137
- class CommandOptions : public Options {
1137
+ class OptionGroupThreadSelect : public OptionGroup {
1138
1138
public:
1139
- CommandOptions () { OptionParsingStarting (nullptr ); }
1139
+ OptionGroupThreadSelect () { OptionParsingStarting (nullptr ); }
1140
1140
1141
- ~CommandOptions () override = default ;
1141
+ ~OptionGroupThreadSelect () override = default ;
1142
1142
1143
1143
void OptionParsingStarting (ExecutionContext *execution_context) override {
1144
- m_thread_id = false ;
1144
+ m_thread_id = LLDB_INVALID_THREAD_ID ;
1145
1145
}
1146
1146
1147
1147
Status SetOptionValue (uint32_t option_idx, llvm::StringRef option_arg,
1148
1148
ExecutionContext *execution_context) override {
1149
- const int short_option = m_getopt_table [option_idx].val ;
1149
+ const int short_option = g_thread_select_options [option_idx].short_option ;
1150
1150
switch (short_option) {
1151
1151
case ' t' : {
1152
- m_thread_id = true ;
1152
+ if (option_arg.getAsInteger (0 , m_thread_id)) {
1153
+ m_thread_id = LLDB_INVALID_THREAD_ID;
1154
+ return Status (" Invalid thread ID: '%s'." , option_arg.str ().c_str ());
1155
+ }
1153
1156
break ;
1154
1157
}
1155
1158
@@ -1164,7 +1167,7 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
1164
1167
return llvm::ArrayRef (g_thread_select_options);
1165
1168
}
1166
1169
1167
- bool m_thread_id;
1170
+ lldb:: tid_t m_thread_id;
1168
1171
};
1169
1172
1170
1173
CommandObjectThreadSelect (CommandInterpreter &interpreter)
@@ -1179,13 +1182,17 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
1179
1182
// Define the first (and only) variant of this arg.
1180
1183
thread_idx_arg.arg_type = eArgTypeThreadIndex;
1181
1184
thread_idx_arg.arg_repetition = eArgRepeatPlain;
1185
+ thread_idx_arg.arg_opt_set_association = LLDB_OPT_SET_1;
1182
1186
1183
1187
// There is only one variant this argument could be; put it into the
1184
1188
// argument entry.
1185
1189
arg.push_back (thread_idx_arg);
1186
1190
1187
1191
// Push the data for the first argument into the m_arguments vector.
1188
1192
m_arguments.push_back (arg);
1193
+
1194
+ m_option_group.Append (&m_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_2);
1195
+ m_option_group.Finalize ();
1189
1196
}
1190
1197
1191
1198
~CommandObjectThreadSelect () override = default ;
@@ -1201,48 +1208,55 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
1201
1208
nullptr );
1202
1209
}
1203
1210
1204
- Options *GetOptions () override { return &m_options ; }
1211
+ Options *GetOptions () override { return &m_option_group ; }
1205
1212
1206
1213
protected:
1207
1214
void DoExecute (Args &command, CommandReturnObject &result) override {
1208
1215
Process *process = m_exe_ctx.GetProcessPtr ();
1209
1216
if (process == nullptr ) {
1210
1217
result.AppendError (" no process" );
1211
1218
return ;
1212
- } else if (command.GetArgumentCount () != 1 ) {
1219
+ } else if (m_options. m_thread_id == LLDB_INVALID_THREAD_ID && command.GetArgumentCount () != 1 ) {
1213
1220
result.AppendErrorWithFormat (
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 ());
1221
+ " '%s' takes exactly one thread index argument, or a thread ID option:\n Usage: %s\n " ,
1222
+ m_cmd_name.c_str (), m_cmd_syntax.c_str ());
1217
1223
return ;
1218
- }
1219
-
1220
- uint32_t index_id;
1221
- if (!llvm::to_integer (command.GetArgumentAtIndex (0 ), index_id)) {
1222
- result.AppendErrorWithFormat (" Invalid thread %s '%s'" ,
1223
- m_options.m_thread_id ? " ID" : " index" ,
1224
- command.GetArgumentAtIndex (0 ));
1224
+ } else if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID && command.GetArgumentCount () != 0 ) {
1225
+ result.AppendErrorWithFormat (
1226
+ " '%s' cannot take both a thread ID option and a thread index argument:\n Usage: %s\n " ,
1227
+ m_cmd_name.c_str (), m_cmd_syntax.c_str ());
1225
1228
return ;
1226
1229
}
1227
1230
1228
1231
Thread *new_thread = nullptr ;
1229
- if (m_options.m_thread_id ) {
1230
- new_thread = process->GetThreadList ().FindThreadByID (index_id).get ();
1232
+ if (command.GetArgumentCount () == 1 ) {
1233
+ uint32_t index_id;
1234
+ if (!llvm::to_integer (command.GetArgumentAtIndex (0 ), index_id)) {
1235
+ result.AppendErrorWithFormat (" Invalid thread index '%s'" ,
1236
+ command.GetArgumentAtIndex (0 ));
1237
+ return ;
1238
+ }
1239
+ new_thread = process->GetThreadList ().FindThreadByIndexID (index_id).get ();
1240
+ if (new_thread == nullptr ) {
1241
+ result.AppendErrorWithFormat (" Invalid thread #%s.\n " ,
1242
+ command.GetArgumentAtIndex (0 ));
1243
+ return ;
1244
+ }
1231
1245
} else {
1232
- new_thread = process->GetThreadList ().FindThreadByIndexID (index_id).get ();
1233
- }
1234
- if (new_thread == nullptr ) {
1235
- result.AppendErrorWithFormat (" invalid thread %s%s.\n " ,
1236
- m_options.m_thread_id ? " ID " : " #" ,
1237
- command.GetArgumentAtIndex (0 ));
1238
- return ;
1246
+ new_thread = process->GetThreadList ().FindThreadByID (m_options.m_thread_id ).get ();
1247
+ if (new_thread == nullptr ) {
1248
+ result.AppendErrorWithFormat (" Invalid thread ID %lu.\n " ,
1249
+ m_options.m_thread_id );
1250
+ return ;
1251
+ }
1239
1252
}
1240
1253
1241
1254
process->GetThreadList ().SetSelectedThreadByID (new_thread->GetID (), true );
1242
1255
result.SetStatus (eReturnStatusSuccessFinishNoResult);
1243
1256
}
1244
1257
1245
- CommandOptions m_options;
1258
+ OptionGroupThreadSelect m_options;
1259
+ OptionGroupOptions m_option_group;
1246
1260
};
1247
1261
1248
1262
// CommandObjectThreadList
0 commit comments