blob: 25f7638ef7d682cca67e701936d4fb8e1ac61850 [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"
28#include "lldb/Symbol/ClangASTType.h"
29#include "lldb/Symbol/ClangASTContext.h"
30#include "lldb/Symbol/ObjectFile.h"
31#include "lldb/Symbol/SymbolContext.h"
32#include "lldb/Symbol/Type.h"
33#include "lldb/Symbol/Variable.h"
34#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000035#include "lldb/Target/Process.h"
36#include "lldb/Target/StackFrame.h"
37#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000038#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000039
40#include "CommandObjectThread.h"
41
42using 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 Clayton238c0a12010-09-18 01:14:36 +000072 ExecutionContext exe_ctx(m_interpreter.GetDebugger().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
102 CommandOptions () :
103 Options()
104 {
105 ResetOptionValues ();
106 }
107
108 virtual
109 ~CommandOptions ()
110 {
111 }
112
113 virtual Error
114 SetOptionValue (int option_idx, const char *option_arg)
115 {
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
136 ResetOptionValues ()
137 {
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 Clayton238c0a12010-09-18 01:14:36 +0000158 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
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 Clayton238c0a12010-09-18 01:14:36 +0000190 ExecutionContext exe_ctx (m_interpreter.GetDebugger().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");
227 m_options.GenerateOptionUsage (m_interpreter, result.GetErrorStream(), this);
228 }
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 Claytonc12b6b42010-10-10 22:28:11 +0000245 if (DisplayFrameForExecutionContext (exe_ctx.thread,
246 exe_ctx.frame,
247 m_interpreter,
248 result.GetOutputStream(),
249 true,
250 !already_shown,
251 3,
252 3))
253 {
254 result.SetStatus (eReturnStatusSuccessFinishResult);
255 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000256 }
257 }
Chris Lattner24943d22010-06-08 16:52:24 +0000258 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000259 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000260 }
261 else
262 {
263 result.AppendError ("no current thread");
264 }
265 result.SetStatus (eReturnStatusFailed);
266 return false;
267 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000268protected:
269
270 CommandOptions m_options;
271};
272
Greg Claytonb3448432011-03-24 21:19:54 +0000273OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000274CommandObjectFrameSelect::CommandOptions::g_option_table[] =
275{
276{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
277{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000278};
279
Jim Ingham537926c2010-09-02 00:18:39 +0000280#pragma mark CommandObjectFrameVariable
281//----------------------------------------------------------------------
282// List images with associated information
283//----------------------------------------------------------------------
284class CommandObjectFrameVariable : public CommandObject
285{
286public:
287
288 class CommandOptions : public Options
289 {
290 public:
291
292 CommandOptions () :
293 Options()
294 {
295 ResetOptionValues ();
296 }
297
298 virtual
299 ~CommandOptions ()
300 {
301 }
302
303 virtual Error
304 SetOptionValue (int option_idx, const char *option_arg)
305 {
306 Error error;
307 bool success;
308 char short_option = (char) m_getopt_table[option_idx].val;
309 switch (short_option)
310 {
311 case 'o': use_objc = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000312 case 'r': use_regex = true; break;
313 case 'a': show_args = false; break;
314 case 'l': show_locals = false; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000315 case 'g': show_globals = true; break;
Greg Claytonb227e142010-10-13 18:56:36 +0000316 case 't': show_types = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000317 case 'y': show_summary = false; break;
318 case 'L': show_location= true; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000319 case 'c': show_decl = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000320 case 'D': debug = true; break;
Greg Claytonb1888f22011-03-19 01:12:21 +0000321 case 'f': error = Args::StringToFormat(option_arg, format); break;
322 case 'F': flat_output = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000323 case 'd':
324 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
325 if (!success)
326 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
327 break;
328
329 case 'p':
330 ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
331 if (!success)
332 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
333 break;
334
335 case 'G':
Greg Claytonaed58812010-09-13 02:37:44 +0000336 globals.push_back(ConstString (option_arg));
Jim Ingham537926c2010-09-02 00:18:39 +0000337 break;
338
339 case 's':
340 show_scope = true;
341 break;
342
343 default:
344 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
345 break;
346 }
347
348 return error;
349 }
350
351 void
352 ResetOptionValues ()
353 {
Jim Ingham537926c2010-09-02 00:18:39 +0000354 use_objc = false;
355 use_regex = false;
356 show_args = true;
357 show_locals = true;
Greg Claytonaed58812010-09-13 02:37:44 +0000358 show_globals = false;
Greg Claytonb227e142010-10-13 18:56:36 +0000359 show_types = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000360 show_scope = false;
361 show_summary = true;
362 show_location = false;
Greg Claytonaed58812010-09-13 02:37:44 +0000363 show_decl = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000364 debug = false;
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000365 flat_output = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000366 max_depth = UINT32_MAX;
367 ptr_depth = 0;
Greg Claytonb1888f22011-03-19 01:12:21 +0000368 format = eFormatDefault;
Jim Ingham537926c2010-09-02 00:18:39 +0000369 globals.clear();
370 }
371
Greg Claytonb3448432011-03-24 21:19:54 +0000372 const OptionDefinition*
Jim Ingham537926c2010-09-02 00:18:39 +0000373 GetDefinitions ()
374 {
375 return g_option_table;
376 }
377
378 // Options table: Required for subclasses of Options.
379
Greg Claytonb3448432011-03-24 21:19:54 +0000380 static OptionDefinition g_option_table[];
Greg Claytonaed58812010-09-13 02:37:44 +0000381 bool use_objc:1,
382 use_regex:1,
383 show_args:1,
384 show_locals:1,
385 show_globals:1,
386 show_types:1,
387 show_scope:1,
388 show_summary:1,
389 show_location:1,
390 show_decl:1,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000391 debug:1,
392 flat_output:1;
Jim Ingham537926c2010-09-02 00:18:39 +0000393 uint32_t max_depth; // The depth to print when dumping concrete (not pointers) aggreate values
394 uint32_t ptr_depth; // The default depth that is dumped when we find pointers
Greg Claytonb1888f22011-03-19 01:12:21 +0000395 lldb::Format format; // The format to use when dumping variables or children of variables
Jim Ingham537926c2010-09-02 00:18:39 +0000396 std::vector<ConstString> globals;
397 // Instance variables to hold the values for command options.
398 };
399
Greg Clayton238c0a12010-09-18 01:14:36 +0000400 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
401 CommandObject (interpreter,
402 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000403 "Show frame variables. All argument and local variables "
404 "that are in scope will be shown when no arguments are given. "
405 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000406 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000407 "Children of aggregate variables can be specified such as "
408 "'var->child.x'.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000409 NULL,
410 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Jim Ingham537926c2010-09-02 00:18:39 +0000411 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000412 CommandArgumentEntry arg;
413 CommandArgumentData var_name_arg;
414
415 // Define the first (and only) variant of this arg.
416 var_name_arg.arg_type = eArgTypeVarName;
417 var_name_arg.arg_repetition = eArgRepeatStar;
418
419 // There is only one variant this argument could be; put it into the argument entry.
420 arg.push_back (var_name_arg);
421
422 // Push the data for the first argument into the m_arguments vector.
423 m_arguments.push_back (arg);
Jim Ingham537926c2010-09-02 00:18:39 +0000424 }
425
426 virtual
427 ~CommandObjectFrameVariable ()
428 {
429 }
430
431 virtual
432 Options *
433 GetOptions ()
434 {
435 return &m_options;
436 }
437
Jim Ingham537926c2010-09-02 00:18:39 +0000438
439 virtual bool
440 Execute
441 (
Jim Ingham537926c2010-09-02 00:18:39 +0000442 Args& command,
443 CommandReturnObject &result
444 )
445 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000446 ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000447 if (exe_ctx.frame == NULL)
448 {
Greg Claytonaa448052010-09-18 04:06:15 +0000449 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000450 result.SetStatus (eReturnStatusFailed);
451 return false;
452 }
453 else
454 {
Greg Claytonaed58812010-09-13 02:37:44 +0000455 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000456
Greg Claytonaed58812010-09-13 02:37:44 +0000457 bool get_file_globals = true;
458 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
459
Jim Ingham537926c2010-09-02 00:18:39 +0000460 VariableSP var_sp;
461 ValueObjectSP valobj_sp;
462 //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList();
463 const char *name_cstr = NULL;
464 size_t idx;
465 if (!m_options.globals.empty())
466 {
467 uint32_t fail_count = 0;
468 if (exe_ctx.target)
469 {
470 const size_t num_globals = m_options.globals.size();
471 for (idx = 0; idx < num_globals; ++idx)
472 {
473 VariableList global_var_list;
474 const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list);
475
476 if (num_matching_globals == 0)
477 {
478 ++fail_count;
479 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString());
480 }
481 else
482 {
483 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
484 {
485 var_sp = global_var_list.GetVariableAtIndex(global_idx);
486 if (var_sp)
487 {
Greg Clayton17dae082010-09-02 02:59:18 +0000488 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000489 if (!valobj_sp)
Greg Clayton17dae082010-09-02 02:59:18 +0000490 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000491
492 if (valobj_sp)
493 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000494 if (m_options.format != eFormatDefault)
495 valobj_sp->SetFormat (m_options.format);
496
Greg Claytonaed58812010-09-13 02:37:44 +0000497 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
498 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000499 var_sp->GetDeclaration ().DumpStopContext (&s, false);
500 s.PutCString (": ");
Greg Claytonaed58812010-09-13 02:37:44 +0000501 }
502
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000503 ValueObject::DumpValueObject (result.GetOutputStream(),
504 exe_ctx.frame,
505 valobj_sp.get(),
506 name_cstr,
507 m_options.ptr_depth,
508 0,
509 m_options.max_depth,
510 m_options.show_types,
511 m_options.show_location,
512 m_options.use_objc,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000513 false,
514 m_options.flat_output);
Jim Ingham537926c2010-09-02 00:18:39 +0000515 }
516 }
517 }
518 }
519 }
520 }
521 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000522 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000523 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000524 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000525 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000526 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000527 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000528 VariableList regex_var_list;
529
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000530 // If we have any args to the variable command, we will make
531 // variable objects from them...
532 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000533 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000534 uint32_t ptr_depth = m_options.ptr_depth;
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000535
536 if (m_options.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000537 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000538 const uint32_t regex_start_index = regex_var_list.GetSize();
539 RegularExpression regex (name_cstr);
540 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000541 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000542 size_t num_matches = 0;
543 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex, regex_var_list, num_matches);
544 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000545 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000546 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
547 regex_idx < end_index;
548 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000549 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000550 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
551 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000552 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000553 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
554 if (valobj_sp)
555 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000556 if (m_options.format != eFormatDefault)
557 valobj_sp->SetFormat (m_options.format);
558
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000559 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
560 {
561 var_sp->GetDeclaration ().DumpStopContext (&s, false);
562 s.PutCString (": ");
563 }
564
565 ValueObject::DumpValueObject (result.GetOutputStream(),
566 exe_ctx.frame,
567 valobj_sp.get(),
568 var_sp->GetName().AsCString(),
569 m_options.ptr_depth,
570 0,
571 m_options.max_depth,
572 m_options.show_types,
573 m_options.show_location,
574 m_options.use_objc,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000575 false,
576 m_options.flat_output);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000577 }
578 }
579 }
580 }
581 else if (num_matches == 0)
582 {
583 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
584 }
585 }
586 else
587 {
588 char regex_error[1024];
589 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
590 result.GetErrorStream().Printf ("error: %s\n", regex_error);
591 else
592 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
593 }
594 }
595 else
596 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000597 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +0000598 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
599 valobj_sp = exe_ctx.frame->GetValueForVariableExpressionPath (name_cstr, expr_path_options, error);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000600 if (valobj_sp)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000601 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000602 if (m_options.format != eFormatDefault)
603 valobj_sp->SetFormat (m_options.format);
604
Greg Claytonc3b61d22010-12-15 05:08:08 +0000605 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000606 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000607 var_sp->GetDeclaration ().DumpStopContext (&s, false);
608 s.PutCString (": ");
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000609 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000610 ValueObject::DumpValueObject (result.GetOutputStream(),
611 exe_ctx.frame,
612 valobj_sp.get(),
613 valobj_sp->GetParent() ? name_cstr : NULL,
614 ptr_depth,
615 0,
616 m_options.max_depth,
617 m_options.show_types,
618 m_options.show_location,
619 m_options.use_objc,
620 false,
621 m_options.flat_output);
Greg Claytonaed58812010-09-13 02:37:44 +0000622 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000623 else
624 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000625 const char *error_cstr = error.AsCString(NULL);
626 if (error_cstr)
627 result.GetErrorStream().Printf("error: %s\n", error_cstr);
628 else
629 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000630 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000631 }
Jim Ingham537926c2010-09-02 00:18:39 +0000632 }
633 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000634 else
635 {
636 const uint32_t num_variables = variable_list->GetSize();
637
638 if (num_variables > 0)
639 {
640 for (uint32_t i=0; i<num_variables; i++)
641 {
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000642 var_sp = variable_list->GetVariableAtIndex(i);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000643 bool dump_variable = true;
644
645 switch (var_sp->GetScope())
646 {
647 case eValueTypeVariableGlobal:
648 dump_variable = m_options.show_globals;
649 if (dump_variable && m_options.show_scope)
650 s.PutCString("GLOBAL: ");
651 break;
652
653 case eValueTypeVariableStatic:
654 dump_variable = m_options.show_globals;
655 if (dump_variable && m_options.show_scope)
656 s.PutCString("STATIC: ");
657 break;
658
659 case eValueTypeVariableArgument:
660 dump_variable = m_options.show_args;
661 if (dump_variable && m_options.show_scope)
662 s.PutCString(" ARG: ");
663 break;
664
665 case eValueTypeVariableLocal:
666 dump_variable = m_options.show_locals;
667 if (dump_variable && m_options.show_scope)
668 s.PutCString(" LOCAL: ");
669 break;
670
671 default:
672 break;
673 }
674
675 if (dump_variable)
676 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000677
678 // Use the variable object code to make sure we are
679 // using the same APIs as the the public API will be
680 // using...
681 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
682 if (valobj_sp)
683 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000684 if (m_options.format != eFormatDefault)
685 valobj_sp->SetFormat (m_options.format);
686
Greg Claytona357ecf2010-09-14 03:16:58 +0000687 // When dumping all variables, don't print any variables
688 // that are not in scope to avoid extra unneeded output
689 if (valobj_sp->IsInScope (exe_ctx.frame))
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000690 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000691 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
692 {
693 var_sp->GetDeclaration ().DumpStopContext (&s, false);
694 s.PutCString (": ");
695 }
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000696 ValueObject::DumpValueObject (result.GetOutputStream(),
697 exe_ctx.frame,
698 valobj_sp.get(),
699 name_cstr,
700 m_options.ptr_depth,
701 0,
702 m_options.max_depth,
703 m_options.show_types,
704 m_options.show_location,
705 m_options.use_objc,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000706 false,
707 m_options.flat_output);
Greg Claytona357ecf2010-09-14 03:16:58 +0000708 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000709 }
710 }
711 }
712 }
713 }
714 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000715 }
Jim Ingham537926c2010-09-02 00:18:39 +0000716 }
717 return result.Succeeded();
718 }
719protected:
720
721 CommandOptions m_options;
722};
723
Greg Claytonb3448432011-03-24 21:19:54 +0000724OptionDefinition
Jim Ingham537926c2010-09-02 00:18:39 +0000725CommandObjectFrameVariable::CommandOptions::g_option_table[] =
726{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000727{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, eArgTypeNone, "Enable verbose debug information."},
728{ LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."},
729{ LLDB_OPT_SET_1, false, "show-globals",'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
730{ 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)."},
731{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, eArgTypeNone, "Show variable location information."},
732{ 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)."},
Caroline Tice4d6675c2010-10-01 19:59:14 +0000733{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
734{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
Greg Claytonb227e142010-10-13 18:56:36 +0000735{ LLDB_OPT_SET_1, false, "show-types", 't', no_argument, NULL, 0, eArgTypeNone, "Show variable types when dumping values."},
Caroline Tice4d6675c2010-10-01 19:59:14 +0000736{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, eArgTypeNone, "Omit summary information."},
737{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
Greg Clayton9bd7e352010-10-28 00:56:11 +0000738{ LLDB_OPT_SET_1, false, "objc", 'o', no_argument, NULL, 0, eArgTypeNone, "When looking up a variable by name, print as an Objective-C object."},
Caroline Tice4d6675c2010-10-01 19:59:14 +0000739{ LLDB_OPT_SET_1, false, "ptr-depth", 'p', required_argument, NULL, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."},
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000740{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."},
Greg Claytonb1888f22011-03-19 01:12:21 +0000741{ LLDB_OPT_SET_1, false, "flat", 'F', no_argument, NULL, 0, eArgTypeNone, "Display results in a flat format that uses expression paths for each variable or member."},
742{ LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, eArgTypeExprFormat, "Specify the format that the variable output should use."},
Caroline Tice4d6675c2010-10-01 19:59:14 +0000743{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Jim Ingham537926c2010-09-02 00:18:39 +0000744};
Chris Lattner24943d22010-06-08 16:52:24 +0000745#pragma mark CommandObjectMultiwordFrame
746
747//-------------------------------------------------------------------------
748// CommandObjectMultiwordFrame
749//-------------------------------------------------------------------------
750
Greg Clayton63094e02010-06-23 01:19:29 +0000751CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000752 CommandObjectMultiword (interpreter,
753 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000754 "A set of commands for operating on the current thread's frames.",
755 "frame <subcommand> [<subcommand-options>]")
756{
Greg Clayton238c0a12010-09-18 01:14:36 +0000757 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
758 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
759 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000760}
761
762CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
763{
764}
765