diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index 1eb7571b33..4a3795c974 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -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 diff --git a/src/apps/debugger/user_interface/cli/CliStackFrameCommand.cpp b/src/apps/debugger/user_interface/cli/CliStackFrameCommand.cpp new file mode 100644 index 0000000000..cc8dcc7fc6 --- /dev/null +++ b/src/apps/debugger/user_interface/cli/CliStackFrameCommand.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2012, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ + + +#include "CliStackFrameCommand.h" + +#include + +#include + +#include "CliContext.h" +#include "FunctionInstance.h" +#include "StackFrame.h" +#include "StackTrace.h" +#include "Team.h" + + +CliStackFrameCommand::CliStackFrameCommand() + : + CliCommand("set current stack frame", + "%s [ ]\n" + "Sets the current stack frame to , 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); +} diff --git a/src/apps/debugger/user_interface/cli/CliStackFrameCommand.h b/src/apps/debugger/user_interface/cli/CliStackFrameCommand.h new file mode 100644 index 0000000000..e6b41de4ea --- /dev/null +++ b/src/apps/debugger/user_interface/cli/CliStackFrameCommand.h @@ -0,0 +1,20 @@ +/* + * Copyright 2012, Rene Gollent, rene@gollent.com. + * 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 diff --git a/src/apps/debugger/user_interface/cli/CliVariablesCommand.cpp b/src/apps/debugger/user_interface/cli/CliVariablesCommand.cpp new file mode 100644 index 0000000000..d513c26017 --- /dev/null +++ b/src/apps/debugger/user_interface/cli/CliVariablesCommand.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ + + +#include "CliVariablesCommand.h" + +#include + +#include + +#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 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()); + } +} diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp index 54f7d4c943..de846471e2 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp @@ -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; }