blob: 202d62e6009c1c7c3ddc1f30dbc0f119e41e425e [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "CommandObjectFrame.h"
13
14// C Includes
15// C++ Includes
Johnny Chende6bd242011-09-16 21:41:42 +000016#include <string>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// Other libraries and framework includes
18// Project includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/Debugger.h"
Jim Ingham6d56d2c2010-09-02 00:18:39 +000020#include "lldb/Core/Module.h"
21#include "lldb/Core/StreamFile.h"
Johnny Chende6bd242011-09-16 21:41:42 +000022#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/Timer.h"
Jim Ingham6d56d2c2010-09-02 00:18:39 +000024#include "lldb/Core/Value.h"
25#include "lldb/Core/ValueObject.h"
26#include "lldb/Core/ValueObjectVariable.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000027#include "lldb/DataFormatters/DataVisualization.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000028#include "lldb/Host/Host.h"
Jim Ingham6d56d2c2010-09-02 00:18:39 +000029#include "lldb/Interpreter/Args.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Interpreter/CommandInterpreter.h"
31#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham6d56d2c2010-09-02 00:18:39 +000032#include "lldb/Interpreter/Options.h"
Greg Clayton1deb7962011-10-25 06:44:01 +000033#include "lldb/Interpreter/OptionGroupFormat.h"
Jim Ingham2837b762011-05-04 03:43:18 +000034#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton715c2362011-07-07 04:38:25 +000035#include "lldb/Interpreter/OptionGroupVariable.h"
Jim Ingham6d56d2c2010-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 Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Target/Process.h"
44#include "lldb/Target/StackFrame.h"
45#include "lldb/Target/Thread.h"
Jim Ingham6d56d2c2010-09-02 00:18:39 +000046#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048using namespace lldb;
49using namespace lldb_private;
50
51#pragma mark CommandObjectFrameInfo
52
53//-------------------------------------------------------------------------
54// CommandObjectFrameInfo
55//-------------------------------------------------------------------------
56
Jim Ingham5a988412012-06-08 21:56:10 +000057class CommandObjectFrameInfo : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058{
59public:
60
Greg Claytona7015092010-09-18 01:14:36 +000061 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-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",
Greg Claytonf9fc6092013-01-09 19:44:40 +000066 eFlagRequiresFrame |
67 eFlagTryTargetAPILock |
68 eFlagProcessMustBeLaunched |
69 eFlagProcessMustBePaused )
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070 {
71 }
72
73 ~CommandObjectFrameInfo ()
74 {
75 }
76
Jim Ingham5a988412012-06-08 21:56:10 +000077protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078 bool
Greg Claytonf9fc6092013-01-09 19:44:40 +000079 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080 {
Greg Claytonf9fc6092013-01-09 19:44:40 +000081 m_exe_ctx.GetFrameRef().DumpUsingSettingsFormat (&result.GetOutputStream());
82 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083 return result.Succeeded();
84 }
85};
86
87#pragma mark CommandObjectFrameSelect
88
89//-------------------------------------------------------------------------
90// CommandObjectFrameSelect
91//-------------------------------------------------------------------------
92
Jim Ingham5a988412012-06-08 21:56:10 +000093class CommandObjectFrameSelect : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094{
95public:
96
Greg Clayton864174e2010-10-10 22:28:11 +000097 class CommandOptions : public Options
98 {
99 public:
100
Greg Claytoneb0103f2011-04-07 22:46:35 +0000101 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chenf16066e2011-04-08 22:39:17 +0000102 Options(interpreter)
Greg Clayton864174e2010-10-10 22:28:11 +0000103 {
Greg Claytonf6b8b582011-04-13 00:18:08 +0000104 OptionParsingStarting ();
Greg Clayton864174e2010-10-10 22:28:11 +0000105 }
106
107 virtual
108 ~CommandOptions ()
109 {
110 }
111
112 virtual Error
Greg Claytonf6b8b582011-04-13 00:18:08 +0000113 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Clayton864174e2010-10-10 22:28:11 +0000114 {
115 Error error;
116 bool success = false;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000117 const int short_option = m_getopt_table[option_idx].val;
Greg Clayton864174e2010-10-10 22:28:11 +0000118 switch (short_option)
119 {
120 case 'r':
121 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
122 if (!success)
Greg Clayton86edbf42011-10-26 00:56:27 +0000123 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'", option_arg);
Greg Clayton864174e2010-10-10 22:28:11 +0000124 break;
125
126 default:
Greg Clayton86edbf42011-10-26 00:56:27 +0000127 error.SetErrorStringWithFormat ("invalid short option character '%c'", short_option);
Greg Clayton864174e2010-10-10 22:28:11 +0000128 break;
129 }
130
131 return error;
132 }
133
134 void
Greg Claytonf6b8b582011-04-13 00:18:08 +0000135 OptionParsingStarting ()
Greg Clayton864174e2010-10-10 22:28:11 +0000136 {
Greg Clayton864174e2010-10-10 22:28:11 +0000137 relative_frame_offset = INT32_MIN;
138 }
139
Greg Claytone0d378b2011-03-24 21:19:54 +0000140 const OptionDefinition*
Greg Clayton864174e2010-10-10 22:28:11 +0000141 GetDefinitions ()
142 {
143 return g_option_table;
144 }
145
146 // Options table: Required for subclasses of Options.
147
Greg Claytone0d378b2011-03-24 21:19:54 +0000148 static OptionDefinition g_option_table[];
Greg Clayton864174e2010-10-10 22:28:11 +0000149 int32_t relative_frame_offset;
150 };
151
Greg Claytona7015092010-09-18 01:14:36 +0000152 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000153 CommandObjectParsed (interpreter,
154 "frame select",
155 "Select a frame by index from within the current thread and make it the current frame.",
156 NULL,
Greg Claytonf9fc6092013-01-09 19:44:40 +0000157 eFlagRequiresThread |
158 eFlagTryTargetAPILock |
159 eFlagProcessMustBeLaunched |
160 eFlagProcessMustBePaused ),
Greg Claytoneb0103f2011-04-07 22:46:35 +0000161 m_options (interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162 {
Caroline Tice405fe672010-10-04 22:28:36 +0000163 CommandArgumentEntry arg;
164 CommandArgumentData index_arg;
165
166 // Define the first (and only) variant of this arg.
167 index_arg.arg_type = eArgTypeFrameIndex;
Greg Clayton864174e2010-10-10 22:28:11 +0000168 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice405fe672010-10-04 22:28:36 +0000169
170 // There is only one variant this argument could be; put it into the argument entry.
171 arg.push_back (index_arg);
172
173 // Push the data for the first argument into the m_arguments vector.
174 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175 }
176
177 ~CommandObjectFrameSelect ()
178 {
179 }
180
Greg Clayton864174e2010-10-10 22:28:11 +0000181 virtual
182 Options *
183 GetOptions ()
184 {
185 return &m_options;
186 }
187
188
Jim Ingham5a988412012-06-08 21:56:10 +0000189protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 bool
Greg Claytonf9fc6092013-01-09 19:44:40 +0000191 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000193 // No need to check "thread" for validity as eFlagRequiresThread ensures it is valid
194 Thread *thread = m_exe_ctx.GetThreadPtr();
195
196 uint32_t frame_idx = UINT32_MAX;
197 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000199 // The one and only argument is a signed relative frame index
200 frame_idx = thread->GetSelectedFrameIndex ();
201 if (frame_idx == UINT32_MAX)
202 frame_idx = 0;
203
204 if (m_options.relative_frame_offset < 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000206 if (frame_idx >= -m_options.relative_frame_offset)
207 frame_idx += m_options.relative_frame_offset;
Greg Clayton864174e2010-10-10 22:28:11 +0000208 else
209 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000210 if (frame_idx == 0)
211 {
212 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
213 result.AppendError("Already at the bottom of the stack");
214 result.SetStatus(eReturnStatusFailed);
215 return false;
216 }
217 else
218 frame_idx = 0;
Greg Clayton864174e2010-10-10 22:28:11 +0000219 }
220 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000221 else if (m_options.relative_frame_offset > 0)
Greg Clayton864174e2010-10-10 22:28:11 +0000222 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000223 // I don't want "up 20" where "20" takes you past the top of the stack to produce
224 // an error, but rather to just go to the top. So I have to count the stack here...
225 const uint32_t num_frames = thread->GetStackFrameCount();
226 if (num_frames - frame_idx > m_options.relative_frame_offset)
227 frame_idx += m_options.relative_frame_offset;
228 else
Greg Clayton864174e2010-10-10 22:28:11 +0000229 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000230 if (frame_idx == num_frames - 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000232 //If we are already at the top of the stack, just warn and don't reset the frame.
233 result.AppendError("Already at the top of the stack");
234 result.SetStatus(eReturnStatusFailed);
235 return false;
Greg Clayton864174e2010-10-10 22:28:11 +0000236 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000237 else
238 frame_idx = num_frames - 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000239 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000242 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000244 if (command.GetArgumentCount() == 1)
245 {
246 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
247 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
248 }
249 else if (command.GetArgumentCount() == 0)
250 {
251 frame_idx = thread->GetSelectedFrameIndex ();
252 if (frame_idx == UINT32_MAX)
253 {
254 frame_idx = 0;
255 }
256 }
257 else
258 {
259 result.AppendError ("invalid arguments.\n");
260 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
261 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000263
Jim Ingham93208b82013-01-31 21:46:01 +0000264 bool success = thread->SetSelectedFrameByIndexNoisily (frame_idx, result.GetOutputStream());
Greg Claytonf9fc6092013-01-09 19:44:40 +0000265 if (success)
266 {
267 m_exe_ctx.SetFrameSP(thread->GetSelectedFrame ());
Jim Ingham93208b82013-01-31 21:46:01 +0000268 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonf9fc6092013-01-09 19:44:40 +0000269 }
Jim Ingham93208b82013-01-31 21:46:01 +0000270 else
271 {
272 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
273 result.SetStatus (eReturnStatusFailed);
274 }
275
276 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000277 }
Greg Clayton864174e2010-10-10 22:28:11 +0000278protected:
279
280 CommandOptions m_options;
281};
282
Greg Claytone0d378b2011-03-24 21:19:54 +0000283OptionDefinition
Greg Clayton864174e2010-10-10 22:28:11 +0000284CommandObjectFrameSelect::CommandOptions::g_option_table[] =
285{
Virgile Belloe2607b52013-09-05 16:42:23 +0000286{ LLDB_OPT_SET_1, false, "relative", 'r', OptionParser::eRequiredArgument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
Filipe Cabecinhasbc6e85c2012-09-11 16:09:27 +0000287{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000288};
289
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000290#pragma mark CommandObjectFrameVariable
291//----------------------------------------------------------------------
292// List images with associated information
293//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +0000294class CommandObjectFrameVariable : public CommandObjectParsed
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000295{
296public:
297
Greg Claytona7015092010-09-18 01:14:36 +0000298 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000299 CommandObjectParsed (interpreter,
300 "frame variable",
301 "Show frame variables. All argument and local variables "
302 "that are in scope will be shown when no arguments are given. "
303 "If any arguments are specified, they can be names of "
304 "argument, local, file static and file global variables. "
305 "Children of aggregate variables can be specified such as "
306 "'var->child.x'.",
307 NULL,
Greg Claytonf9fc6092013-01-09 19:44:40 +0000308 eFlagRequiresFrame |
309 eFlagTryTargetAPILock |
310 eFlagProcessMustBeLaunched |
Enrico Granataa6db9332013-02-21 01:29:04 +0000311 eFlagProcessMustBePaused |
312 eFlagRequiresProcess),
Jim Ingham2837b762011-05-04 03:43:18 +0000313 m_option_group (interpreter),
Greg Clayton715c2362011-07-07 04:38:25 +0000314 m_option_variable(true), // Include the frame specific options by passing "true"
Greg Clayton1deb7962011-10-25 06:44:01 +0000315 m_option_format (eFormatDefault),
Jim Ingham2837b762011-05-04 03:43:18 +0000316 m_varobj_options()
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000317 {
Caroline Tice405fe672010-10-04 22:28:36 +0000318 CommandArgumentEntry arg;
319 CommandArgumentData var_name_arg;
320
321 // Define the first (and only) variant of this arg.
322 var_name_arg.arg_type = eArgTypeVarName;
323 var_name_arg.arg_repetition = eArgRepeatStar;
324
325 // There is only one variant this argument could be; put it into the argument entry.
326 arg.push_back (var_name_arg);
327
328 // Push the data for the first argument into the m_arguments vector.
329 m_arguments.push_back (arg);
Jim Ingham2837b762011-05-04 03:43:18 +0000330
Greg Clayton715c2362011-07-07 04:38:25 +0000331 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton5009f9d2011-10-27 17:55:14 +0000332 m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1);
Jim Ingham2837b762011-05-04 03:43:18 +0000333 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
334 m_option_group.Finalize();
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000335 }
336
337 virtual
338 ~CommandObjectFrameVariable ()
339 {
340 }
341
342 virtual
343 Options *
344 GetOptions ()
345 {
Jim Ingham2837b762011-05-04 03:43:18 +0000346 return &m_option_group;
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000347 }
Greg Claytonf21fead2013-05-14 23:43:18 +0000348
349
350 virtual int
351 HandleArgumentCompletion (Args &input,
352 int &cursor_index,
353 int &cursor_char_position,
354 OptionElementVector &opt_element_vector,
355 int match_start_point,
356 int max_return_elements,
357 bool &word_complete,
358 StringList &matches)
359 {
360 // Arguments are the standard source file completer.
361 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
362 completion_str.erase (cursor_char_position);
363
364 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
365 CommandCompletions::eVariablePathCompletion,
366 completion_str.c_str(),
367 match_start_point,
368 max_return_elements,
369 NULL,
370 word_complete,
371 matches);
372 return matches.GetSize();
373 }
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000374
Jim Ingham5a988412012-06-08 21:56:10 +0000375protected:
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000376 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000377 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000378 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000379 // No need to check "frame" for validity as eFlagRequiresFrame ensures it is valid
380 StackFrame *frame = m_exe_ctx.GetFramePtr();
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000381
382 Stream &s = result.GetOutputStream();
383
384 bool get_file_globals = true;
385
386 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
387 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
388
Greg Claytonc14ee322011-09-22 04:58:26 +0000389 VariableList *variable_list = frame->GetVariableList (get_file_globals);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000390
391 VariableSP var_sp;
392 ValueObjectSP valobj_sp;
393
394 const char *name_cstr = NULL;
395 size_t idx;
396
Enrico Granata061858c2012-02-15 02:34:21 +0000397 TypeSummaryImplSP summary_format_sp;
Enrico Granata17b11742012-08-09 22:02:51 +0000398 if (!m_option_variable.summary.IsCurrentValueEmpty())
399 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.GetCurrentValue()), summary_format_sp);
400 else if (!m_option_variable.summary_string.IsCurrentValueEmpty())
401 summary_format_sp.reset(new StringSummaryFormat(TypeSummaryImpl::Flags(),m_option_variable.summary_string.GetCurrentValue()));
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000402
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000403 ValueObject::DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(false,eFormatDefault,summary_format_sp));
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000404
405 if (variable_list)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000406 {
Greg Clayton1deb7962011-10-25 06:44:01 +0000407 const Format format = m_option_format.GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +0000408 options.SetFormat(format);
Greg Clayton1deb7962011-10-25 06:44:01 +0000409
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000410 if (command.GetArgumentCount() > 0)
411 {
412 VariableList regex_var_list;
413
414 // If we have any args to the variable command, we will make
415 // variable objects from them...
416 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
417 {
418 if (m_option_variable.use_regex)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000419 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000420 const size_t regex_start_index = regex_var_list.GetSize();
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000421 RegularExpression regex (name_cstr);
422 if (regex.Compile(name_cstr))
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000423 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000424 size_t num_matches = 0;
425 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
426 regex_var_list,
427 num_matches);
428 if (num_new_regex_vars > 0)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000429 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000430 for (size_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000431 regex_idx < end_index;
432 ++regex_idx)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000433 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000434 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
435 if (var_sp)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000436 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000437 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000438 if (valobj_sp)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000439 {
Greg Clayton6efba4f2012-01-26 21:08:30 +0000440// if (format != eFormatDefault)
441// valobj_sp->SetFormat (format);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000442
443 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
444 {
445 bool show_fullpaths = false;
446 bool show_module = true;
447 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
448 s.PutCString (": ");
Greg Clayton46747022010-10-10 23:55:27 +0000449 }
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000450 ValueObject::DumpValueObject (result.GetOutputStream(),
451 valobj_sp.get(),
Enrico Granata0c489f52012-03-01 04:24:26 +0000452 options);
Greg Clayton46747022010-10-10 23:55:27 +0000453 }
454 }
455 }
Greg Clayton46747022010-10-10 23:55:27 +0000456 }
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000457 else if (num_matches == 0)
Greg Clayton46747022010-10-10 23:55:27 +0000458 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000459 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
Greg Clayton46747022010-10-10 23:55:27 +0000460 }
461 }
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000462 else
Greg Clayton46747022010-10-10 23:55:27 +0000463 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000464 char regex_error[1024];
465 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
466 result.GetErrorStream().Printf ("error: %s\n", regex_error);
Greg Clayton46747022010-10-10 23:55:27 +0000467 else
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000468 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
469 }
470 }
471 else // No regex, either exact variable names or variable expressions.
472 {
473 Error error;
Greg Clayton685c88c2012-07-14 00:53:55 +0000474 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
475 StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000476 lldb::VariableSP var_sp;
Greg Claytonc14ee322011-09-22 04:58:26 +0000477 valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr,
478 m_varobj_options.use_dynamic,
479 expr_path_options,
480 var_sp,
481 error);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000482 if (valobj_sp)
483 {
Greg Clayton6efba4f2012-01-26 21:08:30 +0000484// if (format != eFormatDefault)
485// valobj_sp->SetFormat (format);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000486 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton46747022010-10-10 23:55:27 +0000487 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000488 var_sp->GetDeclaration ().DumpStopContext (&s, false);
489 s.PutCString (": ");
Greg Clayton46747022010-10-10 23:55:27 +0000490 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000491
492 options.SetFormat(format);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000493
494 Stream &output_stream = result.GetOutputStream();
Enrico Granata0c489f52012-03-01 04:24:26 +0000495 options.SetRootValueObjectName(valobj_sp->GetParent() ? name_cstr : NULL);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000496 ValueObject::DumpValueObject (output_stream,
497 valobj_sp.get(),
Enrico Granata0c489f52012-03-01 04:24:26 +0000498 options);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000499 }
500 else
501 {
502 const char *error_cstr = error.AsCString(NULL);
503 if (error_cstr)
504 result.GetErrorStream().Printf("error: %s\n", error_cstr);
505 else
506 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Clayton9df87c12010-09-13 03:44:33 +0000507 }
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000508 }
509 }
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000510 }
511 else // No command arg specified. Use variable_list, instead.
512 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000513 const size_t num_variables = variable_list->GetSize();
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000514 if (num_variables > 0)
Greg Clayton9df87c12010-09-13 03:44:33 +0000515 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000516 for (size_t i=0; i<num_variables; i++)
Greg Clayton9df87c12010-09-13 03:44:33 +0000517 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000518 var_sp = variable_list->GetVariableAtIndex(i);
519 bool dump_variable = true;
520 switch (var_sp->GetScope())
Greg Clayton9df87c12010-09-13 03:44:33 +0000521 {
Greg Clayton9df87c12010-09-13 03:44:33 +0000522 case eValueTypeVariableGlobal:
Greg Clayton715c2362011-07-07 04:38:25 +0000523 dump_variable = m_option_variable.show_globals;
524 if (dump_variable && m_option_variable.show_scope)
Greg Clayton9df87c12010-09-13 03:44:33 +0000525 s.PutCString("GLOBAL: ");
526 break;
527
528 case eValueTypeVariableStatic:
Greg Clayton715c2362011-07-07 04:38:25 +0000529 dump_variable = m_option_variable.show_globals;
530 if (dump_variable && m_option_variable.show_scope)
Greg Clayton9df87c12010-09-13 03:44:33 +0000531 s.PutCString("STATIC: ");
532 break;
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000533
Greg Clayton9df87c12010-09-13 03:44:33 +0000534 case eValueTypeVariableArgument:
Greg Clayton715c2362011-07-07 04:38:25 +0000535 dump_variable = m_option_variable.show_args;
536 if (dump_variable && m_option_variable.show_scope)
Greg Clayton9df87c12010-09-13 03:44:33 +0000537 s.PutCString(" ARG: ");
538 break;
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000539
Greg Clayton9df87c12010-09-13 03:44:33 +0000540 case eValueTypeVariableLocal:
Greg Clayton715c2362011-07-07 04:38:25 +0000541 dump_variable = m_option_variable.show_locals;
542 if (dump_variable && m_option_variable.show_scope)
Greg Clayton9df87c12010-09-13 03:44:33 +0000543 s.PutCString(" LOCAL: ");
544 break;
545
546 default:
547 break;
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000548 }
Greg Clayton9df87c12010-09-13 03:44:33 +0000549
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000550 if (dump_variable)
551 {
552 // Use the variable object code to make sure we are
553 // using the same APIs as the the public API will be
554 // using...
Greg Claytonc14ee322011-09-22 04:58:26 +0000555 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp,
556 m_varobj_options.use_dynamic);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000557 if (valobj_sp)
558 {
Greg Clayton6efba4f2012-01-26 21:08:30 +0000559// if (format != eFormatDefault)
560// valobj_sp->SetFormat (format);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000561
562 // When dumping all variables, don't print any variables
563 // that are not in scope to avoid extra unneeded output
564 if (valobj_sp->IsInScope ())
Greg Clayton9df87c12010-09-13 03:44:33 +0000565 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000566 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Clayton9df87c12010-09-13 03:44:33 +0000567 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000568 var_sp->GetDeclaration ().DumpStopContext (&s, false);
569 s.PutCString (": ");
Greg Clayton6f00abd2010-09-14 03:16:58 +0000570 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000571
572 options.SetFormat(format);
573 options.SetRootValueObjectName(name_cstr);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000574 ValueObject::DumpValueObject (result.GetOutputStream(),
575 valobj_sp.get(),
Enrico Granata0c489f52012-03-01 04:24:26 +0000576 options);
Greg Clayton9df87c12010-09-13 03:44:33 +0000577 }
578 }
579 }
580 }
581 }
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000582 }
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000583 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000584 }
Enrico Granata61a80ba2011-08-12 16:42:31 +0000585
586 if (m_interpreter.TruncationWarningNecessary())
587 {
588 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
589 m_cmd_name.c_str());
590 m_interpreter.TruncationWarningGiven();
591 }
592
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000593 return result.Succeeded();
594 }
595protected:
596
Jim Ingham2837b762011-05-04 03:43:18 +0000597 OptionGroupOptions m_option_group;
Greg Clayton715c2362011-07-07 04:38:25 +0000598 OptionGroupVariable m_option_variable;
Greg Clayton1deb7962011-10-25 06:44:01 +0000599 OptionGroupFormat m_option_format;
Jim Ingham2837b762011-05-04 03:43:18 +0000600 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000601};
602
Jim Ingham2837b762011-05-04 03:43:18 +0000603
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000604#pragma mark CommandObjectMultiwordFrame
605
606//-------------------------------------------------------------------------
607// CommandObjectMultiwordFrame
608//-------------------------------------------------------------------------
609
Greg Clayton66111032010-06-23 01:19:29 +0000610CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +0000611 CommandObjectMultiword (interpreter,
612 "frame",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000613 "A set of commands for operating on the current thread's frames.",
614 "frame <subcommand> [<subcommand-options>]")
615{
Greg Claytona7015092010-09-18 01:14:36 +0000616 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
617 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
618 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000619}
620
621CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
622{
623}
624