blob: bdcd7039b999b64a0c8ad5d7435aa7088d4b6b9b [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 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 Claytonc12b6b42010-10-10 22:28:11 +0000246 if (DisplayFrameForExecutionContext (exe_ctx.thread,
247 exe_ctx.frame,
248 m_interpreter,
249 result.GetOutputStream(),
250 true,
251 !already_shown,
252 3,
253 3))
254 {
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
289 class CommandOptions : public Options
290 {
291 public:
292
Greg Claytonf15996e2011-04-07 22:46:35 +0000293 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000294 Options(interpreter)
Jim Ingham537926c2010-09-02 00:18:39 +0000295 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000296 OptionParsingStarting ();
Jim Ingham537926c2010-09-02 00:18:39 +0000297 }
298
299 virtual
300 ~CommandOptions ()
301 {
302 }
303
304 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000305 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Ingham537926c2010-09-02 00:18:39 +0000306 {
307 Error error;
308 bool success;
309 char short_option = (char) m_getopt_table[option_idx].val;
310 switch (short_option)
311 {
312 case 'o': use_objc = true; break;
Jim Inghame41494a2011-04-16 00:01:13 +0000313 case 'd':
314 {
315 bool success;
316 bool result;
317 result = Args::StringToBoolean(option_arg, true, &success);
318 if (!success)
319 error.SetErrorStringWithFormat("Invalid dynamic value setting: \"%s\".\n", option_arg);
320 else
321 {
322 if (result)
323 use_dynamic = eLazyBoolYes;
324 else
325 use_dynamic = eLazyBoolNo;
326 }
327 }
328 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000329 case 'r': use_regex = true; break;
330 case 'a': show_args = false; break;
331 case 'l': show_locals = false; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000332 case 'g': show_globals = true; break;
Greg Claytonb227e142010-10-13 18:56:36 +0000333 case 't': show_types = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000334 case 'y': show_summary = false; break;
335 case 'L': show_location= true; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000336 case 'c': show_decl = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000337 case 'D': debug = true; break;
Greg Claytonb1888f22011-03-19 01:12:21 +0000338 case 'f': error = Args::StringToFormat(option_arg, format); break;
339 case 'F': flat_output = true; break;
Jim Inghame41494a2011-04-16 00:01:13 +0000340 case 'A':
Jim Ingham537926c2010-09-02 00:18:39 +0000341 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
342 if (!success)
343 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
344 break;
345
346 case 'p':
347 ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
348 if (!success)
349 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
350 break;
351
352 case 'G':
Greg Claytonaed58812010-09-13 02:37:44 +0000353 globals.push_back(ConstString (option_arg));
Jim Ingham537926c2010-09-02 00:18:39 +0000354 break;
355
356 case 's':
357 show_scope = true;
358 break;
359
360 default:
361 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
362 break;
363 }
364
365 return error;
366 }
367
368 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000369 OptionParsingStarting ()
Jim Ingham537926c2010-09-02 00:18:39 +0000370 {
Jim Ingham537926c2010-09-02 00:18:39 +0000371 use_objc = false;
372 use_regex = false;
373 show_args = true;
374 show_locals = true;
Greg Claytonaed58812010-09-13 02:37:44 +0000375 show_globals = false;
Greg Claytonb227e142010-10-13 18:56:36 +0000376 show_types = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000377 show_scope = false;
378 show_summary = true;
379 show_location = false;
Greg Claytonaed58812010-09-13 02:37:44 +0000380 show_decl = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000381 debug = false;
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000382 flat_output = false;
Jim Inghame41494a2011-04-16 00:01:13 +0000383 use_dynamic = eLazyBoolCalculate;
Jim Ingham537926c2010-09-02 00:18:39 +0000384 max_depth = UINT32_MAX;
385 ptr_depth = 0;
Greg Claytonb1888f22011-03-19 01:12:21 +0000386 format = eFormatDefault;
Jim Ingham537926c2010-09-02 00:18:39 +0000387 globals.clear();
388 }
389
Greg Claytonb3448432011-03-24 21:19:54 +0000390 const OptionDefinition*
Jim Ingham537926c2010-09-02 00:18:39 +0000391 GetDefinitions ()
392 {
393 return g_option_table;
394 }
395
396 // Options table: Required for subclasses of Options.
397
Greg Claytonb3448432011-03-24 21:19:54 +0000398 static OptionDefinition g_option_table[];
Greg Claytonaed58812010-09-13 02:37:44 +0000399 bool use_objc:1,
400 use_regex:1,
401 show_args:1,
402 show_locals:1,
403 show_globals:1,
404 show_types:1,
405 show_scope:1,
406 show_summary:1,
407 show_location:1,
408 show_decl:1,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000409 debug:1,
410 flat_output:1;
Jim Inghame41494a2011-04-16 00:01:13 +0000411 LazyBool use_dynamic;
Jim Ingham537926c2010-09-02 00:18:39 +0000412 uint32_t max_depth; // The depth to print when dumping concrete (not pointers) aggreate values
413 uint32_t ptr_depth; // The default depth that is dumped when we find pointers
Greg Claytonb1888f22011-03-19 01:12:21 +0000414 lldb::Format format; // The format to use when dumping variables or children of variables
Jim Ingham537926c2010-09-02 00:18:39 +0000415 std::vector<ConstString> globals;
416 // Instance variables to hold the values for command options.
417 };
418
Greg Clayton238c0a12010-09-18 01:14:36 +0000419 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
420 CommandObject (interpreter,
421 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000422 "Show frame variables. All argument and local variables "
423 "that are in scope will be shown when no arguments are given. "
424 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000425 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000426 "Children of aggregate variables can be specified such as "
427 "'var->child.x'.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000428 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000429 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
430 m_options (interpreter)
Jim Ingham537926c2010-09-02 00:18:39 +0000431 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000432 CommandArgumentEntry arg;
433 CommandArgumentData var_name_arg;
434
435 // Define the first (and only) variant of this arg.
436 var_name_arg.arg_type = eArgTypeVarName;
437 var_name_arg.arg_repetition = eArgRepeatStar;
438
439 // There is only one variant this argument could be; put it into the argument entry.
440 arg.push_back (var_name_arg);
441
442 // Push the data for the first argument into the m_arguments vector.
443 m_arguments.push_back (arg);
Jim Ingham537926c2010-09-02 00:18:39 +0000444 }
445
446 virtual
447 ~CommandObjectFrameVariable ()
448 {
449 }
450
451 virtual
452 Options *
453 GetOptions ()
454 {
455 return &m_options;
456 }
457
Jim Ingham537926c2010-09-02 00:18:39 +0000458
459 virtual bool
460 Execute
461 (
Jim Ingham537926c2010-09-02 00:18:39 +0000462 Args& command,
463 CommandReturnObject &result
464 )
465 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000466 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000467 if (exe_ctx.frame == NULL)
468 {
Greg Claytonaa448052010-09-18 04:06:15 +0000469 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000470 result.SetStatus (eReturnStatusFailed);
471 return false;
472 }
473 else
474 {
Greg Claytonaed58812010-09-13 02:37:44 +0000475 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000476
Greg Claytonaed58812010-09-13 02:37:44 +0000477 bool get_file_globals = true;
478 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
479
Jim Ingham537926c2010-09-02 00:18:39 +0000480 VariableSP var_sp;
481 ValueObjectSP valobj_sp;
Jim Inghame41494a2011-04-16 00:01:13 +0000482
483 bool use_dynamic;
484
485 // If use dynamic is not set, get it from the target:
486 switch (m_options.use_dynamic)
487 {
488 case eLazyBoolCalculate:
489 {
490 if (exe_ctx.target->GetPreferDynamicValue())
491 use_dynamic = true;
492 else
493 use_dynamic = false;
494 }
495 break;
496 case eLazyBoolYes:
497 use_dynamic = true;
498 break;
499 case eLazyBoolNo:
500 use_dynamic = false;
501 break;
502 }
503
Jim Ingham537926c2010-09-02 00:18:39 +0000504 const char *name_cstr = NULL;
505 size_t idx;
506 if (!m_options.globals.empty())
507 {
508 uint32_t fail_count = 0;
509 if (exe_ctx.target)
510 {
511 const size_t num_globals = m_options.globals.size();
512 for (idx = 0; idx < num_globals; ++idx)
513 {
514 VariableList global_var_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000515 const uint32_t num_matching_globals
516 = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx],
517 true,
518 UINT32_MAX,
519 global_var_list);
Jim Ingham537926c2010-09-02 00:18:39 +0000520
521 if (num_matching_globals == 0)
522 {
523 ++fail_count;
Jim Inghame41494a2011-04-16 00:01:13 +0000524 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n",
525 m_options.globals[idx].AsCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000526 }
527 else
528 {
529 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
530 {
531 var_sp = global_var_list.GetVariableAtIndex(global_idx);
532 if (var_sp)
533 {
Jim Inghame41494a2011-04-16 00:01:13 +0000534 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham537926c2010-09-02 00:18:39 +0000535 if (!valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000536 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp, use_dynamic);
Jim Ingham537926c2010-09-02 00:18:39 +0000537
538 if (valobj_sp)
539 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000540 if (m_options.format != eFormatDefault)
541 valobj_sp->SetFormat (m_options.format);
542
Greg Claytonaed58812010-09-13 02:37:44 +0000543 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
544 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000545 var_sp->GetDeclaration ().DumpStopContext (&s, false);
546 s.PutCString (": ");
Greg Claytonaed58812010-09-13 02:37:44 +0000547 }
Jim Inghame41494a2011-04-16 00:01:13 +0000548
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000549 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000550 valobj_sp.get(),
551 name_cstr,
552 m_options.ptr_depth,
553 0,
554 m_options.max_depth,
555 m_options.show_types,
556 m_options.show_location,
Jim Inghame41494a2011-04-16 00:01:13 +0000557 m_options.use_objc,
558 use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000559 false,
560 m_options.flat_output);
Jim Ingham537926c2010-09-02 00:18:39 +0000561 }
562 }
563 }
564 }
565 }
566 }
567 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000568 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000569 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000570 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000571 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000572 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000573 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000574 VariableList regex_var_list;
575
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000576 // If we have any args to the variable command, we will make
577 // variable objects from them...
578 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000579 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000580 uint32_t ptr_depth = m_options.ptr_depth;
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000581
582 if (m_options.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000583 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000584 const uint32_t regex_start_index = regex_var_list.GetSize();
585 RegularExpression regex (name_cstr);
586 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000587 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000588 size_t num_matches = 0;
Jim Inghame41494a2011-04-16 00:01:13 +0000589 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
590 regex_var_list,
591 num_matches);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000592 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000593 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000594 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
595 regex_idx < end_index;
596 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000597 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000598 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
599 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000600 {
Jim Inghame41494a2011-04-16 00:01:13 +0000601 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, use_dynamic);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000602 if (valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000603 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000604 if (m_options.format != eFormatDefault)
605 valobj_sp->SetFormat (m_options.format);
606
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000607 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
608 {
609 var_sp->GetDeclaration ().DumpStopContext (&s, false);
610 s.PutCString (": ");
611 }
612
613 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000614 valobj_sp.get(),
615 var_sp->GetName().AsCString(),
616 m_options.ptr_depth,
617 0,
618 m_options.max_depth,
619 m_options.show_types,
620 m_options.show_location,
Jim Inghame41494a2011-04-16 00:01:13 +0000621 m_options.use_objc,
622 use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000623 false,
624 m_options.flat_output);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000625 }
626 }
627 }
628 }
629 else if (num_matches == 0)
630 {
631 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
632 }
633 }
634 else
635 {
636 char regex_error[1024];
637 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
638 result.GetErrorStream().Printf ("error: %s\n", regex_error);
639 else
640 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
641 }
642 }
643 else
644 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000645 Error error;
Jim Inghame41494a2011-04-16 00:01:13 +0000646 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
647 if (use_dynamic)
648 expr_path_options |= StackFrame::eExpressionPathOptionsDynamicValue;
649
Greg Claytonc67efa42011-01-20 19:27:18 +0000650 valobj_sp = exe_ctx.frame->GetValueForVariableExpressionPath (name_cstr, expr_path_options, error);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000651 if (valobj_sp)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000652 {
Jim Inghame41494a2011-04-16 00:01:13 +0000653// if (use_dynamic)
654// {
655// lldb::ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue(true, valobj_sp);
656// if (dynamic_sp != NULL)
657// valobj_sp = dynamic_sp;
658// }
659//
Greg Claytonb1888f22011-03-19 01:12:21 +0000660 if (m_options.format != eFormatDefault)
661 valobj_sp->SetFormat (m_options.format);
662
Greg Claytonc3b61d22010-12-15 05:08:08 +0000663 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000664 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000665 var_sp->GetDeclaration ().DumpStopContext (&s, false);
666 s.PutCString (": ");
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000667 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000668 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Claytonc3b61d22010-12-15 05:08:08 +0000669 valobj_sp.get(),
670 valobj_sp->GetParent() ? name_cstr : NULL,
671 ptr_depth,
672 0,
673 m_options.max_depth,
674 m_options.show_types,
675 m_options.show_location,
Jim Inghame41494a2011-04-16 00:01:13 +0000676 m_options.use_objc,
677 use_dynamic,
Greg Claytonc3b61d22010-12-15 05:08:08 +0000678 false,
679 m_options.flat_output);
Greg Claytonaed58812010-09-13 02:37:44 +0000680 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000681 else
682 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000683 const char *error_cstr = error.AsCString(NULL);
684 if (error_cstr)
685 result.GetErrorStream().Printf("error: %s\n", error_cstr);
686 else
687 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000688 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000689 }
Jim Ingham537926c2010-09-02 00:18:39 +0000690 }
691 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000692 else
693 {
694 const uint32_t num_variables = variable_list->GetSize();
695
696 if (num_variables > 0)
697 {
698 for (uint32_t i=0; i<num_variables; i++)
699 {
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000700 var_sp = variable_list->GetVariableAtIndex(i);
Jim Inghame41494a2011-04-16 00:01:13 +0000701
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000702 bool dump_variable = true;
703
704 switch (var_sp->GetScope())
705 {
706 case eValueTypeVariableGlobal:
707 dump_variable = m_options.show_globals;
708 if (dump_variable && m_options.show_scope)
709 s.PutCString("GLOBAL: ");
710 break;
711
712 case eValueTypeVariableStatic:
713 dump_variable = m_options.show_globals;
714 if (dump_variable && m_options.show_scope)
715 s.PutCString("STATIC: ");
716 break;
717
718 case eValueTypeVariableArgument:
719 dump_variable = m_options.show_args;
720 if (dump_variable && m_options.show_scope)
721 s.PutCString(" ARG: ");
722 break;
723
724 case eValueTypeVariableLocal:
725 dump_variable = m_options.show_locals;
726 if (dump_variable && m_options.show_scope)
727 s.PutCString(" LOCAL: ");
728 break;
729
730 default:
731 break;
732 }
733
734 if (dump_variable)
735 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000736
737 // Use the variable object code to make sure we are
738 // using the same APIs as the the public API will be
739 // using...
Jim Inghame41494a2011-04-16 00:01:13 +0000740 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, use_dynamic);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000741 if (valobj_sp)
742 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000743 if (m_options.format != eFormatDefault)
744 valobj_sp->SetFormat (m_options.format);
745
Greg Claytona357ecf2010-09-14 03:16:58 +0000746 // When dumping all variables, don't print any variables
747 // that are not in scope to avoid extra unneeded output
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000748 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000749 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000750 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
751 {
752 var_sp->GetDeclaration ().DumpStopContext (&s, false);
753 s.PutCString (": ");
754 }
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000755 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000756 valobj_sp.get(),
757 name_cstr,
758 m_options.ptr_depth,
759 0,
760 m_options.max_depth,
761 m_options.show_types,
762 m_options.show_location,
Jim Inghame41494a2011-04-16 00:01:13 +0000763 m_options.use_objc,
764 use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000765 false,
766 m_options.flat_output);
Greg Claytona357ecf2010-09-14 03:16:58 +0000767 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000768 }
769 }
770 }
771 }
772 }
773 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000774 }
Jim Ingham537926c2010-09-02 00:18:39 +0000775 }
776 return result.Succeeded();
777 }
778protected:
779
780 CommandOptions m_options;
781};
782
Greg Claytonb3448432011-03-24 21:19:54 +0000783OptionDefinition
Jim Ingham537926c2010-09-02 00:18:39 +0000784CommandObjectFrameVariable::CommandOptions::g_option_table[] =
785{
Jim Inghame41494a2011-04-16 00:01:13 +0000786{ LLDB_OPT_SET_1, false, "aggregate-depth", 'A', required_argument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."},
787{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
788{ 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)."},
789{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, eArgTypeNone, "Enable verbose debug information."},
790{ LLDB_OPT_SET_1, false, "dynamic-type", 'd', required_argument, NULL, 0, eArgTypeBoolean, "Show the object as its full dynamic type, not its static type, if available."},
791{ LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, eArgTypeExprFormat, "Specify the format that the variable output should use."},
792{ 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."},
793{ LLDB_OPT_SET_1, false, "show-globals", 'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
794{ 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)."},
795{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, eArgTypeNone, "Show variable location information."},
796{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
797{ 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."},
798{ 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)."},
799{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."},
800{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
801{ LLDB_OPT_SET_1, false, "show-types", 't', no_argument, NULL, 0, eArgTypeNone, "Show variable types when dumping values."},
802{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, eArgTypeNone, "Omit summary information."},
Caroline Tice4d6675c2010-10-01 19:59:14 +0000803{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Jim Ingham537926c2010-09-02 00:18:39 +0000804};
Chris Lattner24943d22010-06-08 16:52:24 +0000805#pragma mark CommandObjectMultiwordFrame
806
807//-------------------------------------------------------------------------
808// CommandObjectMultiwordFrame
809//-------------------------------------------------------------------------
810
Greg Clayton63094e02010-06-23 01:19:29 +0000811CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000812 CommandObjectMultiword (interpreter,
813 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000814 "A set of commands for operating on the current thread's frames.",
815 "frame <subcommand> [<subcommand-options>]")
816{
Greg Clayton238c0a12010-09-18 01:14:36 +0000817 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
818 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
819 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000820}
821
822CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
823{
824}
825