blob: 6a5c1325e249339f755cc1ec7400777a6fc12189 [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
Daniel Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "CommandObjectFrame.h"
13
14// C Includes
15// C++ Includes
Johnny Chen10b12b32011-09-16 21:41:42 +000016#include <string>
Chris Lattner24943d22010-06-08 16:52:24 +000017// Other libraries and framework includes
18// Project includes
Enrico Granata0be2e9b2011-08-22 22:03:47 +000019#include "lldb/Core/DataVisualization.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Core/Debugger.h"
Jim Ingham537926c2010-09-02 00:18:39 +000021#include "lldb/Core/Module.h"
22#include "lldb/Core/StreamFile.h"
Johnny Chen10b12b32011-09-16 21:41:42 +000023#include "lldb/Core/StreamString.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Core/Timer.h"
Jim Ingham537926c2010-09-02 00:18:39 +000025#include "lldb/Core/Value.h"
26#include "lldb/Core/ValueObject.h"
27#include "lldb/Core/ValueObjectVariable.h"
Greg Claytoncd548032011-02-01 01:31:41 +000028#include "lldb/Host/Host.h"
Jim Ingham537926c2010-09-02 00:18:39 +000029#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Interpreter/CommandInterpreter.h"
31#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham537926c2010-09-02 00:18:39 +000032#include "lldb/Interpreter/Options.h"
Greg Claytona42880a2011-10-25 06:44:01 +000033#include "lldb/Interpreter/OptionGroupFormat.h"
Jim Ingham10de7d12011-05-04 03:43:18 +000034#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton368f8222011-07-07 04:38:25 +000035#include "lldb/Interpreter/OptionGroupVariable.h"
Jim Ingham537926c2010-09-02 00:18:39 +000036#include "lldb/Symbol/ClangASTType.h"
37#include "lldb/Symbol/ClangASTContext.h"
38#include "lldb/Symbol/ObjectFile.h"
39#include "lldb/Symbol/SymbolContext.h"
40#include "lldb/Symbol/Type.h"
41#include "lldb/Symbol/Variable.h"
42#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000043#include "lldb/Target/Process.h"
44#include "lldb/Target/StackFrame.h"
45#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000046#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000047
Chris Lattner24943d22010-06-08 16:52:24 +000048using namespace lldb;
49using namespace lldb_private;
50
51#pragma mark CommandObjectFrameInfo
52
53//-------------------------------------------------------------------------
54// CommandObjectFrameInfo
55//-------------------------------------------------------------------------
56
Jim Inghamda26bd22012-06-08 21:56:10 +000057class CommandObjectFrameInfo : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +000058{
59public:
60
Greg Clayton238c0a12010-09-18 01:14:36 +000061 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +000062 CommandObjectParsed (interpreter,
63 "frame info",
64 "List information about the currently selected frame in the current thread.",
65 "frame info",
66 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000067 {
68 }
69
70 ~CommandObjectFrameInfo ()
71 {
72 }
73
Jim Inghamda26bd22012-06-08 21:56:10 +000074protected:
Chris Lattner24943d22010-06-08 16:52:24 +000075 bool
Jim Inghamda26bd22012-06-08 21:56:10 +000076 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000077 CommandReturnObject &result)
78 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000079 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +000080 StackFrame *frame = exe_ctx.GetFramePtr();
81 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +000082 {
Greg Clayton567e7f32011-09-22 04:58:26 +000083 frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000084 result.SetStatus (eReturnStatusSuccessFinishResult);
85 }
86 else
87 {
88 result.AppendError ("no current frame");
89 result.SetStatus (eReturnStatusFailed);
90 }
91 return result.Succeeded();
92 }
93};
94
95#pragma mark CommandObjectFrameSelect
96
97//-------------------------------------------------------------------------
98// CommandObjectFrameSelect
99//-------------------------------------------------------------------------
100
Jim Inghamda26bd22012-06-08 21:56:10 +0000101class CommandObjectFrameSelect : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000102{
103public:
104
Greg Claytonc12b6b42010-10-10 22:28:11 +0000105 class CommandOptions : public Options
106 {
107 public:
108
Greg Claytonf15996e2011-04-07 22:46:35 +0000109 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000110 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000111 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000112 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000113 }
114
115 virtual
116 ~CommandOptions ()
117 {
118 }
119
120 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000121 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000122 {
123 Error error;
124 bool success = false;
Greg Clayton6475c422012-12-04 00:32:51 +0000125 const int short_option = m_getopt_table[option_idx].val;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000126 switch (short_option)
127 {
128 case 'r':
129 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
130 if (!success)
Greg Clayton9c236732011-10-26 00:56:27 +0000131 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'", option_arg);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000132 break;
133
134 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000135 error.SetErrorStringWithFormat ("invalid short option character '%c'", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000136 break;
137 }
138
139 return error;
140 }
141
142 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000143 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000144 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000145 relative_frame_offset = INT32_MIN;
146 }
147
Greg Claytonb3448432011-03-24 21:19:54 +0000148 const OptionDefinition*
Greg Claytonc12b6b42010-10-10 22:28:11 +0000149 GetDefinitions ()
150 {
151 return g_option_table;
152 }
153
154 // Options table: Required for subclasses of Options.
155
Greg Claytonb3448432011-03-24 21:19:54 +0000156 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000157 int32_t relative_frame_offset;
158 };
159
Greg Clayton238c0a12010-09-18 01:14:36 +0000160 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000161 CommandObjectParsed (interpreter,
162 "frame select",
163 "Select a frame by index from within the current thread and make it the current frame.",
164 NULL,
165 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Greg Claytonf15996e2011-04-07 22:46:35 +0000166 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000167 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000168 CommandArgumentEntry arg;
169 CommandArgumentData index_arg;
170
171 // Define the first (and only) variant of this arg.
172 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000173 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000174
175 // There is only one variant this argument could be; put it into the argument entry.
176 arg.push_back (index_arg);
177
178 // Push the data for the first argument into the m_arguments vector.
179 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000180 }
181
182 ~CommandObjectFrameSelect ()
183 {
184 }
185
Greg Claytonc12b6b42010-10-10 22:28:11 +0000186 virtual
187 Options *
188 GetOptions ()
189 {
190 return &m_options;
191 }
192
193
Jim Inghamda26bd22012-06-08 21:56:10 +0000194protected:
Chris Lattner24943d22010-06-08 16:52:24 +0000195 bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000196 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000197 CommandReturnObject &result)
198 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000199 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000200 Thread *thread = exe_ctx.GetThreadPtr();
201 if (thread)
Chris Lattner24943d22010-06-08 16:52:24 +0000202 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000203 uint32_t frame_idx = UINT32_MAX;
204 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000205 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000206 // The one and only argument is a signed relative frame index
Greg Clayton567e7f32011-09-22 04:58:26 +0000207 frame_idx = thread->GetSelectedFrameIndex ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000208 if (frame_idx == UINT32_MAX)
209 frame_idx = 0;
210
211 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000212 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000213 if (frame_idx >= -m_options.relative_frame_offset)
214 frame_idx += m_options.relative_frame_offset;
215 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000216 {
217 if (frame_idx == 0)
218 {
219 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
220 result.AppendError("Already at the bottom of the stack");
221 result.SetStatus(eReturnStatusFailed);
222 return false;
223 }
224 else
225 frame_idx = 0;
226 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000227 }
228 else if (m_options.relative_frame_offset > 0)
229 {
Jim Inghambf97d742012-02-29 03:40:22 +0000230 // I don't want "up 20" where "20" takes you past the top of the stack to produce
231 // an error, but rather to just go to the top. So I have to count the stack here...
232 const uint32_t num_frames = thread->GetStackFrameCount();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000233 if (num_frames - frame_idx > m_options.relative_frame_offset)
234 frame_idx += m_options.relative_frame_offset;
235 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000236 {
237 if (frame_idx == num_frames - 1)
238 {
239 //If we are already at the top of the stack, just warn and don't reset the frame.
240 result.AppendError("Already at the top of the stack");
241 result.SetStatus(eReturnStatusFailed);
242 return false;
243 }
244 else
245 frame_idx = num_frames - 1;
246 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000247 }
248 }
249 else
250 {
251 if (command.GetArgumentCount() == 1)
252 {
253 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
254 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
255 }
Jason Molenda7685ccc2011-09-30 23:12:14 +0000256 else if (command.GetArgumentCount() == 0)
Jason Molenda811ded52011-09-29 23:02:41 +0000257 {
258 frame_idx = thread->GetSelectedFrameIndex ();
259 if (frame_idx == UINT32_MAX)
Jason Molenda7685ccc2011-09-30 23:12:14 +0000260 {
Jason Molenda811ded52011-09-29 23:02:41 +0000261 frame_idx = 0;
Jason Molenda7685ccc2011-09-30 23:12:14 +0000262 }
Jason Molenda811ded52011-09-29 23:02:41 +0000263 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000264 else
265 {
266 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000267 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000268 }
269 }
Jim Ingham94a5d0d2012-10-10 18:32:14 +0000270
271 const bool broadcast = true;
272 bool success = thread->SetSelectedFrameByIndex (frame_idx, broadcast);
Jim Inghambf97d742012-02-29 03:40:22 +0000273 if (success)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000274 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000275 exe_ctx.SetFrameSP(thread->GetSelectedFrame ());
276 StackFrame *frame = exe_ctx.GetFramePtr();
277 if (frame)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000278 {
279 bool already_shown = false;
Greg Clayton567e7f32011-09-22 04:58:26 +0000280 SymbolContext frame_sc(frame->GetSymbolContext(eSymbolContextLineEntry));
Greg Claytonc12b6b42010-10-10 22:28:11 +0000281 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000282 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000283 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
284 }
Jim Ingham74989e82010-08-30 19:44:40 +0000285
Greg Claytonabe0fed2011-04-18 08:33:37 +0000286 bool show_frame_info = true;
287 bool show_source = !already_shown;
Greg Claytona7d3dc72012-07-11 20:33:48 +0000288 if (frame->GetStatus (result.GetOutputStream(), show_frame_info, show_source))
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."},
Filipe Cabecinhas560c5142012-09-11 16:09:27 +0000313{ 0, false, NULL, 0, 0, NULL, 0, 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//----------------------------------------------------------------------
Jim Inghamda26bd22012-06-08 21:56:10 +0000320class CommandObjectFrameVariable : public CommandObjectParsed
Jim Ingham537926c2010-09-02 00:18:39 +0000321{
322public:
323
Greg Clayton238c0a12010-09-18 01:14:36 +0000324 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000325 CommandObjectParsed (interpreter,
326 "frame variable",
327 "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 "
330 "argument, local, file static and file global variables. "
331 "Children of aggregate variables can be specified such as "
332 "'var->child.x'.",
333 NULL,
334 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 Inghamda26bd22012-06-08 21:56:10 +0000371protected:
Jim Ingham537926c2010-09-02 00:18:39 +0000372 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000373 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham537926c2010-09-02 00:18:39 +0000374 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000375 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000376 StackFrame *frame = exe_ctx.GetFramePtr();
377 if (frame == NULL)
Jim Ingham537926c2010-09-02 00:18:39 +0000378 {
Greg Claytonaa448052010-09-18 04:06:15 +0000379 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000380 result.SetStatus (eReturnStatusFailed);
381 return false;
382 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000383
384 Stream &s = result.GetOutputStream();
385
386 bool get_file_globals = true;
387
388 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
389 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
390
Greg Clayton567e7f32011-09-22 04:58:26 +0000391 VariableList *variable_list = frame->GetVariableList (get_file_globals);
Johnny Chen649d3f12011-09-12 23:58:53 +0000392
393 VariableSP var_sp;
394 ValueObjectSP valobj_sp;
395
396 const char *name_cstr = NULL;
397 size_t idx;
398
Enrico Granata16376ed2012-02-15 02:34:21 +0000399 TypeSummaryImplSP summary_format_sp;
Enrico Granata879de482012-08-09 22:02:51 +0000400 if (!m_option_variable.summary.IsCurrentValueEmpty())
401 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.GetCurrentValue()), summary_format_sp);
402 else if (!m_option_variable.summary_string.IsCurrentValueEmpty())
403 summary_format_sp.reset(new StringSummaryFormat(TypeSummaryImpl::Flags(),m_option_variable.summary_string.GetCurrentValue()));
Johnny Chen649d3f12011-09-12 23:58:53 +0000404
405 ValueObject::DumpValueObjectOptions options;
406
Enrico Granata3069c622012-03-01 04:24:26 +0000407 options.SetMaximumPointerDepth(m_varobj_options.ptr_depth)
Johnny Chen649d3f12011-09-12 23:58:53 +0000408 .SetMaximumDepth(m_varobj_options.max_depth)
409 .SetShowTypes(m_varobj_options.show_types)
410 .SetShowLocation(m_varobj_options.show_location)
411 .SetUseObjectiveC(m_varobj_options.use_objc)
412 .SetUseDynamicType(m_varobj_options.use_dynamic)
Enrico Granatacf09f882012-03-19 22:58:49 +0000413 .SetUseSyntheticValue(m_varobj_options.use_synth)
Johnny Chen649d3f12011-09-12 23:58:53 +0000414 .SetFlatOutput(m_varobj_options.flat_output)
415 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
Enrico Granata3069c622012-03-01 04:24:26 +0000416 .SetIgnoreCap(m_varobj_options.ignore_cap)
417 .SetSummary(summary_format_sp);
Johnny Chen649d3f12011-09-12 23:58:53 +0000418
419 if (m_varobj_options.be_raw)
420 options.SetRawDisplay(true);
421
422 if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000423 {
Greg Claytona42880a2011-10-25 06:44:01 +0000424 const Format format = m_option_format.GetFormat();
Enrico Granata3069c622012-03-01 04:24:26 +0000425 options.SetFormat(format);
Greg Claytona42880a2011-10-25 06:44:01 +0000426
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 ValueObject::DumpValueObject (result.GetOutputStream(),
468 valobj_sp.get(),
Enrico Granata3069c622012-03-01 04:24:26 +0000469 options);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000470 }
471 }
472 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000473 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000474 else if (num_matches == 0)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000475 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000476 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000477 }
478 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000479 else
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000480 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000481 char regex_error[1024];
482 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
483 result.GetErrorStream().Printf ("error: %s\n", regex_error);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000484 else
Johnny Chen649d3f12011-09-12 23:58:53 +0000485 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
486 }
487 }
488 else // No regex, either exact variable names or variable expressions.
489 {
490 Error error;
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000491 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
492 StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
Johnny Chen649d3f12011-09-12 23:58:53 +0000493 lldb::VariableSP var_sp;
Greg Clayton567e7f32011-09-22 04:58:26 +0000494 valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr,
495 m_varobj_options.use_dynamic,
496 expr_path_options,
497 var_sp,
498 error);
Johnny Chen649d3f12011-09-12 23:58:53 +0000499 if (valobj_sp)
500 {
Greg Claytonccf44502012-01-26 21:08:30 +0000501// if (format != eFormatDefault)
502// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000503 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000504 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000505 var_sp->GetDeclaration ().DumpStopContext (&s, false);
506 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000507 }
Enrico Granata3069c622012-03-01 04:24:26 +0000508
509 options.SetFormat(format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000510
511 Stream &output_stream = result.GetOutputStream();
Enrico Granata3069c622012-03-01 04:24:26 +0000512 options.SetRootValueObjectName(valobj_sp->GetParent() ? name_cstr : NULL);
Johnny Chen649d3f12011-09-12 23:58:53 +0000513 ValueObject::DumpValueObject (output_stream,
514 valobj_sp.get(),
Enrico Granata3069c622012-03-01 04:24:26 +0000515 options);
Johnny Chen649d3f12011-09-12 23:58:53 +0000516 }
517 else
518 {
519 const char *error_cstr = error.AsCString(NULL);
520 if (error_cstr)
521 result.GetErrorStream().Printf("error: %s\n", error_cstr);
522 else
523 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000524 }
Jim Ingham537926c2010-09-02 00:18:39 +0000525 }
526 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000527 }
528 else // No command arg specified. Use variable_list, instead.
529 {
530 const uint32_t num_variables = variable_list->GetSize();
531 if (num_variables > 0)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000532 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000533 for (uint32_t i=0; i<num_variables; i++)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000534 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000535 var_sp = variable_list->GetVariableAtIndex(i);
536 bool dump_variable = true;
537 switch (var_sp->GetScope())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000538 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000539 case eValueTypeVariableGlobal:
Greg Clayton368f8222011-07-07 04:38:25 +0000540 dump_variable = m_option_variable.show_globals;
541 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000542 s.PutCString("GLOBAL: ");
543 break;
544
545 case eValueTypeVariableStatic:
Greg Clayton368f8222011-07-07 04:38:25 +0000546 dump_variable = m_option_variable.show_globals;
547 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000548 s.PutCString("STATIC: ");
549 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000550
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000551 case eValueTypeVariableArgument:
Greg Clayton368f8222011-07-07 04:38:25 +0000552 dump_variable = m_option_variable.show_args;
553 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000554 s.PutCString(" ARG: ");
555 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000556
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000557 case eValueTypeVariableLocal:
Greg Clayton368f8222011-07-07 04:38:25 +0000558 dump_variable = m_option_variable.show_locals;
559 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000560 s.PutCString(" LOCAL: ");
561 break;
562
563 default:
564 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000565 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000566
Johnny Chen649d3f12011-09-12 23:58:53 +0000567 if (dump_variable)
568 {
569 // Use the variable object code to make sure we are
570 // using the same APIs as the the public API will be
571 // using...
Greg Clayton567e7f32011-09-22 04:58:26 +0000572 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp,
573 m_varobj_options.use_dynamic);
Johnny Chen649d3f12011-09-12 23:58:53 +0000574 if (valobj_sp)
575 {
Greg Claytonccf44502012-01-26 21:08:30 +0000576// if (format != eFormatDefault)
577// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000578
579 // When dumping all variables, don't print any variables
580 // that are not in scope to avoid extra unneeded output
581 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000582 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000583 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000584 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000585 var_sp->GetDeclaration ().DumpStopContext (&s, false);
586 s.PutCString (": ");
Greg Claytona357ecf2010-09-14 03:16:58 +0000587 }
Enrico Granata3069c622012-03-01 04:24:26 +0000588
589 options.SetFormat(format);
590 options.SetRootValueObjectName(name_cstr);
Johnny Chen649d3f12011-09-12 23:58:53 +0000591 ValueObject::DumpValueObject (result.GetOutputStream(),
592 valobj_sp.get(),
Enrico Granata3069c622012-03-01 04:24:26 +0000593 options);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000594 }
595 }
596 }
597 }
598 }
Jim Ingham537926c2010-09-02 00:18:39 +0000599 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000600 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000601 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000602
603 if (m_interpreter.TruncationWarningNecessary())
604 {
605 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
606 m_cmd_name.c_str());
607 m_interpreter.TruncationWarningGiven();
608 }
609
Jim Ingham537926c2010-09-02 00:18:39 +0000610 return result.Succeeded();
611 }
612protected:
613
Jim Ingham10de7d12011-05-04 03:43:18 +0000614 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000615 OptionGroupVariable m_option_variable;
Greg Claytona42880a2011-10-25 06:44:01 +0000616 OptionGroupFormat m_option_format;
Jim Ingham10de7d12011-05-04 03:43:18 +0000617 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham537926c2010-09-02 00:18:39 +0000618};
619
Jim Ingham10de7d12011-05-04 03:43:18 +0000620
Chris Lattner24943d22010-06-08 16:52:24 +0000621#pragma mark CommandObjectMultiwordFrame
622
623//-------------------------------------------------------------------------
624// CommandObjectMultiwordFrame
625//-------------------------------------------------------------------------
626
Greg Clayton63094e02010-06-23 01:19:29 +0000627CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000628 CommandObjectMultiword (interpreter,
629 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000630 "A set of commands for operating on the current thread's frames.",
631 "frame <subcommand> [<subcommand-options>]")
632{
Greg Clayton238c0a12010-09-18 01:14:36 +0000633 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
634 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
635 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000636}
637
638CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
639{
640}
641