blob: 2e852d0bb7679e328c164b888e3f03bd7956528c [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"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000028#include "lldb/DataFormatters/ValueObjectPrinter.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000029#include "lldb/Host/Host.h"
Jim Ingham6d56d2c2010-09-02 00:18:39 +000030#include "lldb/Interpreter/Args.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Interpreter/CommandInterpreter.h"
32#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham6d56d2c2010-09-02 00:18:39 +000033#include "lldb/Interpreter/Options.h"
Greg Clayton1deb7962011-10-25 06:44:01 +000034#include "lldb/Interpreter/OptionGroupFormat.h"
Jim Ingham2837b762011-05-04 03:43:18 +000035#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton715c2362011-07-07 04:38:25 +000036#include "lldb/Interpreter/OptionGroupVariable.h"
Jim Ingham6d56d2c2010-09-02 00:18:39 +000037#include "lldb/Symbol/ClangASTType.h"
38#include "lldb/Symbol/ClangASTContext.h"
39#include "lldb/Symbol/ObjectFile.h"
40#include "lldb/Symbol/SymbolContext.h"
41#include "lldb/Symbol/Type.h"
42#include "lldb/Symbol/Variable.h"
43#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/Target/Process.h"
45#include "lldb/Target/StackFrame.h"
46#include "lldb/Target/Thread.h"
Jim Ingham6d56d2c2010-09-02 00:18:39 +000047#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049using namespace lldb;
50using namespace lldb_private;
51
52#pragma mark CommandObjectFrameInfo
53
54//-------------------------------------------------------------------------
55// CommandObjectFrameInfo
56//-------------------------------------------------------------------------
57
Jim Ingham5a988412012-06-08 21:56:10 +000058class CommandObjectFrameInfo : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059{
60public:
61
Greg Claytona7015092010-09-18 01:14:36 +000062 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +000063 CommandObjectParsed (interpreter,
64 "frame info",
65 "List information about the currently selected frame in the current thread.",
66 "frame info",
Greg Claytonf9fc6092013-01-09 19:44:40 +000067 eFlagRequiresFrame |
68 eFlagTryTargetAPILock |
69 eFlagProcessMustBeLaunched |
70 eFlagProcessMustBePaused )
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071 {
72 }
73
74 ~CommandObjectFrameInfo ()
75 {
76 }
77
Jim Ingham5a988412012-06-08 21:56:10 +000078protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079 bool
Greg Claytonf9fc6092013-01-09 19:44:40 +000080 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081 {
Greg Claytonf9fc6092013-01-09 19:44:40 +000082 m_exe_ctx.GetFrameRef().DumpUsingSettingsFormat (&result.GetOutputStream());
83 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084 return result.Succeeded();
85 }
86};
87
88#pragma mark CommandObjectFrameSelect
89
90//-------------------------------------------------------------------------
91// CommandObjectFrameSelect
92//-------------------------------------------------------------------------
93
Jim Ingham5a988412012-06-08 21:56:10 +000094class CommandObjectFrameSelect : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095{
96public:
97
Greg Clayton864174e2010-10-10 22:28:11 +000098 class CommandOptions : public Options
99 {
100 public:
101
Greg Claytoneb0103f2011-04-07 22:46:35 +0000102 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chenf16066e2011-04-08 22:39:17 +0000103 Options(interpreter)
Greg Clayton864174e2010-10-10 22:28:11 +0000104 {
Greg Claytonf6b8b582011-04-13 00:18:08 +0000105 OptionParsingStarting ();
Greg Clayton864174e2010-10-10 22:28:11 +0000106 }
107
108 virtual
109 ~CommandOptions ()
110 {
111 }
112
113 virtual Error
Greg Claytonf6b8b582011-04-13 00:18:08 +0000114 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Clayton864174e2010-10-10 22:28:11 +0000115 {
116 Error error;
117 bool success = false;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000118 const int short_option = m_getopt_table[option_idx].val;
Greg Clayton864174e2010-10-10 22:28:11 +0000119 switch (short_option)
120 {
121 case 'r':
122 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
123 if (!success)
Greg Clayton86edbf42011-10-26 00:56:27 +0000124 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'", option_arg);
Greg Clayton864174e2010-10-10 22:28:11 +0000125 break;
126
127 default:
Greg Clayton86edbf42011-10-26 00:56:27 +0000128 error.SetErrorStringWithFormat ("invalid short option character '%c'", short_option);
Greg Clayton864174e2010-10-10 22:28:11 +0000129 break;
130 }
131
132 return error;
133 }
134
135 void
Greg Claytonf6b8b582011-04-13 00:18:08 +0000136 OptionParsingStarting ()
Greg Clayton864174e2010-10-10 22:28:11 +0000137 {
Greg Clayton864174e2010-10-10 22:28:11 +0000138 relative_frame_offset = INT32_MIN;
139 }
140
Greg Claytone0d378b2011-03-24 21:19:54 +0000141 const OptionDefinition*
Greg Clayton864174e2010-10-10 22:28:11 +0000142 GetDefinitions ()
143 {
144 return g_option_table;
145 }
146
147 // Options table: Required for subclasses of Options.
148
Greg Claytone0d378b2011-03-24 21:19:54 +0000149 static OptionDefinition g_option_table[];
Greg Clayton864174e2010-10-10 22:28:11 +0000150 int32_t relative_frame_offset;
151 };
152
Greg Claytona7015092010-09-18 01:14:36 +0000153 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000154 CommandObjectParsed (interpreter,
155 "frame select",
156 "Select a frame by index from within the current thread and make it the current frame.",
157 NULL,
Greg Claytonf9fc6092013-01-09 19:44:40 +0000158 eFlagRequiresThread |
159 eFlagTryTargetAPILock |
160 eFlagProcessMustBeLaunched |
161 eFlagProcessMustBePaused ),
Greg Claytoneb0103f2011-04-07 22:46:35 +0000162 m_options (interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163 {
Caroline Tice405fe672010-10-04 22:28:36 +0000164 CommandArgumentEntry arg;
165 CommandArgumentData index_arg;
166
167 // Define the first (and only) variant of this arg.
168 index_arg.arg_type = eArgTypeFrameIndex;
Greg Clayton864174e2010-10-10 22:28:11 +0000169 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice405fe672010-10-04 22:28:36 +0000170
171 // There is only one variant this argument could be; put it into the argument entry.
172 arg.push_back (index_arg);
173
174 // Push the data for the first argument into the m_arguments vector.
175 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176 }
177
178 ~CommandObjectFrameSelect ()
179 {
180 }
181
Greg Clayton864174e2010-10-10 22:28:11 +0000182 virtual
183 Options *
184 GetOptions ()
185 {
186 return &m_options;
187 }
188
189
Jim Ingham5a988412012-06-08 21:56:10 +0000190protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191 bool
Greg Claytonf9fc6092013-01-09 19:44:40 +0000192 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000194 // No need to check "thread" for validity as eFlagRequiresThread ensures it is valid
195 Thread *thread = m_exe_ctx.GetThreadPtr();
196
197 uint32_t frame_idx = UINT32_MAX;
198 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000200 // The one and only argument is a signed relative frame index
201 frame_idx = thread->GetSelectedFrameIndex ();
202 if (frame_idx == UINT32_MAX)
203 frame_idx = 0;
204
205 if (m_options.relative_frame_offset < 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000207 if (frame_idx >= -m_options.relative_frame_offset)
208 frame_idx += m_options.relative_frame_offset;
Greg Clayton864174e2010-10-10 22:28:11 +0000209 else
210 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000211 if (frame_idx == 0)
212 {
213 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
214 result.AppendError("Already at the bottom of the stack");
215 result.SetStatus(eReturnStatusFailed);
216 return false;
217 }
218 else
219 frame_idx = 0;
Greg Clayton864174e2010-10-10 22:28:11 +0000220 }
221 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000222 else if (m_options.relative_frame_offset > 0)
Greg Clayton864174e2010-10-10 22:28:11 +0000223 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000224 // I don't want "up 20" where "20" takes you past the top of the stack to produce
225 // an error, but rather to just go to the top. So I have to count the stack here...
226 const uint32_t num_frames = thread->GetStackFrameCount();
227 if (num_frames - frame_idx > m_options.relative_frame_offset)
228 frame_idx += m_options.relative_frame_offset;
229 else
Greg Clayton864174e2010-10-10 22:28:11 +0000230 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000231 if (frame_idx == num_frames - 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000233 //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;
Greg Clayton864174e2010-10-10 22:28:11 +0000237 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000238 else
239 frame_idx = num_frames - 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000243 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000245 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 }
250 else if (command.GetArgumentCount() == 0)
251 {
252 frame_idx = thread->GetSelectedFrameIndex ();
253 if (frame_idx == UINT32_MAX)
254 {
255 frame_idx = 0;
256 }
257 }
258 else
259 {
260 result.AppendError ("invalid arguments.\n");
261 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
262 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000264
Jim Ingham93208b82013-01-31 21:46:01 +0000265 bool success = thread->SetSelectedFrameByIndexNoisily (frame_idx, result.GetOutputStream());
Greg Claytonf9fc6092013-01-09 19:44:40 +0000266 if (success)
267 {
268 m_exe_ctx.SetFrameSP(thread->GetSelectedFrame ());
Jim Ingham93208b82013-01-31 21:46:01 +0000269 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonf9fc6092013-01-09 19:44:40 +0000270 }
Jim Ingham93208b82013-01-31 21:46:01 +0000271 else
272 {
273 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
274 result.SetStatus (eReturnStatusFailed);
275 }
276
277 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278 }
Greg Clayton864174e2010-10-10 22:28:11 +0000279protected:
280
281 CommandOptions m_options;
282};
283
Greg Claytone0d378b2011-03-24 21:19:54 +0000284OptionDefinition
Greg Clayton864174e2010-10-10 22:28:11 +0000285CommandObjectFrameSelect::CommandOptions::g_option_table[] =
286{
Virgile Belloe2607b52013-09-05 16:42:23 +0000287{ 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 +0000288{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289};
290
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000291#pragma mark CommandObjectFrameVariable
292//----------------------------------------------------------------------
293// List images with associated information
294//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +0000295class CommandObjectFrameVariable : public CommandObjectParsed
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000296{
297public:
298
Greg Claytona7015092010-09-18 01:14:36 +0000299 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000300 CommandObjectParsed (interpreter,
301 "frame variable",
302 "Show frame variables. All argument and local variables "
303 "that are in scope will be shown when no arguments are given. "
304 "If any arguments are specified, they can be names of "
305 "argument, local, file static and file global variables. "
306 "Children of aggregate variables can be specified such as "
307 "'var->child.x'.",
308 NULL,
Greg Claytonf9fc6092013-01-09 19:44:40 +0000309 eFlagRequiresFrame |
310 eFlagTryTargetAPILock |
311 eFlagProcessMustBeLaunched |
Enrico Granataa6db9332013-02-21 01:29:04 +0000312 eFlagProcessMustBePaused |
313 eFlagRequiresProcess),
Jim Ingham2837b762011-05-04 03:43:18 +0000314 m_option_group (interpreter),
Greg Clayton715c2362011-07-07 04:38:25 +0000315 m_option_variable(true), // Include the frame specific options by passing "true"
Greg Clayton1deb7962011-10-25 06:44:01 +0000316 m_option_format (eFormatDefault),
Jim Ingham2837b762011-05-04 03:43:18 +0000317 m_varobj_options()
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000318 {
Caroline Tice405fe672010-10-04 22:28:36 +0000319 CommandArgumentEntry arg;
320 CommandArgumentData var_name_arg;
321
322 // Define the first (and only) variant of this arg.
323 var_name_arg.arg_type = eArgTypeVarName;
324 var_name_arg.arg_repetition = eArgRepeatStar;
325
326 // There is only one variant this argument could be; put it into the argument entry.
327 arg.push_back (var_name_arg);
328
329 // Push the data for the first argument into the m_arguments vector.
330 m_arguments.push_back (arg);
Jim Ingham2837b762011-05-04 03:43:18 +0000331
Greg Clayton715c2362011-07-07 04:38:25 +0000332 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton5009f9d2011-10-27 17:55:14 +0000333 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 +0000334 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
335 m_option_group.Finalize();
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000336 }
337
338 virtual
339 ~CommandObjectFrameVariable ()
340 {
341 }
342
343 virtual
344 Options *
345 GetOptions ()
346 {
Jim Ingham2837b762011-05-04 03:43:18 +0000347 return &m_option_group;
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000348 }
Greg Claytonf21fead2013-05-14 23:43:18 +0000349
350
351 virtual int
352 HandleArgumentCompletion (Args &input,
353 int &cursor_index,
354 int &cursor_char_position,
355 OptionElementVector &opt_element_vector,
356 int match_start_point,
357 int max_return_elements,
358 bool &word_complete,
359 StringList &matches)
360 {
361 // Arguments are the standard source file completer.
362 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
363 completion_str.erase (cursor_char_position);
364
365 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
366 CommandCompletions::eVariablePathCompletion,
367 completion_str.c_str(),
368 match_start_point,
369 max_return_elements,
370 NULL,
371 word_complete,
372 matches);
373 return matches.GetSize();
374 }
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000375
Jim Ingham5a988412012-06-08 21:56:10 +0000376protected:
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000377 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000378 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000379 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000380 // No need to check "frame" for validity as eFlagRequiresFrame ensures it is valid
381 StackFrame *frame = m_exe_ctx.GetFramePtr();
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000382
383 Stream &s = result.GetOutputStream();
384
385 bool get_file_globals = true;
386
387 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
388 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
389
Greg Claytonc14ee322011-09-22 04:58:26 +0000390 VariableList *variable_list = frame->GetVariableList (get_file_globals);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000391
392 VariableSP var_sp;
393 ValueObjectSP valobj_sp;
394
395 const char *name_cstr = NULL;
396 size_t idx;
397
Enrico Granata061858c2012-02-15 02:34:21 +0000398 TypeSummaryImplSP summary_format_sp;
Enrico Granata17b11742012-08-09 22:02:51 +0000399 if (!m_option_variable.summary.IsCurrentValueEmpty())
400 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.GetCurrentValue()), summary_format_sp);
401 else if (!m_option_variable.summary_string.IsCurrentValueEmpty())
402 summary_format_sp.reset(new StringSummaryFormat(TypeSummaryImpl::Flags(),m_option_variable.summary_string.GetCurrentValue()));
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000403
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000404 DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(eLanguageRuntimeDescriptionDisplayVerbosityFull,eFormatDefault,summary_format_sp));
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000405
406 if (variable_list)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000407 {
Greg Clayton1deb7962011-10-25 06:44:01 +0000408 const Format format = m_option_format.GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +0000409 options.SetFormat(format);
Greg Clayton1deb7962011-10-25 06:44:01 +0000410
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000411 if (command.GetArgumentCount() > 0)
412 {
413 VariableList regex_var_list;
414
415 // If we have any args to the variable command, we will make
416 // variable objects from them...
417 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
418 {
419 if (m_option_variable.use_regex)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000420 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000421 const size_t regex_start_index = regex_var_list.GetSize();
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000422 RegularExpression regex (name_cstr);
423 if (regex.Compile(name_cstr))
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000424 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000425 size_t num_matches = 0;
426 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
427 regex_var_list,
428 num_matches);
429 if (num_new_regex_vars > 0)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000430 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000431 for (size_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000432 regex_idx < end_index;
433 ++regex_idx)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000434 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000435 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
436 if (var_sp)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000437 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000438 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000439 if (valobj_sp)
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000440 {
Greg Clayton6efba4f2012-01-26 21:08:30 +0000441// if (format != eFormatDefault)
442// valobj_sp->SetFormat (format);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000443
444 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
445 {
446 bool show_fullpaths = false;
447 bool show_module = true;
448 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
449 s.PutCString (": ");
Greg Clayton46747022010-10-10 23:55:27 +0000450 }
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000451 valobj_sp->Dump(result.GetOutputStream(),options);
Greg Clayton46747022010-10-10 23:55:27 +0000452 }
453 }
454 }
Greg Clayton46747022010-10-10 23:55:27 +0000455 }
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000456 else if (num_matches == 0)
Greg Clayton46747022010-10-10 23:55:27 +0000457 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000458 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
Greg Clayton46747022010-10-10 23:55:27 +0000459 }
460 }
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000461 else
Greg Clayton46747022010-10-10 23:55:27 +0000462 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000463 char regex_error[1024];
464 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
465 result.GetErrorStream().Printf ("error: %s\n", regex_error);
Greg Clayton46747022010-10-10 23:55:27 +0000466 else
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000467 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
468 }
469 }
470 else // No regex, either exact variable names or variable expressions.
471 {
472 Error error;
Greg Clayton685c88c2012-07-14 00:53:55 +0000473 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
474 StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000475 lldb::VariableSP var_sp;
Greg Claytonc14ee322011-09-22 04:58:26 +0000476 valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr,
477 m_varobj_options.use_dynamic,
478 expr_path_options,
479 var_sp,
480 error);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000481 if (valobj_sp)
482 {
Greg Clayton6efba4f2012-01-26 21:08:30 +0000483// if (format != eFormatDefault)
484// valobj_sp->SetFormat (format);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000485 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton46747022010-10-10 23:55:27 +0000486 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000487 var_sp->GetDeclaration ().DumpStopContext (&s, false);
488 s.PutCString (": ");
Greg Clayton46747022010-10-10 23:55:27 +0000489 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000490
491 options.SetFormat(format);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000492
493 Stream &output_stream = result.GetOutputStream();
Enrico Granata0c489f52012-03-01 04:24:26 +0000494 options.SetRootValueObjectName(valobj_sp->GetParent() ? name_cstr : NULL);
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000495 valobj_sp->Dump(output_stream,options);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000496 }
497 else
498 {
499 const char *error_cstr = error.AsCString(NULL);
500 if (error_cstr)
501 result.GetErrorStream().Printf("error: %s\n", error_cstr);
502 else
503 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Clayton9df87c12010-09-13 03:44:33 +0000504 }
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000505 }
506 }
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000507 }
508 else // No command arg specified. Use variable_list, instead.
509 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000510 const size_t num_variables = variable_list->GetSize();
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000511 if (num_variables > 0)
Greg Clayton9df87c12010-09-13 03:44:33 +0000512 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000513 for (size_t i=0; i<num_variables; i++)
Greg Clayton9df87c12010-09-13 03:44:33 +0000514 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000515 var_sp = variable_list->GetVariableAtIndex(i);
516 bool dump_variable = true;
517 switch (var_sp->GetScope())
Greg Clayton9df87c12010-09-13 03:44:33 +0000518 {
Greg Clayton9df87c12010-09-13 03:44:33 +0000519 case eValueTypeVariableGlobal:
Greg Clayton715c2362011-07-07 04:38:25 +0000520 dump_variable = m_option_variable.show_globals;
521 if (dump_variable && m_option_variable.show_scope)
Greg Clayton9df87c12010-09-13 03:44:33 +0000522 s.PutCString("GLOBAL: ");
523 break;
524
525 case eValueTypeVariableStatic:
Greg Clayton715c2362011-07-07 04:38:25 +0000526 dump_variable = m_option_variable.show_globals;
527 if (dump_variable && m_option_variable.show_scope)
Greg Clayton9df87c12010-09-13 03:44:33 +0000528 s.PutCString("STATIC: ");
529 break;
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000530
Greg Clayton9df87c12010-09-13 03:44:33 +0000531 case eValueTypeVariableArgument:
Greg Clayton715c2362011-07-07 04:38:25 +0000532 dump_variable = m_option_variable.show_args;
533 if (dump_variable && m_option_variable.show_scope)
Greg Clayton9df87c12010-09-13 03:44:33 +0000534 s.PutCString(" ARG: ");
535 break;
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000536
Greg Clayton9df87c12010-09-13 03:44:33 +0000537 case eValueTypeVariableLocal:
Greg Clayton715c2362011-07-07 04:38:25 +0000538 dump_variable = m_option_variable.show_locals;
539 if (dump_variable && m_option_variable.show_scope)
Greg Clayton9df87c12010-09-13 03:44:33 +0000540 s.PutCString(" LOCAL: ");
541 break;
542
543 default:
544 break;
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000545 }
Greg Clayton9df87c12010-09-13 03:44:33 +0000546
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000547 if (dump_variable)
548 {
549 // Use the variable object code to make sure we are
550 // using the same APIs as the the public API will be
551 // using...
Greg Claytonc14ee322011-09-22 04:58:26 +0000552 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp,
553 m_varobj_options.use_dynamic);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000554 if (valobj_sp)
555 {
Greg Clayton6efba4f2012-01-26 21:08:30 +0000556// if (format != eFormatDefault)
557// valobj_sp->SetFormat (format);
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000558
559 // When dumping all variables, don't print any variables
560 // that are not in scope to avoid extra unneeded output
561 if (valobj_sp->IsInScope ())
Greg Clayton9df87c12010-09-13 03:44:33 +0000562 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000563 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Clayton9df87c12010-09-13 03:44:33 +0000564 {
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000565 var_sp->GetDeclaration ().DumpStopContext (&s, false);
566 s.PutCString (": ");
Greg Clayton6f00abd2010-09-14 03:16:58 +0000567 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000568
569 options.SetFormat(format);
570 options.SetRootValueObjectName(name_cstr);
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000571 valobj_sp->Dump(result.GetOutputStream(),options);
Greg Clayton9df87c12010-09-13 03:44:33 +0000572 }
573 }
574 }
575 }
576 }
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000577 }
Johnny Chen1e49e5e2011-09-12 23:58:53 +0000578 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000579 }
Enrico Granata61a80ba2011-08-12 16:42:31 +0000580
581 if (m_interpreter.TruncationWarningNecessary())
582 {
583 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
584 m_cmd_name.c_str());
585 m_interpreter.TruncationWarningGiven();
586 }
587
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000588 return result.Succeeded();
589 }
590protected:
591
Jim Ingham2837b762011-05-04 03:43:18 +0000592 OptionGroupOptions m_option_group;
Greg Clayton715c2362011-07-07 04:38:25 +0000593 OptionGroupVariable m_option_variable;
Greg Clayton1deb7962011-10-25 06:44:01 +0000594 OptionGroupFormat m_option_format;
Jim Ingham2837b762011-05-04 03:43:18 +0000595 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham6d56d2c2010-09-02 00:18:39 +0000596};
597
Jim Ingham2837b762011-05-04 03:43:18 +0000598
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599#pragma mark CommandObjectMultiwordFrame
600
601//-------------------------------------------------------------------------
602// CommandObjectMultiwordFrame
603//-------------------------------------------------------------------------
604
Greg Clayton66111032010-06-23 01:19:29 +0000605CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +0000606 CommandObjectMultiword (interpreter,
607 "frame",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000608 "A set of commands for operating on the current thread's frames.",
609 "frame <subcommand> [<subcommand-options>]")
610{
Greg Claytona7015092010-09-18 01:14:36 +0000611 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
612 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
613 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614}
615
616CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
617{
618}
619