Debugger CLI: Add "threads" command

It just lists the team's thread.
This commit is contained in:
Ingo Weinhold 2012-07-23 23:51:05 +02:00
parent 533a73766d
commit 48b4d20480
4 changed files with 68 additions and 1 deletions

View File

@ -176,6 +176,7 @@ Application Debugger :
# user_interface/cli
CliCommand.cpp
CliContext.cpp
CliThreadsCommand.cpp
CliQuitCommand.cpp
CommandLineUserInterface.cpp

View File

@ -0,0 +1,44 @@
/*
* Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "CliThreadsCommand.h"
#include <stdio.h>
#include <AutoLocker.h>
#include "CliContext.h"
#include "Team.h"
#include "UiUtils.h"
CliThreadsCommand::CliThreadsCommand()
:
CliCommand("list the team's threads",
"%s\n"
"Lists the team's threads.")
{
}
void
CliThreadsCommand::Execute(int argc, const char* const* argv,
CliContext& context)
{
Team* team = context.GetTeam();
AutoLocker<Team> teamLocker(team);
printf(" ID state name\n");
printf("----------------------------\n");
for (ThreadList::ConstIterator it = team->Threads().GetIterator();
Thread* thread = it.Next();) {
const char* stateString = UiUtils::ThreadStateToString(
thread->State(), thread->StoppedReason());
printf("%10" B_PRId32 " %-9s \"%s\"\n", thread->ID(), stateString,
thread->Name());
}
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef CLI_THREADS_COMMAND_H
#define CLI_THREADS_COMMAND_H
#include "CliCommand.h"
class CliThreadsCommand : public CliCommand {
public:
CliThreadsCommand();
virtual void Execute(int argc, const char* const* argv,
CliContext& context);
};
#endif // CLI_THREADS_COMMAND_H

View File

@ -20,6 +20,7 @@
#include "CliContext.h"
#include "CliQuitCommand.h"
#include "CliThreadsCommand.h"
// #pragma mark - CommandEntry
@ -243,7 +244,8 @@ status_t
CommandLineUserInterface::_RegisterCommands()
{
if (_RegisterCommand("help", new(std::nothrow) HelpCommand(this)) &&
_RegisterCommand("quit", new(std::nothrow) CliQuitCommand)) {
_RegisterCommand("quit", new(std::nothrow) CliQuitCommand) &&
_RegisterCommand("threads", new(std::nothrow) CliThreadsCommand)) {
return B_OK;
}