Debugger: Extend CLI stop command.

- "stop" now allows optionally specifying a thread ID to stop an arbitrary
thread in the team, rather than always targetting the current one.
This commit is contained in:
Rene Gollent
2013-12-07 09:59:00 -05:00
parent 00b42dde0d
commit ffe61f274b
@@ -17,9 +17,11 @@
CliStopCommand::CliStopCommand() CliStopCommand::CliStopCommand()
: :
CliCommand("stop the current thread", CliCommand("stop a thread",
"%s\n" "%s [ <thread ID> ]\n"
"Stops the current thread.") "Stops the thread specified by <thread ID>, if supplied. Otherwise "
"stops\n"
"the current thread.")
{ {
} }
@@ -28,15 +30,41 @@ void
CliStopCommand::Execute(int argc, const char* const* argv, CliStopCommand::Execute(int argc, const char* const* argv,
CliContext& context) CliContext& context)
{ {
AutoLocker<Team> teamLocker(context.GetTeam()); if (argc > 2) {
Thread* thread = context.CurrentThread(); PrintUsage(argv[0]);
if (thread == NULL) {
printf("Error: No current thread.\n");
return; return;
} }
AutoLocker<Team> teamLocker(context.GetTeam());
Thread* thread = NULL;
if (argc < 2) {
thread = context.CurrentThread();
if (thread == NULL) {
printf("Error: No current thread.\n");
return;
}
} else if (argc == 2) {
// parse the argument
char* endPointer;
long threadID = strtol(argv[1], &endPointer, 0);
if (*endPointer != '\0' || threadID < 0) {
printf("Error: Invalid parameter \"%s\"\n", argv[1]);
return;
}
// get the thread and change the current thread
Team* team = context.GetTeam();
thread = team->ThreadByID(threadID);
if (thread == NULL) {
printf("Error: No thread with ID %ld\n", threadID);
return;
}
}
if (thread->State() == THREAD_STATE_STOPPED) { if (thread->State() == THREAD_STATE_STOPPED) {
printf("Error: The current thread is already stopped.\n"); printf("Error: thread %" B_PRId32 " is already stopped.\n",
thread->ID());
return; return;
} }