blob: e2c52a61d595bd6f5c0b7336ae1dd72d8117c98d [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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
Jim Ingham84cdc152010-06-15 19:49:27 +000016#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Core/Debugger.h"
18#include "lldb/Core/Timer.h"
Greg Clayton63094e02010-06-23 01:19:29 +000019#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#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
28using namespace lldb;
29using namespace lldb_private;
30
31#pragma mark CommandObjectFrameInfo
32
33//-------------------------------------------------------------------------
34// CommandObjectFrameInfo
35//-------------------------------------------------------------------------
36
37class CommandObjectFrameInfo : public CommandObject
38{
39public:
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
Greg Clayton63094e02010-06-23 01:19:29 +000054 Execute (CommandInterpreter &interpreter,
55 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000056 CommandReturnObject &result)
57 {
Greg Clayton63094e02010-06-23 01:19:29 +000058 ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +000059 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
80class CommandObjectFrameSelect : public CommandObject
81{
82public:
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
Greg Clayton63094e02010-06-23 01:19:29 +000097 Execute (CommandInterpreter &interpreter,
98 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000099 CommandReturnObject &result)
100 {
Greg Clayton63094e02010-06-23 01:19:29 +0000101 ExecutionContext exe_ctx (interpreter.GetDebugger().GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000102 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
Greg Clayton63094e02010-06-23 01:19:29 +0000157CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Chris Lattner24943d22010-06-08 16:52:24 +0000158 CommandObjectMultiword ("frame",
159 "A set of commands for operating on the current thread's frames.",
160 "frame <subcommand> [<subcommand-options>]")
161{
Greg Clayton63094e02010-06-23 01:19:29 +0000162 LoadSubCommand (interpreter, "info", CommandObjectSP (new CommandObjectFrameInfo ()));
163 LoadSubCommand (interpreter, "select", CommandObjectSP (new CommandObjectFrameSelect ()));
Chris Lattner24943d22010-06-08 16:52:24 +0000164}
165
166CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
167{
168}
169