Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame^] | 1 | //===-- CommandObjectFrame.cpp ----------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "CommandObjectFrame.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Core/Args.h" |
| 17 | #include "lldb/Core/Debugger.h" |
| 18 | #include "lldb/Core/Timer.h" |
| 19 | #include "lldb/Interpreter/CommandContext.h" |
| 20 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 21 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 22 | #include "lldb/Target/Process.h" |
| 23 | #include "lldb/Target/StackFrame.h" |
| 24 | #include "lldb/Target/Thread.h" |
| 25 | |
| 26 | #include "CommandObjectThread.h" |
| 27 | |
| 28 | using namespace lldb; |
| 29 | using namespace lldb_private; |
| 30 | |
| 31 | #pragma mark CommandObjectFrameInfo |
| 32 | |
| 33 | //------------------------------------------------------------------------- |
| 34 | // CommandObjectFrameInfo |
| 35 | //------------------------------------------------------------------------- |
| 36 | |
| 37 | class CommandObjectFrameInfo : public CommandObject |
| 38 | { |
| 39 | public: |
| 40 | |
| 41 | CommandObjectFrameInfo () : |
| 42 | CommandObject ("frame info", |
| 43 | "Lists information about the currently selected frame in the current thread.", |
| 44 | "frame info", |
| 45 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | ~CommandObjectFrameInfo () |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | bool |
| 54 | Execute (Args& command, |
| 55 | CommandContext *context, |
| 56 | CommandInterpreter *interpreter, |
| 57 | CommandReturnObject &result) |
| 58 | { |
| 59 | ExecutionContext exe_ctx(context->GetExecutionContext()); |
| 60 | if (exe_ctx.frame) |
| 61 | { |
| 62 | exe_ctx.frame->Dump (&result.GetOutputStream(), true); |
| 63 | result.GetOutputStream().EOL(); |
| 64 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | result.AppendError ("no current frame"); |
| 69 | result.SetStatus (eReturnStatusFailed); |
| 70 | } |
| 71 | return result.Succeeded(); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | #pragma mark CommandObjectFrameSelect |
| 76 | |
| 77 | //------------------------------------------------------------------------- |
| 78 | // CommandObjectFrameSelect |
| 79 | //------------------------------------------------------------------------- |
| 80 | |
| 81 | class CommandObjectFrameSelect : public CommandObject |
| 82 | { |
| 83 | public: |
| 84 | |
| 85 | CommandObjectFrameSelect () : |
| 86 | CommandObject ("frame select", |
| 87 | "Select the current frame by index in the current thread.", |
| 88 | "frame select <frame-index>", |
| 89 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | ~CommandObjectFrameSelect () |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | bool |
| 98 | Execute (Args& command, |
| 99 | CommandContext *context, |
| 100 | CommandInterpreter *interpreter, |
| 101 | CommandReturnObject &result) |
| 102 | { |
| 103 | ExecutionContext exe_ctx (context->GetExecutionContext()); |
| 104 | if (exe_ctx.thread) |
| 105 | { |
| 106 | if (command.GetArgumentCount() == 1) |
| 107 | { |
| 108 | const char *frame_idx_cstr = command.GetArgumentAtIndex(0); |
| 109 | |
| 110 | const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount(); |
| 111 | const uint32_t frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0); |
| 112 | if (frame_idx < num_frames) |
| 113 | { |
| 114 | exe_ctx.thread->SetCurrentFrameByIndex (frame_idx); |
| 115 | exe_ctx.frame = exe_ctx.thread->GetCurrentFrame ().get(); |
| 116 | |
| 117 | if (exe_ctx.frame) |
| 118 | { |
| 119 | if (DisplayFrameForExecutionContext (exe_ctx.thread, |
| 120 | exe_ctx.frame, |
| 121 | interpreter, |
| 122 | result.GetOutputStream(), |
| 123 | true, |
| 124 | true, |
| 125 | 3, |
| 126 | 3)) |
| 127 | { |
| 128 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 129 | return result.Succeeded(); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | if (frame_idx == UINT32_MAX) |
| 134 | result.AppendErrorWithFormat ("Invalid frame index: %s.\n", frame_idx_cstr); |
| 135 | else |
| 136 | result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | result.AppendError ("invalid arguments"); |
| 141 | result.AppendErrorWithFormat ("Usage: %s\n", m_cmd_syntax.c_str()); |
| 142 | } |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | result.AppendError ("no current thread"); |
| 147 | } |
| 148 | result.SetStatus (eReturnStatusFailed); |
| 149 | return false; |
| 150 | } |
| 151 | }; |
| 152 | |
| 153 | #pragma mark CommandObjectMultiwordFrame |
| 154 | |
| 155 | //------------------------------------------------------------------------- |
| 156 | // CommandObjectMultiwordFrame |
| 157 | //------------------------------------------------------------------------- |
| 158 | |
| 159 | CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter *interpreter) : |
| 160 | CommandObjectMultiword ("frame", |
| 161 | "A set of commands for operating on the current thread's frames.", |
| 162 | "frame <subcommand> [<subcommand-options>]") |
| 163 | { |
| 164 | LoadSubCommand (CommandObjectSP (new CommandObjectFrameInfo ()), "info", interpreter); |
| 165 | LoadSubCommand (CommandObjectSP (new CommandObjectFrameSelect ()), "select", interpreter); |
| 166 | } |
| 167 | |
| 168 | CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame () |
| 169 | { |
| 170 | } |
| 171 | |