blob: c44a45b893025d1d78ca68002ec747abc92a0270 [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
Johnny Chen10b12b32011-09-16 21:41:42 +000014#include <string>
Chris Lattner24943d22010-06-08 16:52:24 +000015// Other libraries and framework includes
16// Project includes
Enrico Granata0be2e9b2011-08-22 22:03:47 +000017#include "lldb/Core/DataVisualization.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Core/Debugger.h"
Jim Ingham537926c2010-09-02 00:18:39 +000019#include "lldb/Core/Module.h"
20#include "lldb/Core/StreamFile.h"
Johnny Chen10b12b32011-09-16 21:41:42 +000021#include "lldb/Core/StreamString.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Timer.h"
Jim Ingham537926c2010-09-02 00:18:39 +000023#include "lldb/Core/Value.h"
24#include "lldb/Core/ValueObject.h"
25#include "lldb/Core/ValueObjectVariable.h"
Greg Claytoncd548032011-02-01 01:31:41 +000026#include "lldb/Host/Host.h"
Jim Ingham537926c2010-09-02 00:18:39 +000027#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028#include "lldb/Interpreter/CommandInterpreter.h"
29#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham537926c2010-09-02 00:18:39 +000030#include "lldb/Interpreter/Options.h"
Greg Claytona42880a2011-10-25 06:44:01 +000031#include "lldb/Interpreter/OptionGroupFormat.h"
Jim Ingham10de7d12011-05-04 03:43:18 +000032#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton368f8222011-07-07 04:38:25 +000033#include "lldb/Interpreter/OptionGroupVariable.h"
Jim Ingham537926c2010-09-02 00:18:39 +000034#include "lldb/Symbol/ClangASTType.h"
35#include "lldb/Symbol/ClangASTContext.h"
36#include "lldb/Symbol/ObjectFile.h"
37#include "lldb/Symbol/SymbolContext.h"
38#include "lldb/Symbol/Type.h"
39#include "lldb/Symbol/Variable.h"
40#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000041#include "lldb/Target/Process.h"
42#include "lldb/Target/StackFrame.h"
43#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000044#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000045
Chris Lattner24943d22010-06-08 16:52:24 +000046using namespace lldb;
47using namespace lldb_private;
48
49#pragma mark CommandObjectFrameInfo
50
51//-------------------------------------------------------------------------
52// CommandObjectFrameInfo
53//-------------------------------------------------------------------------
54
55class CommandObjectFrameInfo : public CommandObject
56{
57public:
58
Greg Clayton238c0a12010-09-18 01:14:36 +000059 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
60 CommandObject (interpreter,
61 "frame info",
62 "List information about the currently selected frame in the current thread.",
63 "frame info",
64 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000065 {
66 }
67
68 ~CommandObjectFrameInfo ()
69 {
70 }
71
72 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000073 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000074 CommandReturnObject &result)
75 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000076 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +000077 StackFrame *frame = exe_ctx.GetFramePtr();
78 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +000079 {
Greg Clayton567e7f32011-09-22 04:58:26 +000080 frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000081 result.SetStatus (eReturnStatusSuccessFinishResult);
82 }
83 else
84 {
85 result.AppendError ("no current frame");
86 result.SetStatus (eReturnStatusFailed);
87 }
88 return result.Succeeded();
89 }
90};
91
92#pragma mark CommandObjectFrameSelect
93
94//-------------------------------------------------------------------------
95// CommandObjectFrameSelect
96//-------------------------------------------------------------------------
97
98class CommandObjectFrameSelect : public CommandObject
99{
100public:
101
Greg Claytonc12b6b42010-10-10 22:28:11 +0000102 class CommandOptions : public Options
103 {
104 public:
105
Greg Claytonf15996e2011-04-07 22:46:35 +0000106 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000107 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000108 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000109 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000110 }
111
112 virtual
113 ~CommandOptions ()
114 {
115 }
116
117 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000118 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000119 {
120 Error error;
121 bool success = false;
122 char short_option = (char) m_getopt_table[option_idx].val;
123 switch (short_option)
124 {
125 case 'r':
126 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
127 if (!success)
Greg Clayton9c236732011-10-26 00:56:27 +0000128 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'", option_arg);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000129 break;
130
131 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000132 error.SetErrorStringWithFormat ("invalid short option character '%c'", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000133 break;
134 }
135
136 return error;
137 }
138
139 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000140 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000141 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000142 relative_frame_offset = INT32_MIN;
143 }
144
Greg Claytonb3448432011-03-24 21:19:54 +0000145 const OptionDefinition*
Greg Claytonc12b6b42010-10-10 22:28:11 +0000146 GetDefinitions ()
147 {
148 return g_option_table;
149 }
150
151 // Options table: Required for subclasses of Options.
152
Greg Claytonb3448432011-03-24 21:19:54 +0000153 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000154 int32_t relative_frame_offset;
155 };
156
Greg Clayton238c0a12010-09-18 01:14:36 +0000157 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
158 CommandObject (interpreter,
159 "frame select",
160 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000161 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000162 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
163 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000164 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000165 CommandArgumentEntry arg;
166 CommandArgumentData index_arg;
167
168 // Define the first (and only) variant of this arg.
169 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000170 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000171
172 // There is only one variant this argument could be; put it into the argument entry.
173 arg.push_back (index_arg);
174
175 // Push the data for the first argument into the m_arguments vector.
176 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000177 }
178
179 ~CommandObjectFrameSelect ()
180 {
181 }
182
Greg Claytonc12b6b42010-10-10 22:28:11 +0000183 virtual
184 Options *
185 GetOptions ()
186 {
187 return &m_options;
188 }
189
190
Chris Lattner24943d22010-06-08 16:52:24 +0000191 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000192 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000193 CommandReturnObject &result)
194 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000195 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000196 Thread *thread = exe_ctx.GetThreadPtr();
197 if (thread)
Chris Lattner24943d22010-06-08 16:52:24 +0000198 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000199 const uint32_t num_frames = thread->GetStackFrameCount();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000200 uint32_t frame_idx = UINT32_MAX;
201 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000202 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000203 // The one and only argument is a signed relative frame index
Greg Clayton567e7f32011-09-22 04:58:26 +0000204 frame_idx = thread->GetSelectedFrameIndex ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000205 if (frame_idx == UINT32_MAX)
206 frame_idx = 0;
207
208 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000209 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000210 if (frame_idx >= -m_options.relative_frame_offset)
211 frame_idx += m_options.relative_frame_offset;
212 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000213 {
214 if (frame_idx == 0)
215 {
216 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
217 result.AppendError("Already at the bottom of the stack");
218 result.SetStatus(eReturnStatusFailed);
219 return false;
220 }
221 else
222 frame_idx = 0;
223 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000224 }
225 else if (m_options.relative_frame_offset > 0)
226 {
227 if (num_frames - frame_idx > m_options.relative_frame_offset)
228 frame_idx += m_options.relative_frame_offset;
229 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000230 {
231 if (frame_idx == num_frames - 1)
232 {
233 //If we are already at the top of the stack, just warn and don't reset the frame.
234 result.AppendError("Already at the top of the stack");
235 result.SetStatus(eReturnStatusFailed);
236 return false;
237 }
238 else
239 frame_idx = num_frames - 1;
240 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000241 }
242 }
243 else
244 {
245 if (command.GetArgumentCount() == 1)
246 {
247 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
248 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
249 }
Jason Molenda7685ccc2011-09-30 23:12:14 +0000250 else if (command.GetArgumentCount() == 0)
Jason Molenda811ded52011-09-29 23:02:41 +0000251 {
252 frame_idx = thread->GetSelectedFrameIndex ();
253 if (frame_idx == UINT32_MAX)
Jason Molenda7685ccc2011-09-30 23:12:14 +0000254 {
Jason Molenda811ded52011-09-29 23:02:41 +0000255 frame_idx = 0;
Jason Molenda7685ccc2011-09-30 23:12:14 +0000256 }
Jason Molenda811ded52011-09-29 23:02:41 +0000257 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000258 else
259 {
260 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000261 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000262 }
263 }
264
265 if (frame_idx < num_frames)
266 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000267 thread->SetSelectedFrameByIndex (frame_idx);
268 exe_ctx.SetFrameSP(thread->GetSelectedFrame ());
269 StackFrame *frame = exe_ctx.GetFramePtr();
270 if (frame)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000271 {
272 bool already_shown = false;
Greg Clayton567e7f32011-09-22 04:58:26 +0000273 SymbolContext frame_sc(frame->GetSymbolContext(eSymbolContextLineEntry));
Greg Claytonc12b6b42010-10-10 22:28:11 +0000274 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000275 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000276 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
277 }
Jim Ingham74989e82010-08-30 19:44:40 +0000278
Greg Claytonabe0fed2011-04-18 08:33:37 +0000279 bool show_frame_info = true;
280 bool show_source = !already_shown;
Greg Clayton289afcb2012-02-18 05:35:26 +0000281 Debugger &debugger = m_interpreter.GetDebugger();
282 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
283 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
Greg Clayton567e7f32011-09-22 04:58:26 +0000284 if (frame->GetStatus (result.GetOutputStream(),
285 show_frame_info,
286 show_source,
287 source_lines_before,
288 source_lines_after))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000289 {
290 result.SetStatus (eReturnStatusSuccessFinishResult);
291 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000292 }
293 }
Chris Lattner24943d22010-06-08 16:52:24 +0000294 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000295 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000296 }
297 else
298 {
299 result.AppendError ("no current thread");
300 }
301 result.SetStatus (eReturnStatusFailed);
302 return false;
303 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000304protected:
305
306 CommandOptions m_options;
307};
308
Greg Claytonb3448432011-03-24 21:19:54 +0000309OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000310CommandObjectFrameSelect::CommandOptions::g_option_table[] =
311{
312{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
313{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000314};
315
Jim Ingham537926c2010-09-02 00:18:39 +0000316#pragma mark CommandObjectFrameVariable
317//----------------------------------------------------------------------
318// List images with associated information
319//----------------------------------------------------------------------
320class CommandObjectFrameVariable : public CommandObject
321{
322public:
323
Greg Clayton238c0a12010-09-18 01:14:36 +0000324 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
325 CommandObject (interpreter,
326 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000327 "Show frame variables. All argument and local variables "
328 "that are in scope will be shown when no arguments are given. "
329 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000330 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000331 "Children of aggregate variables can be specified such as "
Johnny Chen2b05e292012-02-14 22:00:40 +0000332 "'var->child.x'.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000333 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000334 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Jim Ingham10de7d12011-05-04 03:43:18 +0000335 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000336 m_option_variable(true), // Include the frame specific options by passing "true"
Greg Claytona42880a2011-10-25 06:44:01 +0000337 m_option_format (eFormatDefault),
Jim Ingham10de7d12011-05-04 03:43:18 +0000338 m_varobj_options()
Jim Ingham537926c2010-09-02 00:18:39 +0000339 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000340 CommandArgumentEntry arg;
341 CommandArgumentData var_name_arg;
342
343 // Define the first (and only) variant of this arg.
344 var_name_arg.arg_type = eArgTypeVarName;
345 var_name_arg.arg_repetition = eArgRepeatStar;
346
347 // There is only one variant this argument could be; put it into the argument entry.
348 arg.push_back (var_name_arg);
349
350 // Push the data for the first argument into the m_arguments vector.
351 m_arguments.push_back (arg);
Jim Ingham10de7d12011-05-04 03:43:18 +0000352
Greg Clayton368f8222011-07-07 04:38:25 +0000353 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton24a6bd92011-10-27 17:55:14 +0000354 m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1);
Jim Ingham10de7d12011-05-04 03:43:18 +0000355 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
356 m_option_group.Finalize();
Jim Ingham537926c2010-09-02 00:18:39 +0000357 }
358
359 virtual
360 ~CommandObjectFrameVariable ()
361 {
362 }
363
364 virtual
365 Options *
366 GetOptions ()
367 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000368 return &m_option_group;
Jim Ingham537926c2010-09-02 00:18:39 +0000369 }
370
Jim Ingham537926c2010-09-02 00:18:39 +0000371
372 virtual bool
373 Execute
374 (
Jim Ingham537926c2010-09-02 00:18:39 +0000375 Args& command,
376 CommandReturnObject &result
377 )
378 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000379 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000380 StackFrame *frame = exe_ctx.GetFramePtr();
381 if (frame == NULL)
Jim Ingham537926c2010-09-02 00:18:39 +0000382 {
Greg Claytonaa448052010-09-18 04:06:15 +0000383 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000384 result.SetStatus (eReturnStatusFailed);
385 return false;
386 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000387
388 Stream &s = result.GetOutputStream();
389
390 bool get_file_globals = true;
391
392 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
393 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
394
Greg Clayton567e7f32011-09-22 04:58:26 +0000395 VariableList *variable_list = frame->GetVariableList (get_file_globals);
Johnny Chen649d3f12011-09-12 23:58:53 +0000396
397 VariableSP var_sp;
398 ValueObjectSP valobj_sp;
399
400 const char *name_cstr = NULL;
401 size_t idx;
402
Enrico Granata16376ed2012-02-15 02:34:21 +0000403 TypeSummaryImplSP summary_format_sp;
Johnny Chen649d3f12011-09-12 23:58:53 +0000404 if (!m_option_variable.summary.empty())
405 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.c_str()), summary_format_sp);
406
407 ValueObject::DumpValueObjectOptions options;
408
409 options.SetPointerDepth(m_varobj_options.ptr_depth)
410 .SetMaximumDepth(m_varobj_options.max_depth)
411 .SetShowTypes(m_varobj_options.show_types)
412 .SetShowLocation(m_varobj_options.show_location)
413 .SetUseObjectiveC(m_varobj_options.use_objc)
414 .SetUseDynamicType(m_varobj_options.use_dynamic)
415 .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth)
416 .SetFlatOutput(m_varobj_options.flat_output)
417 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
418 .SetIgnoreCap(m_varobj_options.ignore_cap);
419
420 if (m_varobj_options.be_raw)
421 options.SetRawDisplay(true);
422
423 if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000424 {
Greg Claytona42880a2011-10-25 06:44:01 +0000425 const Format format = m_option_format.GetFormat();
426
Johnny Chen649d3f12011-09-12 23:58:53 +0000427 if (command.GetArgumentCount() > 0)
428 {
429 VariableList regex_var_list;
430
431 // If we have any args to the variable command, we will make
432 // variable objects from them...
433 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
434 {
435 if (m_option_variable.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000436 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000437 const uint32_t regex_start_index = regex_var_list.GetSize();
438 RegularExpression regex (name_cstr);
439 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000440 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000441 size_t num_matches = 0;
442 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
443 regex_var_list,
444 num_matches);
445 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000446 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000447 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
448 regex_idx < end_index;
449 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000450 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000451 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
452 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000453 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000454 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
Johnny Chen649d3f12011-09-12 23:58:53 +0000455 if (valobj_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000456 {
Greg Claytonccf44502012-01-26 21:08:30 +0000457// if (format != eFormatDefault)
458// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000459
460 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
461 {
462 bool show_fullpaths = false;
463 bool show_module = true;
464 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
465 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000466 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000467 if (summary_format_sp)
468 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
469 ValueObject::DumpValueObject (result.GetOutputStream(),
470 valobj_sp.get(),
Greg Claytonccf44502012-01-26 21:08:30 +0000471 options,
472 format);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000473 }
474 }
475 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000476 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000477 else if (num_matches == 0)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000478 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000479 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000480 }
481 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000482 else
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000483 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000484 char regex_error[1024];
485 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
486 result.GetErrorStream().Printf ("error: %s\n", regex_error);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000487 else
Johnny Chen649d3f12011-09-12 23:58:53 +0000488 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
489 }
490 }
491 else // No regex, either exact variable names or variable expressions.
492 {
493 Error error;
494 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
495 lldb::VariableSP var_sp;
Greg Clayton567e7f32011-09-22 04:58:26 +0000496 valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr,
497 m_varobj_options.use_dynamic,
498 expr_path_options,
499 var_sp,
500 error);
Johnny Chen649d3f12011-09-12 23:58:53 +0000501 if (valobj_sp)
502 {
Greg Claytonccf44502012-01-26 21:08:30 +0000503// if (format != eFormatDefault)
504// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000505 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000506 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000507 var_sp->GetDeclaration ().DumpStopContext (&s, false);
508 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000509 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000510 if (summary_format_sp)
511 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
512
513 Stream &output_stream = result.GetOutputStream();
514 ValueObject::DumpValueObject (output_stream,
515 valobj_sp.get(),
516 valobj_sp->GetParent() ? name_cstr : NULL,
Greg Claytonccf44502012-01-26 21:08:30 +0000517 options,
518 format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000519 }
520 else
521 {
522 const char *error_cstr = error.AsCString(NULL);
523 if (error_cstr)
524 result.GetErrorStream().Printf("error: %s\n", error_cstr);
525 else
526 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000527 }
Jim Ingham537926c2010-09-02 00:18:39 +0000528 }
529 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000530 }
531 else // No command arg specified. Use variable_list, instead.
532 {
533 const uint32_t num_variables = variable_list->GetSize();
534 if (num_variables > 0)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000535 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000536 for (uint32_t i=0; i<num_variables; i++)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000537 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000538 var_sp = variable_list->GetVariableAtIndex(i);
539 bool dump_variable = true;
540 switch (var_sp->GetScope())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000541 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000542 case eValueTypeVariableGlobal:
Greg Clayton368f8222011-07-07 04:38:25 +0000543 dump_variable = m_option_variable.show_globals;
544 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000545 s.PutCString("GLOBAL: ");
546 break;
547
548 case eValueTypeVariableStatic:
Greg Clayton368f8222011-07-07 04:38:25 +0000549 dump_variable = m_option_variable.show_globals;
550 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000551 s.PutCString("STATIC: ");
552 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000553
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000554 case eValueTypeVariableArgument:
Greg Clayton368f8222011-07-07 04:38:25 +0000555 dump_variable = m_option_variable.show_args;
556 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000557 s.PutCString(" ARG: ");
558 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000559
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000560 case eValueTypeVariableLocal:
Greg Clayton368f8222011-07-07 04:38:25 +0000561 dump_variable = m_option_variable.show_locals;
562 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000563 s.PutCString(" LOCAL: ");
564 break;
565
566 default:
567 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000568 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000569
Johnny Chen649d3f12011-09-12 23:58:53 +0000570 if (dump_variable)
571 {
572 // Use the variable object code to make sure we are
573 // using the same APIs as the the public API will be
574 // using...
Greg Clayton567e7f32011-09-22 04:58:26 +0000575 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp,
576 m_varobj_options.use_dynamic);
Johnny Chen649d3f12011-09-12 23:58:53 +0000577 if (valobj_sp)
578 {
Greg Claytonccf44502012-01-26 21:08:30 +0000579// if (format != eFormatDefault)
580// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000581
582 // When dumping all variables, don't print any variables
583 // that are not in scope to avoid extra unneeded output
584 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000585 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000586 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000587 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000588 var_sp->GetDeclaration ().DumpStopContext (&s, false);
589 s.PutCString (": ");
Greg Claytona357ecf2010-09-14 03:16:58 +0000590 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000591 if (summary_format_sp)
592 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
593 ValueObject::DumpValueObject (result.GetOutputStream(),
594 valobj_sp.get(),
595 name_cstr,
Greg Claytonccf44502012-01-26 21:08:30 +0000596 options,
597 format);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000598 }
599 }
600 }
601 }
602 }
Jim Ingham537926c2010-09-02 00:18:39 +0000603 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000604 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000605 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000606
607 if (m_interpreter.TruncationWarningNecessary())
608 {
609 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
610 m_cmd_name.c_str());
611 m_interpreter.TruncationWarningGiven();
612 }
613
Jim Ingham537926c2010-09-02 00:18:39 +0000614 return result.Succeeded();
615 }
616protected:
617
Jim Ingham10de7d12011-05-04 03:43:18 +0000618 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000619 OptionGroupVariable m_option_variable;
Greg Claytona42880a2011-10-25 06:44:01 +0000620 OptionGroupFormat m_option_format;
Jim Ingham10de7d12011-05-04 03:43:18 +0000621 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham537926c2010-09-02 00:18:39 +0000622};
623
Jim Ingham10de7d12011-05-04 03:43:18 +0000624
Chris Lattner24943d22010-06-08 16:52:24 +0000625#pragma mark CommandObjectMultiwordFrame
626
627//-------------------------------------------------------------------------
628// CommandObjectMultiwordFrame
629//-------------------------------------------------------------------------
630
Greg Clayton63094e02010-06-23 01:19:29 +0000631CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000632 CommandObjectMultiword (interpreter,
633 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000634 "A set of commands for operating on the current thread's frames.",
635 "frame <subcommand> [<subcommand-options>]")
636{
Greg Clayton238c0a12010-09-18 01:14:36 +0000637 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
638 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
639 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000640}
641
642CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
643{
644}
645