vfs: check userland buffers before reading them.
[haiku.git] / src / apps / debugger / user_interface / cli / commands / CliThreadCommand.cpp
blob6e8163b0993c6392f3ef95413b4706a377b27ca8
1 /*
2 * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "CliThreadCommand.h"
9 #include <stdio.h>
11 #include <AutoLocker.h>
13 #include "CliContext.h"
14 #include "Team.h"
17 CliThreadCommand::CliThreadCommand()
19 CliCommand("set or print the current thread",
20 "%s [ <thread ID> ]\n"
21 "Sets the current thread to <thread ID>, if supplied. Otherwise prints "
22 "the\n"
23 "current thread.")
28 void
29 CliThreadCommand::Execute(int argc, const char* const* argv,
30 CliContext& context)
32 if (argc > 2) {
33 PrintUsage(argv[0]);
34 return;
37 if (argc < 2) {
38 // no arguments -- print the current thread
39 context.PrintCurrentThread();
40 return;
43 // parse the argument
44 char* endPointer;
45 long threadID = strtol(argv[1], &endPointer, 0);
46 if (*endPointer != '\0' || threadID < 0) {
47 printf("Error: Invalid parameter \"%s\"\n", argv[1]);
48 return;
51 // get the thread and change the current thread
52 Team* team = context.GetTeam();
53 AutoLocker<Team> teamLocker(team);
54 if (Thread* thread = team->ThreadByID(threadID))
55 context.SetCurrentThread(thread);
56 else
57 printf("Error: No thread with ID %ld\n", threadID);