blob: ccbd974415c81abe63ad9c8df059483d45e431eb [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
Jim Inghamda26bd22012-06-08 21:56:10 +000055class CommandObjectFrameInfo : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +000056{
57public:
58
Greg Clayton238c0a12010-09-18 01:14:36 +000059 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +000060 CommandObjectParsed (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
Jim Inghamda26bd22012-06-08 21:56:10 +000072protected:
Chris Lattner24943d22010-06-08 16:52:24 +000073 bool
Jim Inghamda26bd22012-06-08 21:56:10 +000074 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000075 CommandReturnObject &result)
76 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000077 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +000078 StackFrame *frame = exe_ctx.GetFramePtr();
79 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +000080 {
Greg Clayton567e7f32011-09-22 04:58:26 +000081 frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000082 result.SetStatus (eReturnStatusSuccessFinishResult);
83 }
84 else
85 {
86 result.AppendError ("no current frame");
87 result.SetStatus (eReturnStatusFailed);
88 }
89 return result.Succeeded();
90 }
91};
92
93#pragma mark CommandObjectFrameSelect
94
95//-------------------------------------------------------------------------
96// CommandObjectFrameSelect
97//-------------------------------------------------------------------------
98
Jim Inghamda26bd22012-06-08 21:56:10 +000099class CommandObjectFrameSelect : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000100{
101public:
102
Greg Claytonc12b6b42010-10-10 22:28:11 +0000103 class CommandOptions : public Options
104 {
105 public:
106
Greg Claytonf15996e2011-04-07 22:46:35 +0000107 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000108 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000109 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000110 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000111 }
112
113 virtual
114 ~CommandOptions ()
115 {
116 }
117
118 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000119 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000120 {
121 Error error;
122 bool success = false;
123 char short_option = (char) m_getopt_table[option_idx].val;
124 switch (short_option)
125 {
126 case 'r':
127 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
128 if (!success)
Greg Clayton9c236732011-10-26 00:56:27 +0000129 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'", option_arg);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000130 break;
131
132 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000133 error.SetErrorStringWithFormat ("invalid short option character '%c'", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000134 break;
135 }
136
137 return error;
138 }
139
140 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000141 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000142 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000143 relative_frame_offset = INT32_MIN;
144 }
145
Greg Claytonb3448432011-03-24 21:19:54 +0000146 const OptionDefinition*
Greg Claytonc12b6b42010-10-10 22:28:11 +0000147 GetDefinitions ()
148 {
149 return g_option_table;
150 }
151
152 // Options table: Required for subclasses of Options.
153
Greg Claytonb3448432011-03-24 21:19:54 +0000154 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000155 int32_t relative_frame_offset;
156 };
157
Greg Clayton238c0a12010-09-18 01:14:36 +0000158 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000159 CommandObjectParsed (interpreter,
160 "frame select",
161 "Select a frame by index from within the current thread and make it the current frame.",
162 NULL,
163 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Greg Claytonf15996e2011-04-07 22:46:35 +0000164 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000165 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000166 CommandArgumentEntry arg;
167 CommandArgumentData index_arg;
168
169 // Define the first (and only) variant of this arg.
170 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000171 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000172
173 // There is only one variant this argument could be; put it into the argument entry.
174 arg.push_back (index_arg);
175
176 // Push the data for the first argument into the m_arguments vector.
177 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000178 }
179
180 ~CommandObjectFrameSelect ()
181 {
182 }
183
Greg Claytonc12b6b42010-10-10 22:28:11 +0000184 virtual
185 Options *
186 GetOptions ()
187 {
188 return &m_options;
189 }
190
191
Jim Inghamda26bd22012-06-08 21:56:10 +0000192protected:
Chris Lattner24943d22010-06-08 16:52:24 +0000193 bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000194 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000195 CommandReturnObject &result)
196 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000197 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000198 Thread *thread = exe_ctx.GetThreadPtr();
199 if (thread)
Chris Lattner24943d22010-06-08 16:52:24 +0000200 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000201 uint32_t frame_idx = UINT32_MAX;
202 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000203 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000204 // The one and only argument is a signed relative frame index
Greg Clayton567e7f32011-09-22 04:58:26 +0000205 frame_idx = thread->GetSelectedFrameIndex ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000206 if (frame_idx == UINT32_MAX)
207 frame_idx = 0;
208
209 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000210 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000211 if (frame_idx >= -m_options.relative_frame_offset)
212 frame_idx += m_options.relative_frame_offset;
213 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000214 {
215 if (frame_idx == 0)
216 {
217 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
218 result.AppendError("Already at the bottom of the stack");
219 result.SetStatus(eReturnStatusFailed);
220 return false;
221 }
222 else
223 frame_idx = 0;
224 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000225 }
226 else if (m_options.relative_frame_offset > 0)
227 {
Jim Inghambf97d742012-02-29 03:40:22 +0000228 // I don't want "up 20" where "20" takes you past the top of the stack to produce
229 // an error, but rather to just go to the top. So I have to count the stack here...
230 const uint32_t num_frames = thread->GetStackFrameCount();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000231 if (num_frames - frame_idx > m_options.relative_frame_offset)
232 frame_idx += m_options.relative_frame_offset;
233 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000234 {
235 if (frame_idx == num_frames - 1)
236 {
237 //If we are already at the top of the stack, just warn and don't reset the frame.
238 result.AppendError("Already at the top of the stack");
239 result.SetStatus(eReturnStatusFailed);
240 return false;
241 }
242 else
243 frame_idx = num_frames - 1;
244 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000245 }
246 }
247 else
248 {
249 if (command.GetArgumentCount() == 1)
250 {
251 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
252 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
253 }
Jason Molenda7685ccc2011-09-30 23:12:14 +0000254 else if (command.GetArgumentCount() == 0)
Jason Molenda811ded52011-09-29 23:02:41 +0000255 {
256 frame_idx = thread->GetSelectedFrameIndex ();
257 if (frame_idx == UINT32_MAX)
Jason Molenda7685ccc2011-09-30 23:12:14 +0000258 {
Jason Molenda811ded52011-09-29 23:02:41 +0000259 frame_idx = 0;
Jason Molenda7685ccc2011-09-30 23:12:14 +0000260 }
Jason Molenda811ded52011-09-29 23:02:41 +0000261 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000262 else
263 {
264 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000265 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000266 }
267 }
268
Jim Inghambf97d742012-02-29 03:40:22 +0000269 bool success = thread->SetSelectedFrameByIndex (frame_idx);
270 if (success)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000271 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000272 exe_ctx.SetFrameSP(thread->GetSelectedFrame ());
273 StackFrame *frame = exe_ctx.GetFramePtr();
274 if (frame)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000275 {
276 bool already_shown = false;
Greg Clayton567e7f32011-09-22 04:58:26 +0000277 SymbolContext frame_sc(frame->GetSymbolContext(eSymbolContextLineEntry));
Greg Claytonc12b6b42010-10-10 22:28:11 +0000278 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000279 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000280 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
281 }
Jim Ingham74989e82010-08-30 19:44:40 +0000282
Greg Claytonabe0fed2011-04-18 08:33:37 +0000283 bool show_frame_info = true;
284 bool show_source = !already_shown;
Greg Claytona7d3dc72012-07-11 20:33:48 +0000285 if (frame->GetStatus (result.GetOutputStream(), show_frame_info, show_source))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000286 {
287 result.SetStatus (eReturnStatusSuccessFinishResult);
288 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000289 }
290 }
Chris Lattner24943d22010-06-08 16:52:24 +0000291 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000292 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000293 }
294 else
295 {
296 result.AppendError ("no current thread");
297 }
298 result.SetStatus (eReturnStatusFailed);
299 return false;
300 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000301protected:
302
303 CommandOptions m_options;
304};
305
Greg Claytonb3448432011-03-24 21:19:54 +0000306OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000307CommandObjectFrameSelect::CommandOptions::g_option_table[] =
308{
309{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
310{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000311};
312
Jim Ingham537926c2010-09-02 00:18:39 +0000313#pragma mark CommandObjectFrameVariable
314//----------------------------------------------------------------------
315// List images with associated information
316//----------------------------------------------------------------------
Jim Inghamda26bd22012-06-08 21:56:10 +0000317class CommandObjectFrameVariable : public CommandObjectParsed
Jim Ingham537926c2010-09-02 00:18:39 +0000318{
319public:
320
Greg Clayton238c0a12010-09-18 01:14:36 +0000321 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000322 CommandObjectParsed (interpreter,
323 "frame variable",
324 "Show frame variables. All argument and local variables "
325 "that are in scope will be shown when no arguments are given. "
326 "If any arguments are specified, they can be names of "
327 "argument, local, file static and file global variables. "
328 "Children of aggregate variables can be specified such as "
329 "'var->child.x'.",
330 NULL,
331 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Jim Ingham10de7d12011-05-04 03:43:18 +0000332 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000333 m_option_variable(true), // Include the frame specific options by passing "true"
Greg Claytona42880a2011-10-25 06:44:01 +0000334 m_option_format (eFormatDefault),
Jim Ingham10de7d12011-05-04 03:43:18 +0000335 m_varobj_options()
Jim Ingham537926c2010-09-02 00:18:39 +0000336 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000337 CommandArgumentEntry arg;
338 CommandArgumentData var_name_arg;
339
340 // Define the first (and only) variant of this arg.
341 var_name_arg.arg_type = eArgTypeVarName;
342 var_name_arg.arg_repetition = eArgRepeatStar;
343
344 // There is only one variant this argument could be; put it into the argument entry.
345 arg.push_back (var_name_arg);
346
347 // Push the data for the first argument into the m_arguments vector.
348 m_arguments.push_back (arg);
Jim Ingham10de7d12011-05-04 03:43:18 +0000349
Greg Clayton368f8222011-07-07 04:38:25 +0000350 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton24a6bd92011-10-27 17:55:14 +0000351 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 +0000352 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
353 m_option_group.Finalize();
Jim Ingham537926c2010-09-02 00:18:39 +0000354 }
355
356 virtual
357 ~CommandObjectFrameVariable ()
358 {
359 }
360
361 virtual
362 Options *
363 GetOptions ()
364 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000365 return &m_option_group;
Jim Ingham537926c2010-09-02 00:18:39 +0000366 }
367
Jim Inghamda26bd22012-06-08 21:56:10 +0000368protected:
Jim Ingham537926c2010-09-02 00:18:39 +0000369 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000370 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham537926c2010-09-02 00:18:39 +0000371 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000372 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000373 StackFrame *frame = exe_ctx.GetFramePtr();
374 if (frame == NULL)
Jim Ingham537926c2010-09-02 00:18:39 +0000375 {
Greg Claytonaa448052010-09-18 04:06:15 +0000376 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000377 result.SetStatus (eReturnStatusFailed);
378 return false;
379 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000380
381 Stream &s = result.GetOutputStream();
382
383 bool get_file_globals = true;
384
385 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
386 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
387
Greg Clayton567e7f32011-09-22 04:58:26 +0000388 VariableList *variable_list = frame->GetVariableList (get_file_globals);
Johnny Chen649d3f12011-09-12 23:58:53 +0000389
390 VariableSP var_sp;
391 ValueObjectSP valobj_sp;
392
393 const char *name_cstr = NULL;
394 size_t idx;
395
Enrico Granata16376ed2012-02-15 02:34:21 +0000396 TypeSummaryImplSP summary_format_sp;
Enrico Granata879de482012-08-09 22:02:51 +0000397 if (!m_option_variable.summary.IsCurrentValueEmpty())
398 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.GetCurrentValue()), summary_format_sp);
399 else if (!m_option_variable.summary_string.IsCurrentValueEmpty())
400 summary_format_sp.reset(new StringSummaryFormat(TypeSummaryImpl::Flags(),m_option_variable.summary_string.GetCurrentValue()));
Johnny Chen649d3f12011-09-12 23:58:53 +0000401
402 ValueObject::DumpValueObjectOptions options;
403
Enrico Granata3069c622012-03-01 04:24:26 +0000404 options.SetMaximumPointerDepth(m_varobj_options.ptr_depth)
Johnny Chen649d3f12011-09-12 23:58:53 +0000405 .SetMaximumDepth(m_varobj_options.max_depth)
406 .SetShowTypes(m_varobj_options.show_types)
407 .SetShowLocation(m_varobj_options.show_location)
408 .SetUseObjectiveC(m_varobj_options.use_objc)
409 .SetUseDynamicType(m_varobj_options.use_dynamic)
Enrico Granatacf09f882012-03-19 22:58:49 +0000410 .SetUseSyntheticValue(m_varobj_options.use_synth)
Johnny Chen649d3f12011-09-12 23:58:53 +0000411 .SetFlatOutput(m_varobj_options.flat_output)
412 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
Enrico Granata3069c622012-03-01 04:24:26 +0000413 .SetIgnoreCap(m_varobj_options.ignore_cap)
414 .SetSummary(summary_format_sp);
Johnny Chen649d3f12011-09-12 23:58:53 +0000415
416 if (m_varobj_options.be_raw)
417 options.SetRawDisplay(true);
418
419 if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000420 {
Greg Claytona42880a2011-10-25 06:44:01 +0000421 const Format format = m_option_format.GetFormat();
Enrico Granata3069c622012-03-01 04:24:26 +0000422 options.SetFormat(format);
Greg Claytona42880a2011-10-25 06:44:01 +0000423
Johnny Chen649d3f12011-09-12 23:58:53 +0000424 if (command.GetArgumentCount() > 0)
425 {
426 VariableList regex_var_list;
427
428 // If we have any args to the variable command, we will make
429 // variable objects from them...
430 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
431 {
432 if (m_option_variable.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000433 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000434 const uint32_t regex_start_index = regex_var_list.GetSize();
435 RegularExpression regex (name_cstr);
436 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000437 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000438 size_t num_matches = 0;
439 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
440 regex_var_list,
441 num_matches);
442 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000443 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000444 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
445 regex_idx < end_index;
446 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000447 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000448 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
449 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000450 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000451 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
Johnny Chen649d3f12011-09-12 23:58:53 +0000452 if (valobj_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000453 {
Greg Claytonccf44502012-01-26 21:08:30 +0000454// if (format != eFormatDefault)
455// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000456
457 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
458 {
459 bool show_fullpaths = false;
460 bool show_module = true;
461 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
462 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000463 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000464 ValueObject::DumpValueObject (result.GetOutputStream(),
465 valobj_sp.get(),
Enrico Granata3069c622012-03-01 04:24:26 +0000466 options);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000467 }
468 }
469 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000470 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000471 else if (num_matches == 0)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000472 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000473 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000474 }
475 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000476 else
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000477 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000478 char regex_error[1024];
479 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
480 result.GetErrorStream().Printf ("error: %s\n", regex_error);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000481 else
Johnny Chen649d3f12011-09-12 23:58:53 +0000482 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
483 }
484 }
485 else // No regex, either exact variable names or variable expressions.
486 {
487 Error error;
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000488 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
489 StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
Johnny Chen649d3f12011-09-12 23:58:53 +0000490 lldb::VariableSP var_sp;
Greg Clayton567e7f32011-09-22 04:58:26 +0000491 valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr,
492 m_varobj_options.use_dynamic,
493 expr_path_options,
494 var_sp,
495 error);
Johnny Chen649d3f12011-09-12 23:58:53 +0000496 if (valobj_sp)
497 {
Greg Claytonccf44502012-01-26 21:08:30 +0000498// if (format != eFormatDefault)
499// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000500 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000501 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000502 var_sp->GetDeclaration ().DumpStopContext (&s, false);
503 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000504 }
Enrico Granata3069c622012-03-01 04:24:26 +0000505
506 options.SetFormat(format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000507
508 Stream &output_stream = result.GetOutputStream();
Enrico Granata3069c622012-03-01 04:24:26 +0000509 options.SetRootValueObjectName(valobj_sp->GetParent() ? name_cstr : NULL);
Johnny Chen649d3f12011-09-12 23:58:53 +0000510 ValueObject::DumpValueObject (output_stream,
511 valobj_sp.get(),
Enrico Granata3069c622012-03-01 04:24:26 +0000512 options);
Johnny Chen649d3f12011-09-12 23:58:53 +0000513 }
514 else
515 {
516 const char *error_cstr = error.AsCString(NULL);
517 if (error_cstr)
518 result.GetErrorStream().Printf("error: %s\n", error_cstr);
519 else
520 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000521 }
Jim Ingham537926c2010-09-02 00:18:39 +0000522 }
523 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000524 }
525 else // No command arg specified. Use variable_list, instead.
526 {
527 const uint32_t num_variables = variable_list->GetSize();
528 if (num_variables > 0)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000529 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000530 for (uint32_t i=0; i<num_variables; i++)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000531 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000532 var_sp = variable_list->GetVariableAtIndex(i);
533 bool dump_variable = true;
534 switch (var_sp->GetScope())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000535 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000536 case eValueTypeVariableGlobal:
Greg Clayton368f8222011-07-07 04:38:25 +0000537 dump_variable = m_option_variable.show_globals;
538 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000539 s.PutCString("GLOBAL: ");
540 break;
541
542 case eValueTypeVariableStatic:
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("STATIC: ");
546 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000547
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000548 case eValueTypeVariableArgument:
Greg Clayton368f8222011-07-07 04:38:25 +0000549 dump_variable = m_option_variable.show_args;
550 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000551 s.PutCString(" ARG: ");
552 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000553
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000554 case eValueTypeVariableLocal:
Greg Clayton368f8222011-07-07 04:38:25 +0000555 dump_variable = m_option_variable.show_locals;
556 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000557 s.PutCString(" LOCAL: ");
558 break;
559
560 default:
561 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000562 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000563
Johnny Chen649d3f12011-09-12 23:58:53 +0000564 if (dump_variable)
565 {
566 // Use the variable object code to make sure we are
567 // using the same APIs as the the public API will be
568 // using...
Greg Clayton567e7f32011-09-22 04:58:26 +0000569 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp,
570 m_varobj_options.use_dynamic);
Johnny Chen649d3f12011-09-12 23:58:53 +0000571 if (valobj_sp)
572 {
Greg Claytonccf44502012-01-26 21:08:30 +0000573// if (format != eFormatDefault)
574// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000575
576 // When dumping all variables, don't print any variables
577 // that are not in scope to avoid extra unneeded output
578 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000579 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000580 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000581 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000582 var_sp->GetDeclaration ().DumpStopContext (&s, false);
583 s.PutCString (": ");
Greg Claytona357ecf2010-09-14 03:16:58 +0000584 }
Enrico Granata3069c622012-03-01 04:24:26 +0000585
586 options.SetFormat(format);
587 options.SetRootValueObjectName(name_cstr);
Johnny Chen649d3f12011-09-12 23:58:53 +0000588 ValueObject::DumpValueObject (result.GetOutputStream(),
589 valobj_sp.get(),
Enrico Granata3069c622012-03-01 04:24:26 +0000590 options);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000591 }
592 }
593 }
594 }
595 }
Jim Ingham537926c2010-09-02 00:18:39 +0000596 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000597 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000598 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000599
600 if (m_interpreter.TruncationWarningNecessary())
601 {
602 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
603 m_cmd_name.c_str());
604 m_interpreter.TruncationWarningGiven();
605 }
606
Jim Ingham537926c2010-09-02 00:18:39 +0000607 return result.Succeeded();
608 }
609protected:
610
Jim Ingham10de7d12011-05-04 03:43:18 +0000611 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000612 OptionGroupVariable m_option_variable;
Greg Claytona42880a2011-10-25 06:44:01 +0000613 OptionGroupFormat m_option_format;
Jim Ingham10de7d12011-05-04 03:43:18 +0000614 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham537926c2010-09-02 00:18:39 +0000615};
616
Jim Ingham10de7d12011-05-04 03:43:18 +0000617
Chris Lattner24943d22010-06-08 16:52:24 +0000618#pragma mark CommandObjectMultiwordFrame
619
620//-------------------------------------------------------------------------
621// CommandObjectMultiwordFrame
622//-------------------------------------------------------------------------
623
Greg Clayton63094e02010-06-23 01:19:29 +0000624CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000625 CommandObjectMultiword (interpreter,
626 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000627 "A set of commands for operating on the current thread's frames.",
628 "frame <subcommand> [<subcommand-options>]")
629{
Greg Clayton238c0a12010-09-18 01:14:36 +0000630 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
631 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
632 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000633}
634
635CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
636{
637}
638