1/* 2 * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7#include "CliThreadsCommand.h" 8 9#include <stdio.h> 10 11#include <AutoLocker.h> 12 13#include "CliContext.h" 14#include "Team.h" 15#include "UiUtils.h" 16 17 18CliThreadsCommand::CliThreadsCommand() 19 : 20 CliCommand("list the team's threads", 21 "%s\n" 22 "Lists the team's threads.") 23{ 24} 25 26 27void 28CliThreadsCommand::Execute(int argc, const char* const* argv, 29 CliContext& context) 30{ 31 Team* team = context.GetTeam(); 32 AutoLocker<Team> teamLocker(team); 33 34 printf(" ID state name\n"); 35 printf("----------------------------\n"); 36 37 for (ThreadList::ConstIterator it = team->Threads().GetIterator(); 38 Thread* thread = it.Next();) { 39 const char* stateString = UiUtils::ThreadStateToString( 40 thread->State(), thread->StoppedReason()); 41 printf("%10" B_PRId32 " %-9s \"%s\"", thread->ID(), stateString, 42 thread->Name()); 43 44 const BString& stoppedReason = thread->StoppedReasonInfo(); 45 if (thread->State() == THREAD_STATE_STOPPED 46 && !stoppedReason.IsEmpty()) { 47 printf(" (Reason: \"%s\")", stoppedReason.String()); 48 } 49 printf("\n"); 50 } 51} 52