From ffe61f274b386d1e8bd52e2ea763fb01a8fd6359 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sat, 7 Dec 2013 09:59:00 -0500 Subject: [PATCH] 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. --- .../cli/commands/CliStopCommand.cpp | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/apps/debugger/user_interface/cli/commands/CliStopCommand.cpp b/src/apps/debugger/user_interface/cli/commands/CliStopCommand.cpp index 40961b4b00..43d2426837 100644 --- a/src/apps/debugger/user_interface/cli/commands/CliStopCommand.cpp +++ b/src/apps/debugger/user_interface/cli/commands/CliStopCommand.cpp @@ -17,9 +17,11 @@ CliStopCommand::CliStopCommand() : - CliCommand("stop the current thread", - "%s\n" - "Stops the current thread.") + CliCommand("stop a thread", + "%s [ ]\n" + "Stops the thread specified by , if supplied. Otherwise " + "stops\n" + "the current thread.") { } @@ -28,15 +30,41 @@ void CliStopCommand::Execute(int argc, const char* const* argv, CliContext& context) { - AutoLocker teamLocker(context.GetTeam()); - Thread* thread = context.CurrentThread(); - if (thread == NULL) { - printf("Error: No current thread.\n"); + if (argc > 2) { + PrintUsage(argv[0]); return; } + + AutoLocker 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) { - printf("Error: The current thread is already stopped.\n"); + printf("Error: thread %" B_PRId32 " is already stopped.\n", + thread->ID()); return; }