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/Interpreter/Args.h" 17 #include "lldb/Core/Debugger.h" 18 #include "lldb/Core/Timer.h" 19 #include "lldb/Core/Debugger.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 (CommandInterpreter &interpreter, 55 Args& command, 56 CommandReturnObject &result) 57 { 58 ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext()); 59 if (exe_ctx.frame) 60 { 61 exe_ctx.frame->Dump (&result.GetOutputStream(), true); 62 result.GetOutputStream().EOL(); 63 result.SetStatus (eReturnStatusSuccessFinishResult); 64 } 65 else 66 { 67 result.AppendError ("no current frame"); 68 result.SetStatus (eReturnStatusFailed); 69 } 70 return result.Succeeded(); 71 } 72 }; 73 74 #pragma mark CommandObjectFrameSelect 75 76 //------------------------------------------------------------------------- 77 // CommandObjectFrameSelect 78 //------------------------------------------------------------------------- 79 80 class CommandObjectFrameSelect : public CommandObject 81 { 82 public: 83 84 CommandObjectFrameSelect () : 85 CommandObject ("frame select", 86 "Select the current frame by index in the current thread.", 87 "frame select <frame-index>", 88 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) 89 { 90 } 91 92 ~CommandObjectFrameSelect () 93 { 94 } 95 96 bool 97 Execute (CommandInterpreter &interpreter, 98 Args& command, 99 CommandReturnObject &result) 100 { 101 ExecutionContext exe_ctx (interpreter.GetDebugger().GetExecutionContext()); 102 if (exe_ctx.thread) 103 { 104 if (command.GetArgumentCount() == 1) 105 { 106 const char *frame_idx_cstr = command.GetArgumentAtIndex(0); 107 108 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount(); 109 const uint32_t frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0); 110 if (frame_idx < num_frames) 111 { 112 exe_ctx.thread->SetCurrentFrameByIndex (frame_idx); 113 exe_ctx.frame = exe_ctx.thread->GetCurrentFrame ().get(); 114 115 if (exe_ctx.frame) 116 { 117 if (DisplayFrameForExecutionContext (exe_ctx.thread, 118 exe_ctx.frame, 119 interpreter, 120 result.GetOutputStream(), 121 true, 122 true, 123 3, 124 3)) 125 { 126 result.SetStatus (eReturnStatusSuccessFinishResult); 127 return result.Succeeded(); 128 } 129 } 130 } 131 if (frame_idx == UINT32_MAX) 132 result.AppendErrorWithFormat ("Invalid frame index: %s.\n", frame_idx_cstr); 133 else 134 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx); 135 } 136 else 137 { 138 result.AppendError ("invalid arguments"); 139 result.AppendErrorWithFormat ("Usage: %s\n", m_cmd_syntax.c_str()); 140 } 141 } 142 else 143 { 144 result.AppendError ("no current thread"); 145 } 146 result.SetStatus (eReturnStatusFailed); 147 return false; 148 } 149 }; 150 151 #pragma mark CommandObjectMultiwordFrame 152 153 //------------------------------------------------------------------------- 154 // CommandObjectMultiwordFrame 155 //------------------------------------------------------------------------- 156 157 CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) : 158 CommandObjectMultiword ("frame", 159 "A set of commands for operating on the current thread's frames.", 160 "frame <subcommand> [<subcommand-options>]") 161 { 162 LoadSubCommand (interpreter, "info", CommandObjectSP (new CommandObjectFrameInfo ())); 163 LoadSubCommand (interpreter, "select", CommandObjectSP (new CommandObjectFrameSelect ())); 164 } 165 166 CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame () 167 { 168 } 169 170