blob: 33e735ac81d1395ba2588e10f92024d50600e5ab [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"
Jim Ingham537926c2010-09-02 00:18:39 +000029#include "lldb/Symbol/ClangASTType.h"
30#include "lldb/Symbol/ClangASTContext.h"
31#include "lldb/Symbol/ObjectFile.h"
32#include "lldb/Symbol/SymbolContext.h"
33#include "lldb/Symbol/Type.h"
34#include "lldb/Symbol/Variable.h"
35#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000036#include "lldb/Target/Process.h"
37#include "lldb/Target/StackFrame.h"
38#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000039#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000040
Chris Lattner24943d22010-06-08 16:52:24 +000041using namespace lldb;
42using namespace lldb_private;
43
44#pragma mark CommandObjectFrameInfo
45
46//-------------------------------------------------------------------------
47// CommandObjectFrameInfo
48//-------------------------------------------------------------------------
49
50class CommandObjectFrameInfo : public CommandObject
51{
52public:
53
Greg Clayton238c0a12010-09-18 01:14:36 +000054 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
55 CommandObject (interpreter,
56 "frame info",
57 "List information about the currently selected frame in the current thread.",
58 "frame info",
59 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000060 {
61 }
62
63 ~CommandObjectFrameInfo ()
64 {
65 }
66
67 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000068 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000069 CommandReturnObject &result)
70 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000071 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +000072 if (exe_ctx.frame)
73 {
Greg Claytona830adb2010-10-04 01:05:56 +000074 exe_ctx.frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000075 result.GetOutputStream().EOL();
76 result.SetStatus (eReturnStatusSuccessFinishResult);
77 }
78 else
79 {
80 result.AppendError ("no current frame");
81 result.SetStatus (eReturnStatusFailed);
82 }
83 return result.Succeeded();
84 }
85};
86
87#pragma mark CommandObjectFrameSelect
88
89//-------------------------------------------------------------------------
90// CommandObjectFrameSelect
91//-------------------------------------------------------------------------
92
93class CommandObjectFrameSelect : public CommandObject
94{
95public:
96
Greg Claytonc12b6b42010-10-10 22:28:11 +000097 class CommandOptions : public Options
98 {
99 public:
100
Greg Claytonf15996e2011-04-07 22:46:35 +0000101 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000102 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000103 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000104 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000105 }
106
107 virtual
108 ~CommandOptions ()
109 {
110 }
111
112 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000113 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000114 {
115 Error error;
116 bool success = false;
117 char short_option = (char) m_getopt_table[option_idx].val;
118 switch (short_option)
119 {
120 case 'r':
121 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
122 if (!success)
123 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg);
124 break;
125
126 default:
Benjamin Kramerfddc25a2010-11-10 20:16:47 +0000127 error.SetErrorStringWithFormat ("Invalid short option character '%c'.\n", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000128 break;
129 }
130
131 return error;
132 }
133
134 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000135 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000136 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000137 relative_frame_offset = INT32_MIN;
138 }
139
Greg Claytonb3448432011-03-24 21:19:54 +0000140 const OptionDefinition*
Greg Claytonc12b6b42010-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 Claytonb3448432011-03-24 21:19:54 +0000148 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000149 int32_t relative_frame_offset;
150 };
151
Greg Clayton238c0a12010-09-18 01:14:36 +0000152 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
153 CommandObject (interpreter,
154 "frame select",
155 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000156 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000157 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
158 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000159 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000160 CommandArgumentEntry arg;
161 CommandArgumentData index_arg;
162
163 // Define the first (and only) variant of this arg.
164 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000165 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000166
167 // There is only one variant this argument could be; put it into the argument entry.
168 arg.push_back (index_arg);
169
170 // Push the data for the first argument into the m_arguments vector.
171 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000172 }
173
174 ~CommandObjectFrameSelect ()
175 {
176 }
177
Greg Claytonc12b6b42010-10-10 22:28:11 +0000178 virtual
179 Options *
180 GetOptions ()
181 {
182 return &m_options;
183 }
184
185
Chris Lattner24943d22010-06-08 16:52:24 +0000186 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000187 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000188 CommandReturnObject &result)
189 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000190 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000191 if (exe_ctx.thread)
192 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000193 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
194 uint32_t frame_idx = UINT32_MAX;
195 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000196 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000197 // The one and only argument is a signed relative frame index
198 frame_idx = exe_ctx.thread->GetSelectedFrameIndex ();
199 if (frame_idx == UINT32_MAX)
200 frame_idx = 0;
201
202 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000203 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000204 if (frame_idx >= -m_options.relative_frame_offset)
205 frame_idx += m_options.relative_frame_offset;
206 else
207 frame_idx = 0;
208 }
209 else if (m_options.relative_frame_offset > 0)
210 {
211 if (num_frames - frame_idx > m_options.relative_frame_offset)
212 frame_idx += m_options.relative_frame_offset;
213 else
214 frame_idx = num_frames - 1;
215 }
216 }
217 else
218 {
219 if (command.GetArgumentCount() == 1)
220 {
221 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
222 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
223 }
224 else
225 {
226 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000227 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000228 }
229 }
230
231 if (frame_idx < num_frames)
232 {
233 exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
234 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000235
Greg Claytonc12b6b42010-10-10 22:28:11 +0000236 if (exe_ctx.frame)
237 {
238 bool already_shown = false;
239 SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
240 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000241 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000242 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
243 }
Jim Ingham74989e82010-08-30 19:44:40 +0000244
Greg Claytonabe0fed2011-04-18 08:33:37 +0000245 bool show_frame_info = true;
246 bool show_source = !already_shown;
247 uint32_t source_lines_before = 3;
248 uint32_t source_lines_after = 3;
249 if (exe_ctx.frame->GetStatus(result.GetOutputStream(),
250 show_frame_info,
251 show_source,
252 source_lines_before,
253 source_lines_after))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000254 {
255 result.SetStatus (eReturnStatusSuccessFinishResult);
256 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000257 }
258 }
Chris Lattner24943d22010-06-08 16:52:24 +0000259 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000260 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000261 }
262 else
263 {
264 result.AppendError ("no current thread");
265 }
266 result.SetStatus (eReturnStatusFailed);
267 return false;
268 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000269protected:
270
271 CommandOptions m_options;
272};
273
Greg Claytonb3448432011-03-24 21:19:54 +0000274OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000275CommandObjectFrameSelect::CommandOptions::g_option_table[] =
276{
277{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
278{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000279};
280
Jim Ingham537926c2010-09-02 00:18:39 +0000281#pragma mark CommandObjectFrameVariable
282//----------------------------------------------------------------------
283// List images with associated information
284//----------------------------------------------------------------------
285class CommandObjectFrameVariable : public CommandObject
286{
287public:
288
Jim Ingham10de7d12011-05-04 03:43:18 +0000289 class OptionGroupFrameVariable : public OptionGroup
Jim Ingham537926c2010-09-02 00:18:39 +0000290 {
291 public:
292
Jim Ingham10de7d12011-05-04 03:43:18 +0000293 OptionGroupFrameVariable ()
Jim Ingham537926c2010-09-02 00:18:39 +0000294 {
Jim Ingham537926c2010-09-02 00:18:39 +0000295 }
296
297 virtual
Jim Ingham10de7d12011-05-04 03:43:18 +0000298 ~OptionGroupFrameVariable ()
Jim Ingham537926c2010-09-02 00:18:39 +0000299 {
300 }
301
Jim Ingham10de7d12011-05-04 03:43:18 +0000302 virtual uint32_t
303 GetNumDefinitions ();
304
305 virtual const OptionDefinition*
306 GetDefinitions ()
307 {
308 return g_option_table;
309 }
310
Jim Ingham537926c2010-09-02 00:18:39 +0000311 virtual Error
Jim Ingham10de7d12011-05-04 03:43:18 +0000312 SetOptionValue (CommandInterpreter &interpreter,
313 uint32_t option_idx,
314 const char *option_arg)
Jim Ingham537926c2010-09-02 00:18:39 +0000315 {
316 Error error;
Jim Ingham10de7d12011-05-04 03:43:18 +0000317 char short_option = (char) g_option_table[option_idx].short_option;
Jim Ingham537926c2010-09-02 00:18:39 +0000318 switch (short_option)
319 {
Jim Ingham537926c2010-09-02 00:18:39 +0000320 case 'r': use_regex = true; break;
321 case 'a': show_args = false; break;
322 case 'l': show_locals = false; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000323 case 'g': show_globals = true; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000324 case 'c': show_decl = true; break;
Greg Clayton56bbdaf2011-04-28 20:55:26 +0000325 case 'f': error = Args::StringToFormat(option_arg, format, NULL); break;
Jim Ingham537926c2010-09-02 00:18:39 +0000326 case 'G':
Greg Claytonaed58812010-09-13 02:37:44 +0000327 globals.push_back(ConstString (option_arg));
Jim Ingham537926c2010-09-02 00:18:39 +0000328 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000329 case 's':
330 show_scope = true;
331 break;
332
333 default:
334 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
335 break;
336 }
337
338 return error;
339 }
340
Jim Ingham10de7d12011-05-04 03:43:18 +0000341 virtual void
342 OptionParsingStarting (CommandInterpreter &interpreter)
Jim Ingham537926c2010-09-02 00:18:39 +0000343 {
Jim Ingham537926c2010-09-02 00:18:39 +0000344 show_args = true;
Greg Claytonaed58812010-09-13 02:37:44 +0000345 show_decl = false;
Greg Claytonb1888f22011-03-19 01:12:21 +0000346 format = eFormatDefault;
Jim Ingham10de7d12011-05-04 03:43:18 +0000347 show_globals = false;
348 show_locals = true;
349 use_regex = false;
350 show_scope = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000351 globals.clear();
352 }
353
Jim Ingham537926c2010-09-02 00:18:39 +0000354 // Options table: Required for subclasses of Options.
355
Greg Claytonb3448432011-03-24 21:19:54 +0000356 static OptionDefinition g_option_table[];
Jim Ingham10de7d12011-05-04 03:43:18 +0000357
358 bool use_regex:1,
Greg Claytonaed58812010-09-13 02:37:44 +0000359 show_args:1,
360 show_locals:1,
361 show_globals:1,
Greg Claytonaed58812010-09-13 02:37:44 +0000362 show_scope:1,
Jim Ingham10de7d12011-05-04 03:43:18 +0000363 show_decl:1;
Greg Claytonb1888f22011-03-19 01:12:21 +0000364 lldb::Format format; // The format to use when dumping variables or children of variables
Jim Ingham537926c2010-09-02 00:18:39 +0000365 std::vector<ConstString> globals;
366 // Instance variables to hold the values for command options.
367 };
368
Greg Clayton238c0a12010-09-18 01:14:36 +0000369 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
370 CommandObject (interpreter,
371 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000372 "Show frame variables. All argument and local variables "
373 "that are in scope will be shown when no arguments are given. "
374 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000375 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000376 "Children of aggregate variables can be specified such as "
377 "'var->child.x'.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000378 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000379 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Jim Ingham10de7d12011-05-04 03:43:18 +0000380 m_option_group (interpreter),
381 m_frame_var_options(),
382 m_varobj_options()
Jim Ingham537926c2010-09-02 00:18:39 +0000383 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000384 CommandArgumentEntry arg;
385 CommandArgumentData var_name_arg;
386
387 // Define the first (and only) variant of this arg.
388 var_name_arg.arg_type = eArgTypeVarName;
389 var_name_arg.arg_repetition = eArgRepeatStar;
390
391 // There is only one variant this argument could be; put it into the argument entry.
392 arg.push_back (var_name_arg);
393
394 // Push the data for the first argument into the m_arguments vector.
395 m_arguments.push_back (arg);
Jim Ingham10de7d12011-05-04 03:43:18 +0000396
397 m_option_group.Append (&m_frame_var_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
398 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
399 m_option_group.Finalize();
Jim Ingham537926c2010-09-02 00:18:39 +0000400 }
401
402 virtual
403 ~CommandObjectFrameVariable ()
404 {
405 }
406
407 virtual
408 Options *
409 GetOptions ()
410 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000411 return &m_option_group;
Jim Ingham537926c2010-09-02 00:18:39 +0000412 }
413
Jim Ingham537926c2010-09-02 00:18:39 +0000414
415 virtual bool
416 Execute
417 (
Jim Ingham537926c2010-09-02 00:18:39 +0000418 Args& command,
419 CommandReturnObject &result
420 )
421 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000422 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000423 if (exe_ctx.frame == NULL)
424 {
Greg Claytonaa448052010-09-18 04:06:15 +0000425 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000426 result.SetStatus (eReturnStatusFailed);
427 return false;
428 }
429 else
430 {
Greg Claytonaed58812010-09-13 02:37:44 +0000431 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000432
Greg Claytonaed58812010-09-13 02:37:44 +0000433 bool get_file_globals = true;
434 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
435
Jim Ingham537926c2010-09-02 00:18:39 +0000436 VariableSP var_sp;
437 ValueObjectSP valobj_sp;
Jim Inghame41494a2011-04-16 00:01:13 +0000438
Jim Ingham537926c2010-09-02 00:18:39 +0000439 const char *name_cstr = NULL;
440 size_t idx;
Jim Ingham10de7d12011-05-04 03:43:18 +0000441 if (!m_frame_var_options.globals.empty())
Jim Ingham537926c2010-09-02 00:18:39 +0000442 {
443 uint32_t fail_count = 0;
444 if (exe_ctx.target)
445 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000446 const size_t num_globals = m_frame_var_options.globals.size();
Jim Ingham537926c2010-09-02 00:18:39 +0000447 for (idx = 0; idx < num_globals; ++idx)
448 {
449 VariableList global_var_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000450 const uint32_t num_matching_globals
Jim Ingham10de7d12011-05-04 03:43:18 +0000451 = exe_ctx.target->GetImages().FindGlobalVariables (m_frame_var_options.globals[idx],
Jim Inghame41494a2011-04-16 00:01:13 +0000452 true,
453 UINT32_MAX,
454 global_var_list);
Jim Ingham537926c2010-09-02 00:18:39 +0000455
456 if (num_matching_globals == 0)
457 {
458 ++fail_count;
Jim Inghame41494a2011-04-16 00:01:13 +0000459 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n",
Jim Ingham10de7d12011-05-04 03:43:18 +0000460 m_frame_var_options.globals[idx].AsCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000461 }
462 else
463 {
464 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
465 {
466 var_sp = global_var_list.GetVariableAtIndex(global_idx);
467 if (var_sp)
468 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000469 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp,
470 m_varobj_options.use_dynamic);
Jim Ingham537926c2010-09-02 00:18:39 +0000471 if (!valobj_sp)
Jim Ingham10de7d12011-05-04 03:43:18 +0000472 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp,
473 m_varobj_options.use_dynamic);
Jim Ingham537926c2010-09-02 00:18:39 +0000474
475 if (valobj_sp)
476 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000477 if (m_frame_var_options.format != eFormatDefault)
478 valobj_sp->SetFormat (m_frame_var_options.format);
Greg Claytonb1888f22011-03-19 01:12:21 +0000479
Jim Ingham10de7d12011-05-04 03:43:18 +0000480 if (m_frame_var_options.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytonaed58812010-09-13 02:37:44 +0000481 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000482 var_sp->GetDeclaration ().DumpStopContext (&s, false);
483 s.PutCString (": ");
Greg Claytonaed58812010-09-13 02:37:44 +0000484 }
Jim Inghame41494a2011-04-16 00:01:13 +0000485
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000486 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000487 valobj_sp.get(),
488 name_cstr,
Jim Ingham10de7d12011-05-04 03:43:18 +0000489 m_varobj_options.ptr_depth,
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000490 0,
Jim Ingham10de7d12011-05-04 03:43:18 +0000491 m_varobj_options.max_depth,
492 m_varobj_options.show_types,
493 m_varobj_options.show_location,
494 m_varobj_options.use_objc,
495 m_varobj_options.use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000496 false,
Jim Ingham10de7d12011-05-04 03:43:18 +0000497 m_varobj_options.flat_output);
Jim Ingham537926c2010-09-02 00:18:39 +0000498 }
499 }
500 }
501 }
502 }
503 }
504 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000505 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000506 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000507 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000508 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000509 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000510 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000511 VariableList regex_var_list;
512
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000513 // If we have any args to the variable command, we will make
514 // variable objects from them...
515 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000516 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000517 uint32_t ptr_depth = m_varobj_options.ptr_depth;
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000518
Jim Ingham10de7d12011-05-04 03:43:18 +0000519 if (m_frame_var_options.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000520 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000521 const uint32_t regex_start_index = regex_var_list.GetSize();
522 RegularExpression regex (name_cstr);
523 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000524 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000525 size_t num_matches = 0;
Jim Inghame41494a2011-04-16 00:01:13 +0000526 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
527 regex_var_list,
528 num_matches);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000529 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000530 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000531 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
532 regex_idx < end_index;
533 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000534 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000535 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
536 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000537 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000538 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000539 if (valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000540 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000541 if (m_frame_var_options.format != eFormatDefault)
542 valobj_sp->SetFormat (m_frame_var_options.format);
Greg Claytonb1888f22011-03-19 01:12:21 +0000543
Jim Ingham10de7d12011-05-04 03:43:18 +0000544 if (m_frame_var_options.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000545 {
546 var_sp->GetDeclaration ().DumpStopContext (&s, false);
547 s.PutCString (": ");
548 }
549
550 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000551 valobj_sp.get(),
552 var_sp->GetName().AsCString(),
Jim Ingham10de7d12011-05-04 03:43:18 +0000553 m_varobj_options.ptr_depth,
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000554 0,
Jim Ingham10de7d12011-05-04 03:43:18 +0000555 m_varobj_options.max_depth,
556 m_varobj_options.show_types,
557 m_varobj_options.show_location,
558 m_varobj_options.use_objc,
559 m_varobj_options.use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000560 false,
Jim Ingham10de7d12011-05-04 03:43:18 +0000561 m_varobj_options.flat_output);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000562 }
563 }
564 }
565 }
566 else if (num_matches == 0)
567 {
568 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
569 }
570 }
571 else
572 {
573 char regex_error[1024];
574 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
575 result.GetErrorStream().Printf ("error: %s\n", regex_error);
576 else
577 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
578 }
579 }
580 else
581 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000582 Error error;
Jim Inghame41494a2011-04-16 00:01:13 +0000583 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
Jim Ingham10de7d12011-05-04 03:43:18 +0000584 lldb::VariableSP var_sp;
585 valobj_sp = exe_ctx.frame->GetValueForVariableExpressionPath (name_cstr,
586 m_varobj_options.use_dynamic,
587 expr_path_options,
588 var_sp,
589 error);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000590 if (valobj_sp)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000591 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000592 if (m_frame_var_options.format != eFormatDefault)
593 valobj_sp->SetFormat (m_frame_var_options.format);
594 if (m_frame_var_options.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000595 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000596 var_sp->GetDeclaration ().DumpStopContext (&s, false);
597 s.PutCString (": ");
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000598 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000599 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Claytonc3b61d22010-12-15 05:08:08 +0000600 valobj_sp.get(),
601 valobj_sp->GetParent() ? name_cstr : NULL,
602 ptr_depth,
603 0,
Jim Ingham10de7d12011-05-04 03:43:18 +0000604 m_varobj_options.max_depth,
605 m_varobj_options.show_types,
606 m_varobj_options.show_location,
607 m_varobj_options.use_objc,
608 m_varobj_options.use_dynamic,
Greg Claytonc3b61d22010-12-15 05:08:08 +0000609 false,
Jim Ingham10de7d12011-05-04 03:43:18 +0000610 m_varobj_options.flat_output);
Greg Claytonaed58812010-09-13 02:37:44 +0000611 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000612 else
613 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000614 const char *error_cstr = error.AsCString(NULL);
615 if (error_cstr)
616 result.GetErrorStream().Printf("error: %s\n", error_cstr);
617 else
618 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000619 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000620 }
Jim Ingham537926c2010-09-02 00:18:39 +0000621 }
622 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000623 else
624 {
625 const uint32_t num_variables = variable_list->GetSize();
626
627 if (num_variables > 0)
628 {
629 for (uint32_t i=0; i<num_variables; i++)
630 {
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000631 var_sp = variable_list->GetVariableAtIndex(i);
Jim Inghame41494a2011-04-16 00:01:13 +0000632
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000633 bool dump_variable = true;
634
635 switch (var_sp->GetScope())
636 {
637 case eValueTypeVariableGlobal:
Jim Ingham10de7d12011-05-04 03:43:18 +0000638 dump_variable = m_frame_var_options.show_globals;
639 if (dump_variable && m_frame_var_options.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000640 s.PutCString("GLOBAL: ");
641 break;
642
643 case eValueTypeVariableStatic:
Jim Ingham10de7d12011-05-04 03:43:18 +0000644 dump_variable = m_frame_var_options.show_globals;
645 if (dump_variable && m_frame_var_options.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000646 s.PutCString("STATIC: ");
647 break;
648
649 case eValueTypeVariableArgument:
Jim Ingham10de7d12011-05-04 03:43:18 +0000650 dump_variable = m_frame_var_options.show_args;
651 if (dump_variable && m_frame_var_options.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000652 s.PutCString(" ARG: ");
653 break;
654
655 case eValueTypeVariableLocal:
Jim Ingham10de7d12011-05-04 03:43:18 +0000656 dump_variable = m_frame_var_options.show_locals;
657 if (dump_variable && m_frame_var_options.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000658 s.PutCString(" LOCAL: ");
659 break;
660
661 default:
662 break;
663 }
664
665 if (dump_variable)
666 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000667
668 // Use the variable object code to make sure we are
669 // using the same APIs as the the public API will be
670 // using...
Jim Ingham10de7d12011-05-04 03:43:18 +0000671 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp,
672 m_varobj_options.use_dynamic);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000673 if (valobj_sp)
674 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000675 if (m_frame_var_options.format != eFormatDefault)
676 valobj_sp->SetFormat (m_frame_var_options.format);
Greg Claytonb1888f22011-03-19 01:12:21 +0000677
Greg Claytona357ecf2010-09-14 03:16:58 +0000678 // When dumping all variables, don't print any variables
679 // that are not in scope to avoid extra unneeded output
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000680 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000681 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000682 if (m_frame_var_options.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytona357ecf2010-09-14 03:16:58 +0000683 {
684 var_sp->GetDeclaration ().DumpStopContext (&s, false);
685 s.PutCString (": ");
686 }
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000687 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000688 valobj_sp.get(),
689 name_cstr,
Jim Ingham10de7d12011-05-04 03:43:18 +0000690 m_varobj_options.ptr_depth,
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000691 0,
Jim Ingham10de7d12011-05-04 03:43:18 +0000692 m_varobj_options.max_depth,
693 m_varobj_options.show_types,
694 m_varobj_options.show_location,
695 m_varobj_options.use_objc,
696 m_varobj_options.use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000697 false,
Jim Ingham10de7d12011-05-04 03:43:18 +0000698 m_varobj_options.flat_output);
Greg Claytona357ecf2010-09-14 03:16:58 +0000699 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000700 }
701 }
702 }
703 }
704 }
705 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000706 }
Jim Ingham537926c2010-09-02 00:18:39 +0000707 }
708 return result.Succeeded();
709 }
710protected:
711
Jim Ingham10de7d12011-05-04 03:43:18 +0000712 OptionGroupOptions m_option_group;
713 OptionGroupFrameVariable m_frame_var_options;
714 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham537926c2010-09-02 00:18:39 +0000715};
716
Greg Claytonb3448432011-03-24 21:19:54 +0000717OptionDefinition
Jim Ingham10de7d12011-05-04 03:43:18 +0000718CommandObjectFrameVariable::OptionGroupFrameVariable::g_option_table[] =
Jim Ingham537926c2010-09-02 00:18:39 +0000719{
Jim Inghame41494a2011-04-16 00:01:13 +0000720{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
721{ LLDB_OPT_SET_1, false, "show-declaration",'c', no_argument, NULL, 0, eArgTypeNone, "Show variable declaration information (source file and line where the variable was declared)."},
Jim Inghame41494a2011-04-16 00:01:13 +0000722{ LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, eArgTypeExprFormat, "Specify the format that the variable output should use."},
Jim Inghame41494a2011-04-16 00:01:13 +0000723{ LLDB_OPT_SET_1, false, "show-globals", 'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
724{ LLDB_OPT_SET_1, false, "find-global", 'G', required_argument, NULL, 0, eArgTypeVarName, "Find a global variable by name (which might not be in the current stack frame source file)."},
Jim Inghame41494a2011-04-16 00:01:13 +0000725{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
Jim Inghame41494a2011-04-16 00:01:13 +0000726{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."},
727{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
Caroline Tice4d6675c2010-10-01 19:59:14 +0000728{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Jim Ingham537926c2010-09-02 00:18:39 +0000729};
Jim Ingham10de7d12011-05-04 03:43:18 +0000730
731uint32_t
732CommandObjectFrameVariable::OptionGroupFrameVariable::GetNumDefinitions ()
733{
734 return sizeof(CommandObjectFrameVariable::OptionGroupFrameVariable::g_option_table)/sizeof(OptionDefinition);
735}
736
737
Chris Lattner24943d22010-06-08 16:52:24 +0000738#pragma mark CommandObjectMultiwordFrame
739
740//-------------------------------------------------------------------------
741// CommandObjectMultiwordFrame
742//-------------------------------------------------------------------------
743
Greg Clayton63094e02010-06-23 01:19:29 +0000744CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000745 CommandObjectMultiword (interpreter,
746 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000747 "A set of commands for operating on the current thread's frames.",
748 "frame <subcommand> [<subcommand-options>]")
749{
Greg Clayton238c0a12010-09-18 01:14:36 +0000750 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
751 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
752 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000753}
754
755CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
756{
757}
758