Add some more commands to the CLI.

- Added 'frame' command for setting/printing the context's current stack
  frame within the active stack trace.
- Added 'variables' command for printing the list of variables visible
  within the current frame.
This commit is contained in:
Rene Gollent
2012-12-16 22:03:35 -05:00
parent 1325ad5fe8
commit 287cda6f72
5 changed files with 144 additions and 1 deletions
+2
View File
@@ -193,11 +193,13 @@ Application Debugger :
CliContext.cpp
CliContinueCommand.cpp
CliDebugReportCommand.cpp
CliStackFrameCommand.cpp
CliStackTraceCommand.cpp
CliStopCommand.cpp
CliThreadCommand.cpp
CliThreadsCommand.cpp
CliQuitCommand.cpp
CliVariablesCommand.cpp
CommandLineUserInterface.cpp
# user_interface/gui
@@ -0,0 +1,64 @@
/*
* Copyright 2012, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "CliStackFrameCommand.h"
#include <stdio.h>
#include <AutoLocker.h>
#include "CliContext.h"
#include "FunctionInstance.h"
#include "StackFrame.h"
#include "StackTrace.h"
#include "Team.h"
CliStackFrameCommand::CliStackFrameCommand()
:
CliCommand("set current stack frame",
"%s [ <frame number> ]\n"
"Sets the current stack frame to <frame number>, if supplied. "
"Otherwise\n prints the current frame.")
{
}
void
CliStackFrameCommand::Execute(int argc, const char* const* argv,
CliContext& context)
{
if (argc > 2) {
PrintUsage(argv[0]);
return;
}
StackTrace* stackTrace = context.GetStackTrace();
if (argc == 1) {
int32 currentFrameIndex = context.CurrentStackFrameIndex();
if (currentFrameIndex < 0)
printf("No current frame.\n");
else {
StackFrame* frame = stackTrace->FrameAt(currentFrameIndex);
printf("Current frame: %" B_PRId32 ": %s\n", currentFrameIndex,
frame->Function()->PrettyName().String());
}
return;
}
// parse the argument
char* endPointer;
int32 frameNumber = strtol(argv[1], &endPointer, 0);
if (*endPointer != '\0' || frameNumber < 0) {
printf("Error: Invalid parameter \"%s\"\n", argv[1]);
return;
}
if (stackTrace == NULL || frameNumber >= stackTrace->CountFrames()) {
printf("Error: Index %" B_PRId32 " out of range\n", frameNumber);
return;
} else
context.SetCurrentStackFrameIndex(frameNumber);
}
@@ -0,0 +1,20 @@
/*
* Copyright 2012, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef CLI_STACK_FRAME_COMMAND_H
#define CLI_STACK_FRAME_COMMAND_H
#include "CliCommand.h"
class CliStackFrameCommand : public CliCommand {
public:
CliStackFrameCommand();
virtual void Execute(int argc, const char* const* argv,
CliContext& context);
};
#endif // CLI_STACK_FRAME_COMMAND_H
@@ -0,0 +1,52 @@
/*
* Copyright 2012, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "CliVariablesCommand.h"
#include <stdio.h>
#include <AutoLocker.h>
#include "CliContext.h"
#include "Team.h"
#include "ValueNode.h"
#include "ValueNodeContainer.h"
#include "ValueNodeManager.h"
CliVariablesCommand::CliVariablesCommand()
:
CliCommand("show current frame variables",
"%s\n"
"Prints the parameters and variables of the current frame, if "
" available.")
{
}
void
CliVariablesCommand::Execute(int argc, const char* const* argv,
CliContext& context)
{
if (argc > 1) {
PrintUsage(argv[0]);
return;
}
ValueNodeManager* manager = context.GetValueNodeManager();
ValueNodeContainer* container = manager->GetContainer();
AutoLocker<ValueNodeContainer> containerLocker(container);
if (container == NULL || container->CountChildren() == 0) {
printf("No variables available.\n");
return;
}
printf("Variables:\n");
for (int32 i = 0; ValueNodeChild* child = container->ChildAt(i); i++) {
printf(" %s\n", child->Name().String());
}
}
@@ -19,10 +19,12 @@
#include "CliContinueCommand.h"
#include "CliDebugReportCommand.h"
#include "CliQuitCommand.h"
#include "CliStackFrameCommand.h"
#include "CliStackTraceCommand.h"
#include "CliStopCommand.h"
#include "CliThreadCommand.h"
#include "CliThreadsCommand.h"
#include "CliVariablesCommand.h"
static const char* kDebuggerPrompt = "debugger> ";
@@ -309,6 +311,7 @@ CommandLineUserInterface::_RegisterCommands()
if (_RegisterCommand("bt", stackTraceCommandReference.Detach())
&& _RegisterCommand("continue", new(std::nothrow) CliContinueCommand)
&& _RegisterCommand("frame", new(std::nothrow) CliStackFrameCommand)
&& _RegisterCommand("help", new(std::nothrow) HelpCommand(this))
&& _RegisterCommand("quit", new(std::nothrow) CliQuitCommand)
&& _RegisterCommand("save-report",
@@ -316,7 +319,9 @@ CommandLineUserInterface::_RegisterCommands()
&& _RegisterCommand("sc", stackTraceCommandReference2.Detach())
&& _RegisterCommand("stop", new(std::nothrow) CliStopCommand)
&& _RegisterCommand("thread", new(std::nothrow) CliThreadCommand)
&& _RegisterCommand("threads", new(std::nothrow) CliThreadsCommand)) {
&& _RegisterCommand("threads", new(std::nothrow) CliThreadsCommand)
&& _RegisterCommand("variables",
new(std::nothrow) CliVariablesCommand)) {
return B_OK;
}