blob: 12670a1e9e51418c110582805d1d1ca6230168f7 [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
14// Other libraries and framework includes
15// Project includes
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Core/Debugger.h"
Jim Ingham537926c2010-09-02 00:18:39 +000017#include "lldb/Core/Module.h"
18#include "lldb/Core/StreamFile.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/Timer.h"
Jim Ingham537926c2010-09-02 00:18:39 +000020#include "lldb/Core/Value.h"
21#include "lldb/Core/ValueObject.h"
22#include "lldb/Core/ValueObjectVariable.h"
Greg Claytoncd548032011-02-01 01:31:41 +000023#include "lldb/Host/Host.h"
Jim Ingham537926c2010-09-02 00:18:39 +000024#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Interpreter/CommandInterpreter.h"
26#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham537926c2010-09-02 00:18:39 +000027#include "lldb/Interpreter/Options.h"
Jim Ingham10de7d12011-05-04 03:43:18 +000028#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton368f8222011-07-07 04:38:25 +000029#include "lldb/Interpreter/OptionGroupVariable.h"
Jim Ingham537926c2010-09-02 00:18:39 +000030#include "lldb/Symbol/ClangASTType.h"
31#include "lldb/Symbol/ClangASTContext.h"
32#include "lldb/Symbol/ObjectFile.h"
33#include "lldb/Symbol/SymbolContext.h"
34#include "lldb/Symbol/Type.h"
35#include "lldb/Symbol/Variable.h"
36#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000037#include "lldb/Target/Process.h"
38#include "lldb/Target/StackFrame.h"
39#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000040#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000041
Chris Lattner24943d22010-06-08 16:52:24 +000042using namespace lldb;
43using namespace lldb_private;
44
45#pragma mark CommandObjectFrameInfo
46
47//-------------------------------------------------------------------------
48// CommandObjectFrameInfo
49//-------------------------------------------------------------------------
50
51class CommandObjectFrameInfo : public CommandObject
52{
53public:
54
Greg Clayton238c0a12010-09-18 01:14:36 +000055 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
56 CommandObject (interpreter,
57 "frame info",
58 "List information about the currently selected frame in the current thread.",
59 "frame info",
60 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000061 {
62 }
63
64 ~CommandObjectFrameInfo ()
65 {
66 }
67
68 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000069 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000070 CommandReturnObject &result)
71 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000072 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +000073 if (exe_ctx.frame)
74 {
Greg Claytona830adb2010-10-04 01:05:56 +000075 exe_ctx.frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000076 result.GetOutputStream().EOL();
77 result.SetStatus (eReturnStatusSuccessFinishResult);
78 }
79 else
80 {
81 result.AppendError ("no current frame");
82 result.SetStatus (eReturnStatusFailed);
83 }
84 return result.Succeeded();
85 }
86};
87
88#pragma mark CommandObjectFrameSelect
89
90//-------------------------------------------------------------------------
91// CommandObjectFrameSelect
92//-------------------------------------------------------------------------
93
94class CommandObjectFrameSelect : public CommandObject
95{
96public:
97
Greg Claytonc12b6b42010-10-10 22:28:11 +000098 class CommandOptions : public Options
99 {
100 public:
101
Greg Claytonf15996e2011-04-07 22:46:35 +0000102 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000103 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000104 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000105 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000106 }
107
108 virtual
109 ~CommandOptions ()
110 {
111 }
112
113 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000114 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000115 {
116 Error error;
117 bool success = false;
118 char short_option = (char) m_getopt_table[option_idx].val;
119 switch (short_option)
120 {
121 case 'r':
122 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
123 if (!success)
124 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg);
125 break;
126
127 default:
Benjamin Kramerfddc25a2010-11-10 20:16:47 +0000128 error.SetErrorStringWithFormat ("Invalid short option character '%c'.\n", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000129 break;
130 }
131
132 return error;
133 }
134
135 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000136 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000137 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000138 relative_frame_offset = INT32_MIN;
139 }
140
Greg Claytonb3448432011-03-24 21:19:54 +0000141 const OptionDefinition*
Greg Claytonc12b6b42010-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 Claytonb3448432011-03-24 21:19:54 +0000149 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000150 int32_t relative_frame_offset;
151 };
152
Greg Clayton238c0a12010-09-18 01:14:36 +0000153 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
154 CommandObject (interpreter,
155 "frame select",
156 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000157 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000158 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
159 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000160 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000161 CommandArgumentEntry arg;
162 CommandArgumentData index_arg;
163
164 // Define the first (and only) variant of this arg.
165 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000166 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000167
168 // There is only one variant this argument could be; put it into the argument entry.
169 arg.push_back (index_arg);
170
171 // Push the data for the first argument into the m_arguments vector.
172 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000173 }
174
175 ~CommandObjectFrameSelect ()
176 {
177 }
178
Greg Claytonc12b6b42010-10-10 22:28:11 +0000179 virtual
180 Options *
181 GetOptions ()
182 {
183 return &m_options;
184 }
185
186
Chris Lattner24943d22010-06-08 16:52:24 +0000187 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000188 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000189 CommandReturnObject &result)
190 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000191 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000192 if (exe_ctx.thread)
193 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000194 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
195 uint32_t frame_idx = UINT32_MAX;
196 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000197 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000198 // The one and only argument is a signed relative frame index
199 frame_idx = exe_ctx.thread->GetSelectedFrameIndex ();
200 if (frame_idx == UINT32_MAX)
201 frame_idx = 0;
202
203 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000204 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000205 if (frame_idx >= -m_options.relative_frame_offset)
206 frame_idx += m_options.relative_frame_offset;
207 else
208 frame_idx = 0;
209 }
210 else if (m_options.relative_frame_offset > 0)
211 {
212 if (num_frames - frame_idx > m_options.relative_frame_offset)
213 frame_idx += m_options.relative_frame_offset;
214 else
215 frame_idx = num_frames - 1;
216 }
217 }
218 else
219 {
220 if (command.GetArgumentCount() == 1)
221 {
222 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
223 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
224 }
225 else
226 {
227 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000228 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000229 }
230 }
231
232 if (frame_idx < num_frames)
233 {
234 exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
235 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000236
Greg Claytonc12b6b42010-10-10 22:28:11 +0000237 if (exe_ctx.frame)
238 {
239 bool already_shown = false;
240 SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
241 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000242 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000243 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
244 }
Jim Ingham74989e82010-08-30 19:44:40 +0000245
Greg Claytonabe0fed2011-04-18 08:33:37 +0000246 bool show_frame_info = true;
247 bool show_source = !already_shown;
248 uint32_t source_lines_before = 3;
249 uint32_t source_lines_after = 3;
250 if (exe_ctx.frame->GetStatus(result.GetOutputStream(),
251 show_frame_info,
252 show_source,
253 source_lines_before,
254 source_lines_after))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000255 {
256 result.SetStatus (eReturnStatusSuccessFinishResult);
257 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000258 }
259 }
Chris Lattner24943d22010-06-08 16:52:24 +0000260 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000261 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000262 }
263 else
264 {
265 result.AppendError ("no current thread");
266 }
267 result.SetStatus (eReturnStatusFailed);
268 return false;
269 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000270protected:
271
272 CommandOptions m_options;
273};
274
Greg Claytonb3448432011-03-24 21:19:54 +0000275OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000276CommandObjectFrameSelect::CommandOptions::g_option_table[] =
277{
278{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
279{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000280};
281
Jim Ingham537926c2010-09-02 00:18:39 +0000282#pragma mark CommandObjectFrameVariable
283//----------------------------------------------------------------------
284// List images with associated information
285//----------------------------------------------------------------------
286class CommandObjectFrameVariable : public CommandObject
287{
288public:
289
Jim Ingham10de7d12011-05-04 03:43:18 +0000290 class OptionGroupFrameVariable : public OptionGroup
Jim Ingham537926c2010-09-02 00:18:39 +0000291 {
292 public:
293
Jim Ingham10de7d12011-05-04 03:43:18 +0000294 OptionGroupFrameVariable ()
Jim Ingham537926c2010-09-02 00:18:39 +0000295 {
Jim Ingham537926c2010-09-02 00:18:39 +0000296 }
297
298 virtual
Jim Ingham10de7d12011-05-04 03:43:18 +0000299 ~OptionGroupFrameVariable ()
Jim Ingham537926c2010-09-02 00:18:39 +0000300 {
301 }
302
Jim Ingham10de7d12011-05-04 03:43:18 +0000303 virtual uint32_t
304 GetNumDefinitions ();
305
306 virtual const OptionDefinition*
307 GetDefinitions ()
308 {
309 return g_option_table;
310 }
311
Jim Ingham537926c2010-09-02 00:18:39 +0000312 virtual Error
Jim Ingham10de7d12011-05-04 03:43:18 +0000313 SetOptionValue (CommandInterpreter &interpreter,
314 uint32_t option_idx,
315 const char *option_arg)
Jim Ingham537926c2010-09-02 00:18:39 +0000316 {
317 Error error;
Jim Ingham10de7d12011-05-04 03:43:18 +0000318 char short_option = (char) g_option_table[option_idx].short_option;
Jim Ingham537926c2010-09-02 00:18:39 +0000319 switch (short_option)
320 {
Jim Ingham537926c2010-09-02 00:18:39 +0000321 case 'r': use_regex = true; break;
322 case 'a': show_args = false; break;
323 case 'l': show_locals = false; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000324 case 'g': show_globals = true; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000325 case 'c': show_decl = true; break;
Greg Clayton56bbdaf2011-04-28 20:55:26 +0000326 case 'f': error = Args::StringToFormat(option_arg, format, NULL); break;
Jim Ingham537926c2010-09-02 00:18:39 +0000327 case 'G':
Greg Claytonaed58812010-09-13 02:37:44 +0000328 globals.push_back(ConstString (option_arg));
Jim Ingham537926c2010-09-02 00:18:39 +0000329 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000330 case 's':
331 show_scope = true;
332 break;
333
334 default:
335 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
336 break;
337 }
338
339 return error;
340 }
341
Jim Ingham10de7d12011-05-04 03:43:18 +0000342 virtual void
343 OptionParsingStarting (CommandInterpreter &interpreter)
Jim Ingham537926c2010-09-02 00:18:39 +0000344 {
Jim Ingham537926c2010-09-02 00:18:39 +0000345 show_args = true;
Greg Claytonaed58812010-09-13 02:37:44 +0000346 show_decl = false;
Greg Claytonb1888f22011-03-19 01:12:21 +0000347 format = eFormatDefault;
Jim Ingham10de7d12011-05-04 03:43:18 +0000348 show_globals = false;
349 show_locals = true;
350 use_regex = false;
351 show_scope = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000352 globals.clear();
353 }
354
Jim Ingham537926c2010-09-02 00:18:39 +0000355 // Options table: Required for subclasses of Options.
356
Greg Claytonb3448432011-03-24 21:19:54 +0000357 static OptionDefinition g_option_table[];
Jim Ingham10de7d12011-05-04 03:43:18 +0000358
359 bool use_regex:1,
Greg Claytonaed58812010-09-13 02:37:44 +0000360 show_args:1,
361 show_locals:1,
362 show_globals:1,
Greg Claytonaed58812010-09-13 02:37:44 +0000363 show_scope:1,
Jim Ingham10de7d12011-05-04 03:43:18 +0000364 show_decl:1;
Greg Claytonb1888f22011-03-19 01:12:21 +0000365 lldb::Format format; // The format to use when dumping variables or children of variables
Jim Ingham537926c2010-09-02 00:18:39 +0000366 std::vector<ConstString> globals;
367 // Instance variables to hold the values for command options.
368 };
369
Greg Clayton238c0a12010-09-18 01:14:36 +0000370 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
371 CommandObject (interpreter,
372 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000373 "Show frame variables. All argument and local variables "
374 "that are in scope will be shown when no arguments are given. "
375 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000376 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000377 "Children of aggregate variables can be specified such as "
378 "'var->child.x'.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000379 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000380 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Jim Ingham10de7d12011-05-04 03:43:18 +0000381 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000382 m_option_variable(true), // Include the frame specific options by passing "true"
Jim Ingham10de7d12011-05-04 03:43:18 +0000383 m_varobj_options()
Jim Ingham537926c2010-09-02 00:18:39 +0000384 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000385 CommandArgumentEntry arg;
386 CommandArgumentData var_name_arg;
387
388 // Define the first (and only) variant of this arg.
389 var_name_arg.arg_type = eArgTypeVarName;
390 var_name_arg.arg_repetition = eArgRepeatStar;
391
392 // There is only one variant this argument could be; put it into the argument entry.
393 arg.push_back (var_name_arg);
394
395 // Push the data for the first argument into the m_arguments vector.
396 m_arguments.push_back (arg);
Jim Ingham10de7d12011-05-04 03:43:18 +0000397
Greg Clayton368f8222011-07-07 04:38:25 +0000398 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Jim Ingham10de7d12011-05-04 03:43:18 +0000399 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
400 m_option_group.Finalize();
Jim Ingham537926c2010-09-02 00:18:39 +0000401 }
402
403 virtual
404 ~CommandObjectFrameVariable ()
405 {
406 }
407
408 virtual
409 Options *
410 GetOptions ()
411 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000412 return &m_option_group;
Jim Ingham537926c2010-09-02 00:18:39 +0000413 }
414
Jim Ingham537926c2010-09-02 00:18:39 +0000415
416 virtual bool
417 Execute
418 (
Jim Ingham537926c2010-09-02 00:18:39 +0000419 Args& command,
420 CommandReturnObject &result
421 )
422 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000423 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000424 if (exe_ctx.frame == NULL)
425 {
Greg Claytonaa448052010-09-18 04:06:15 +0000426 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000427 result.SetStatus (eReturnStatusFailed);
428 return false;
429 }
430 else
431 {
Greg Claytonaed58812010-09-13 02:37:44 +0000432 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000433
Greg Claytonaed58812010-09-13 02:37:44 +0000434 bool get_file_globals = true;
435 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
436
Jim Ingham537926c2010-09-02 00:18:39 +0000437 VariableSP var_sp;
438 ValueObjectSP valobj_sp;
Jim Inghame41494a2011-04-16 00:01:13 +0000439
Jim Ingham537926c2010-09-02 00:18:39 +0000440 const char *name_cstr = NULL;
441 size_t idx;
Enrico Granata1a102082011-07-12 00:18:11 +0000442
443 SummaryFormatSP summary_format_sp;
444 if (!m_option_variable.summary.empty())
Enrico Granata8a717e52011-07-19 02:34:21 +0000445 Debugger::Formatting::NamedSummaryFormats::Get(ConstString(m_option_variable.summary.c_str()), summary_format_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000446
Greg Clayton368f8222011-07-07 04:38:25 +0000447 if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000448 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000449 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000450 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000451 VariableList regex_var_list;
452
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000453 // If we have any args to the variable command, we will make
454 // variable objects from them...
455 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000456 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000457 uint32_t ptr_depth = m_varobj_options.ptr_depth;
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000458
Greg Clayton368f8222011-07-07 04:38:25 +0000459 if (m_option_variable.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000460 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000461 const uint32_t regex_start_index = regex_var_list.GetSize();
462 RegularExpression regex (name_cstr);
463 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000464 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000465 size_t num_matches = 0;
Jim Inghame41494a2011-04-16 00:01:13 +0000466 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
467 regex_var_list,
468 num_matches);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000469 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000470 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000471 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
472 regex_idx < end_index;
473 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000474 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000475 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
476 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000477 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000478 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000479 if (valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000480 {
Greg Clayton368f8222011-07-07 04:38:25 +0000481 if (m_option_variable.format != eFormatDefault)
482 valobj_sp->SetFormat (m_option_variable.format);
Greg Claytonb1888f22011-03-19 01:12:21 +0000483
Greg Clayton368f8222011-07-07 04:38:25 +0000484 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000485 {
Greg Claytonfb816422011-07-10 19:21:23 +0000486 bool show_fullpaths = false;
487 bool show_module = true;
488 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
489 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000490 }
Enrico Granata1a102082011-07-12 00:18:11 +0000491 if (summary_format_sp)
492 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000493 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000494 valobj_sp.get(),
495 var_sp->GetName().AsCString(),
Jim Ingham10de7d12011-05-04 03:43:18 +0000496 m_varobj_options.ptr_depth,
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000497 0,
Jim Ingham10de7d12011-05-04 03:43:18 +0000498 m_varobj_options.max_depth,
499 m_varobj_options.show_types,
500 m_varobj_options.show_location,
501 m_varobj_options.use_objc,
502 m_varobj_options.use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000503 false,
Enrico Granata7f163b32011-07-16 01:22:04 +0000504 m_varobj_options.flat_output,
505 m_varobj_options.no_summary_depth);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000506 }
507 }
508 }
509 }
510 else if (num_matches == 0)
511 {
512 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
513 }
514 }
515 else
516 {
517 char regex_error[1024];
518 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
519 result.GetErrorStream().Printf ("error: %s\n", regex_error);
520 else
521 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
522 }
523 }
524 else
525 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000526 Error error;
Jim Inghame41494a2011-04-16 00:01:13 +0000527 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
Jim Ingham10de7d12011-05-04 03:43:18 +0000528 lldb::VariableSP var_sp;
529 valobj_sp = exe_ctx.frame->GetValueForVariableExpressionPath (name_cstr,
530 m_varobj_options.use_dynamic,
531 expr_path_options,
532 var_sp,
533 error);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000534 if (valobj_sp)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000535 {
Greg Clayton368f8222011-07-07 04:38:25 +0000536 if (m_option_variable.format != eFormatDefault)
537 valobj_sp->SetFormat (m_option_variable.format);
538 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000539 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000540 var_sp->GetDeclaration ().DumpStopContext (&s, false);
541 s.PutCString (": ");
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000542 }
Enrico Granata1a102082011-07-12 00:18:11 +0000543 if (summary_format_sp)
544 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000545 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Claytonc3b61d22010-12-15 05:08:08 +0000546 valobj_sp.get(),
547 valobj_sp->GetParent() ? name_cstr : NULL,
548 ptr_depth,
549 0,
Jim Ingham10de7d12011-05-04 03:43:18 +0000550 m_varobj_options.max_depth,
551 m_varobj_options.show_types,
552 m_varobj_options.show_location,
553 m_varobj_options.use_objc,
554 m_varobj_options.use_dynamic,
Greg Claytonc3b61d22010-12-15 05:08:08 +0000555 false,
Enrico Granata7f163b32011-07-16 01:22:04 +0000556 m_varobj_options.flat_output,
557 m_varobj_options.no_summary_depth);
Greg Claytonaed58812010-09-13 02:37:44 +0000558 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000559 else
560 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000561 const char *error_cstr = error.AsCString(NULL);
562 if (error_cstr)
563 result.GetErrorStream().Printf("error: %s\n", error_cstr);
564 else
565 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000566 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000567 }
Jim Ingham537926c2010-09-02 00:18:39 +0000568 }
569 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000570 else
571 {
572 const uint32_t num_variables = variable_list->GetSize();
573
574 if (num_variables > 0)
575 {
576 for (uint32_t i=0; i<num_variables; i++)
577 {
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000578 var_sp = variable_list->GetVariableAtIndex(i);
Jim Inghame41494a2011-04-16 00:01:13 +0000579
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000580 bool dump_variable = true;
581
582 switch (var_sp->GetScope())
583 {
584 case eValueTypeVariableGlobal:
Greg Clayton368f8222011-07-07 04:38:25 +0000585 dump_variable = m_option_variable.show_globals;
586 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000587 s.PutCString("GLOBAL: ");
588 break;
589
590 case eValueTypeVariableStatic:
Greg Clayton368f8222011-07-07 04:38:25 +0000591 dump_variable = m_option_variable.show_globals;
592 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000593 s.PutCString("STATIC: ");
594 break;
595
596 case eValueTypeVariableArgument:
Greg Clayton368f8222011-07-07 04:38:25 +0000597 dump_variable = m_option_variable.show_args;
598 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000599 s.PutCString(" ARG: ");
600 break;
601
602 case eValueTypeVariableLocal:
Greg Clayton368f8222011-07-07 04:38:25 +0000603 dump_variable = m_option_variable.show_locals;
604 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000605 s.PutCString(" LOCAL: ");
606 break;
607
608 default:
609 break;
610 }
611
612 if (dump_variable)
613 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000614
615 // Use the variable object code to make sure we are
616 // using the same APIs as the the public API will be
617 // using...
Jim Ingham10de7d12011-05-04 03:43:18 +0000618 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp,
619 m_varobj_options.use_dynamic);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000620 if (valobj_sp)
621 {
Greg Clayton368f8222011-07-07 04:38:25 +0000622 if (m_option_variable.format != eFormatDefault)
623 valobj_sp->SetFormat (m_option_variable.format);
Greg Claytonb1888f22011-03-19 01:12:21 +0000624
Greg Claytona357ecf2010-09-14 03:16:58 +0000625 // When dumping all variables, don't print any variables
626 // that are not in scope to avoid extra unneeded output
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000627 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000628 {
Greg Clayton368f8222011-07-07 04:38:25 +0000629 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytona357ecf2010-09-14 03:16:58 +0000630 {
631 var_sp->GetDeclaration ().DumpStopContext (&s, false);
632 s.PutCString (": ");
633 }
Enrico Granata1a102082011-07-12 00:18:11 +0000634 if (summary_format_sp)
635 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000636 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000637 valobj_sp.get(),
638 name_cstr,
Jim Ingham10de7d12011-05-04 03:43:18 +0000639 m_varobj_options.ptr_depth,
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000640 0,
Jim Ingham10de7d12011-05-04 03:43:18 +0000641 m_varobj_options.max_depth,
642 m_varobj_options.show_types,
643 m_varobj_options.show_location,
644 m_varobj_options.use_objc,
645 m_varobj_options.use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000646 false,
Enrico Granata7f163b32011-07-16 01:22:04 +0000647 m_varobj_options.flat_output,
648 m_varobj_options.no_summary_depth);
Greg Claytona357ecf2010-09-14 03:16:58 +0000649 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000650 }
651 }
652 }
653 }
654 }
655 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000656 }
Jim Ingham537926c2010-09-02 00:18:39 +0000657 }
658 return result.Succeeded();
659 }
660protected:
661
Jim Ingham10de7d12011-05-04 03:43:18 +0000662 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000663 OptionGroupVariable m_option_variable;
Jim Ingham10de7d12011-05-04 03:43:18 +0000664 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham537926c2010-09-02 00:18:39 +0000665};
666
Jim Ingham10de7d12011-05-04 03:43:18 +0000667
Chris Lattner24943d22010-06-08 16:52:24 +0000668#pragma mark CommandObjectMultiwordFrame
669
670//-------------------------------------------------------------------------
671// CommandObjectMultiwordFrame
672//-------------------------------------------------------------------------
673
Greg Clayton63094e02010-06-23 01:19:29 +0000674CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000675 CommandObjectMultiword (interpreter,
676 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000677 "A set of commands for operating on the current thread's frames.",
678 "frame <subcommand> [<subcommand-options>]")
679{
Greg Clayton238c0a12010-09-18 01:14:36 +0000680 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
681 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
682 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000683}
684
685CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
686{
687}
688