blob: 6521416536036abd73bd1551d471e9c770721dcf [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
Chris Lattner24943d22010-06-08 16:52:24 +000040using namespace lldb;
41using namespace lldb_private;
42
43#pragma mark CommandObjectFrameInfo
44
45//-------------------------------------------------------------------------
46// CommandObjectFrameInfo
47//-------------------------------------------------------------------------
48
49class CommandObjectFrameInfo : public CommandObject
50{
51public:
52
Greg Clayton238c0a12010-09-18 01:14:36 +000053 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
54 CommandObject (interpreter,
55 "frame info",
56 "List information about the currently selected frame in the current thread.",
57 "frame info",
58 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000059 {
60 }
61
62 ~CommandObjectFrameInfo ()
63 {
64 }
65
66 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000067 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000068 CommandReturnObject &result)
69 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000070 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +000071 if (exe_ctx.frame)
72 {
Greg Claytona830adb2010-10-04 01:05:56 +000073 exe_ctx.frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000074 result.GetOutputStream().EOL();
75 result.SetStatus (eReturnStatusSuccessFinishResult);
76 }
77 else
78 {
79 result.AppendError ("no current frame");
80 result.SetStatus (eReturnStatusFailed);
81 }
82 return result.Succeeded();
83 }
84};
85
86#pragma mark CommandObjectFrameSelect
87
88//-------------------------------------------------------------------------
89// CommandObjectFrameSelect
90//-------------------------------------------------------------------------
91
92class CommandObjectFrameSelect : public CommandObject
93{
94public:
95
Greg Claytonc12b6b42010-10-10 22:28:11 +000096 class CommandOptions : public Options
97 {
98 public:
99
Greg Claytonf15996e2011-04-07 22:46:35 +0000100 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000101 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000102 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000103 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000104 }
105
106 virtual
107 ~CommandOptions ()
108 {
109 }
110
111 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000112 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000113 {
114 Error error;
115 bool success = false;
116 char short_option = (char) m_getopt_table[option_idx].val;
117 switch (short_option)
118 {
119 case 'r':
120 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
121 if (!success)
122 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg);
123 break;
124
125 default:
Benjamin Kramerfddc25a2010-11-10 20:16:47 +0000126 error.SetErrorStringWithFormat ("Invalid short option character '%c'.\n", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000127 break;
128 }
129
130 return error;
131 }
132
133 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000134 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000135 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000136 relative_frame_offset = INT32_MIN;
137 }
138
Greg Claytonb3448432011-03-24 21:19:54 +0000139 const OptionDefinition*
Greg Claytonc12b6b42010-10-10 22:28:11 +0000140 GetDefinitions ()
141 {
142 return g_option_table;
143 }
144
145 // Options table: Required for subclasses of Options.
146
Greg Claytonb3448432011-03-24 21:19:54 +0000147 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000148 int32_t relative_frame_offset;
149 };
150
Greg Clayton238c0a12010-09-18 01:14:36 +0000151 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
152 CommandObject (interpreter,
153 "frame select",
154 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000155 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000156 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
157 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000158 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000159 CommandArgumentEntry arg;
160 CommandArgumentData index_arg;
161
162 // Define the first (and only) variant of this arg.
163 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000164 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000165
166 // There is only one variant this argument could be; put it into the argument entry.
167 arg.push_back (index_arg);
168
169 // Push the data for the first argument into the m_arguments vector.
170 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000171 }
172
173 ~CommandObjectFrameSelect ()
174 {
175 }
176
Greg Claytonc12b6b42010-10-10 22:28:11 +0000177 virtual
178 Options *
179 GetOptions ()
180 {
181 return &m_options;
182 }
183
184
Chris Lattner24943d22010-06-08 16:52:24 +0000185 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000186 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000187 CommandReturnObject &result)
188 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000189 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000190 if (exe_ctx.thread)
191 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000192 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
193 uint32_t frame_idx = UINT32_MAX;
194 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000195 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000196 // The one and only argument is a signed relative frame index
197 frame_idx = exe_ctx.thread->GetSelectedFrameIndex ();
198 if (frame_idx == UINT32_MAX)
199 frame_idx = 0;
200
201 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000202 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000203 if (frame_idx >= -m_options.relative_frame_offset)
204 frame_idx += m_options.relative_frame_offset;
205 else
206 frame_idx = 0;
207 }
208 else if (m_options.relative_frame_offset > 0)
209 {
210 if (num_frames - frame_idx > m_options.relative_frame_offset)
211 frame_idx += m_options.relative_frame_offset;
212 else
213 frame_idx = num_frames - 1;
214 }
215 }
216 else
217 {
218 if (command.GetArgumentCount() == 1)
219 {
220 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
221 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
222 }
223 else
224 {
225 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000226 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000227 }
228 }
229
230 if (frame_idx < num_frames)
231 {
232 exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
233 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000234
Greg Claytonc12b6b42010-10-10 22:28:11 +0000235 if (exe_ctx.frame)
236 {
237 bool already_shown = false;
238 SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
239 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000240 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000241 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
242 }
Jim Ingham74989e82010-08-30 19:44:40 +0000243
Greg Claytonabe0fed2011-04-18 08:33:37 +0000244 bool show_frame_info = true;
245 bool show_source = !already_shown;
246 uint32_t source_lines_before = 3;
247 uint32_t source_lines_after = 3;
248 if (exe_ctx.frame->GetStatus(result.GetOutputStream(),
249 show_frame_info,
250 show_source,
251 source_lines_before,
252 source_lines_after))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000253 {
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
Greg Claytonf15996e2011-04-07 22:46:35 +0000292 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000293 Options(interpreter)
Jim Ingham537926c2010-09-02 00:18:39 +0000294 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000295 OptionParsingStarting ();
Jim Ingham537926c2010-09-02 00:18:39 +0000296 }
297
298 virtual
299 ~CommandOptions ()
300 {
301 }
302
303 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000304 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Ingham537926c2010-09-02 00:18:39 +0000305 {
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 Inghame41494a2011-04-16 00:01:13 +0000312 case 'd':
313 {
314 bool success;
315 bool result;
316 result = Args::StringToBoolean(option_arg, true, &success);
317 if (!success)
318 error.SetErrorStringWithFormat("Invalid dynamic value setting: \"%s\".\n", option_arg);
319 else
320 {
321 if (result)
322 use_dynamic = eLazyBoolYes;
323 else
324 use_dynamic = eLazyBoolNo;
325 }
326 }
327 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000328 case 'r': use_regex = true; break;
329 case 'a': show_args = false; break;
330 case 'l': show_locals = false; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000331 case 'g': show_globals = true; break;
Greg Claytonb227e142010-10-13 18:56:36 +0000332 case 't': show_types = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000333 case 'y': show_summary = false; break;
334 case 'L': show_location= true; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000335 case 'c': show_decl = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000336 case 'D': debug = true; break;
Greg Clayton56bbdaf2011-04-28 20:55:26 +0000337 case 'f': error = Args::StringToFormat(option_arg, format, NULL); break;
Greg Claytonb1888f22011-03-19 01:12:21 +0000338 case 'F': flat_output = true; break;
Jim Inghame41494a2011-04-16 00:01:13 +0000339 case 'A':
Jim Ingham537926c2010-09-02 00:18:39 +0000340 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
341 if (!success)
342 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
343 break;
344
345 case 'p':
346 ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
347 if (!success)
348 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
349 break;
350
351 case 'G':
Greg Claytonaed58812010-09-13 02:37:44 +0000352 globals.push_back(ConstString (option_arg));
Jim Ingham537926c2010-09-02 00:18:39 +0000353 break;
354
355 case 's':
356 show_scope = true;
357 break;
358
359 default:
360 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
361 break;
362 }
363
364 return error;
365 }
366
367 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000368 OptionParsingStarting ()
Jim Ingham537926c2010-09-02 00:18:39 +0000369 {
Jim Ingham537926c2010-09-02 00:18:39 +0000370 use_objc = false;
371 use_regex = false;
372 show_args = true;
373 show_locals = true;
Greg Claytonaed58812010-09-13 02:37:44 +0000374 show_globals = false;
Greg Claytonb227e142010-10-13 18:56:36 +0000375 show_types = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000376 show_scope = false;
377 show_summary = true;
378 show_location = false;
Greg Claytonaed58812010-09-13 02:37:44 +0000379 show_decl = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000380 debug = false;
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000381 flat_output = false;
Jim Inghame41494a2011-04-16 00:01:13 +0000382 use_dynamic = eLazyBoolCalculate;
Jim Ingham537926c2010-09-02 00:18:39 +0000383 max_depth = UINT32_MAX;
384 ptr_depth = 0;
Greg Claytonb1888f22011-03-19 01:12:21 +0000385 format = eFormatDefault;
Jim Ingham537926c2010-09-02 00:18:39 +0000386 globals.clear();
387 }
388
Greg Claytonb3448432011-03-24 21:19:54 +0000389 const OptionDefinition*
Jim Ingham537926c2010-09-02 00:18:39 +0000390 GetDefinitions ()
391 {
392 return g_option_table;
393 }
394
395 // Options table: Required for subclasses of Options.
396
Greg Claytonb3448432011-03-24 21:19:54 +0000397 static OptionDefinition g_option_table[];
Greg Claytonaed58812010-09-13 02:37:44 +0000398 bool use_objc:1,
399 use_regex:1,
400 show_args:1,
401 show_locals:1,
402 show_globals:1,
403 show_types:1,
404 show_scope:1,
405 show_summary:1,
406 show_location:1,
407 show_decl:1,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000408 debug:1,
409 flat_output:1;
Jim Inghame41494a2011-04-16 00:01:13 +0000410 LazyBool use_dynamic;
Jim Ingham537926c2010-09-02 00:18:39 +0000411 uint32_t max_depth; // The depth to print when dumping concrete (not pointers) aggreate values
412 uint32_t ptr_depth; // The default depth that is dumped when we find pointers
Greg Claytonb1888f22011-03-19 01:12:21 +0000413 lldb::Format format; // The format to use when dumping variables or children of variables
Jim Ingham537926c2010-09-02 00:18:39 +0000414 std::vector<ConstString> globals;
415 // Instance variables to hold the values for command options.
416 };
417
Greg Clayton238c0a12010-09-18 01:14:36 +0000418 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
419 CommandObject (interpreter,
420 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000421 "Show frame variables. All argument and local variables "
422 "that are in scope will be shown when no arguments are given. "
423 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000424 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000425 "Children of aggregate variables can be specified such as "
426 "'var->child.x'.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000427 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000428 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
429 m_options (interpreter)
Jim Ingham537926c2010-09-02 00:18:39 +0000430 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000431 CommandArgumentEntry arg;
432 CommandArgumentData var_name_arg;
433
434 // Define the first (and only) variant of this arg.
435 var_name_arg.arg_type = eArgTypeVarName;
436 var_name_arg.arg_repetition = eArgRepeatStar;
437
438 // There is only one variant this argument could be; put it into the argument entry.
439 arg.push_back (var_name_arg);
440
441 // Push the data for the first argument into the m_arguments vector.
442 m_arguments.push_back (arg);
Jim Ingham537926c2010-09-02 00:18:39 +0000443 }
444
445 virtual
446 ~CommandObjectFrameVariable ()
447 {
448 }
449
450 virtual
451 Options *
452 GetOptions ()
453 {
454 return &m_options;
455 }
456
Jim Ingham537926c2010-09-02 00:18:39 +0000457
458 virtual bool
459 Execute
460 (
Jim Ingham537926c2010-09-02 00:18:39 +0000461 Args& command,
462 CommandReturnObject &result
463 )
464 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000465 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000466 if (exe_ctx.frame == NULL)
467 {
Greg Claytonaa448052010-09-18 04:06:15 +0000468 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000469 result.SetStatus (eReturnStatusFailed);
470 return false;
471 }
472 else
473 {
Greg Claytonaed58812010-09-13 02:37:44 +0000474 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000475
Greg Claytonaed58812010-09-13 02:37:44 +0000476 bool get_file_globals = true;
477 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
478
Jim Ingham537926c2010-09-02 00:18:39 +0000479 VariableSP var_sp;
480 ValueObjectSP valobj_sp;
Jim Inghame41494a2011-04-16 00:01:13 +0000481
482 bool use_dynamic;
483
484 // If use dynamic is not set, get it from the target:
485 switch (m_options.use_dynamic)
486 {
487 case eLazyBoolCalculate:
488 {
489 if (exe_ctx.target->GetPreferDynamicValue())
490 use_dynamic = true;
491 else
492 use_dynamic = false;
493 }
494 break;
495 case eLazyBoolYes:
496 use_dynamic = true;
497 break;
498 case eLazyBoolNo:
499 use_dynamic = false;
500 break;
501 }
502
Jim Ingham537926c2010-09-02 00:18:39 +0000503 const char *name_cstr = NULL;
504 size_t idx;
505 if (!m_options.globals.empty())
506 {
507 uint32_t fail_count = 0;
508 if (exe_ctx.target)
509 {
510 const size_t num_globals = m_options.globals.size();
511 for (idx = 0; idx < num_globals; ++idx)
512 {
513 VariableList global_var_list;
Jim Inghame41494a2011-04-16 00:01:13 +0000514 const uint32_t num_matching_globals
515 = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx],
516 true,
517 UINT32_MAX,
518 global_var_list);
Jim Ingham537926c2010-09-02 00:18:39 +0000519
520 if (num_matching_globals == 0)
521 {
522 ++fail_count;
Jim Inghame41494a2011-04-16 00:01:13 +0000523 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n",
524 m_options.globals[idx].AsCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000525 }
526 else
527 {
528 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
529 {
530 var_sp = global_var_list.GetVariableAtIndex(global_idx);
531 if (var_sp)
532 {
Jim Inghame41494a2011-04-16 00:01:13 +0000533 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham537926c2010-09-02 00:18:39 +0000534 if (!valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000535 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp, use_dynamic);
Jim Ingham537926c2010-09-02 00:18:39 +0000536
537 if (valobj_sp)
538 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000539 if (m_options.format != eFormatDefault)
540 valobj_sp->SetFormat (m_options.format);
541
Greg Claytonaed58812010-09-13 02:37:44 +0000542 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
543 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000544 var_sp->GetDeclaration ().DumpStopContext (&s, false);
545 s.PutCString (": ");
Greg Claytonaed58812010-09-13 02:37:44 +0000546 }
Jim Inghame41494a2011-04-16 00:01:13 +0000547
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000548 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000549 valobj_sp.get(),
550 name_cstr,
551 m_options.ptr_depth,
552 0,
553 m_options.max_depth,
554 m_options.show_types,
555 m_options.show_location,
Jim Inghame41494a2011-04-16 00:01:13 +0000556 m_options.use_objc,
557 use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000558 false,
559 m_options.flat_output);
Jim Ingham537926c2010-09-02 00:18:39 +0000560 }
561 }
562 }
563 }
564 }
565 }
566 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000567 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000568 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000569 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000570 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000571 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000572 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000573 VariableList regex_var_list;
574
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000575 // If we have any args to the variable command, we will make
576 // variable objects from them...
577 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000578 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000579 uint32_t ptr_depth = m_options.ptr_depth;
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000580
581 if (m_options.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000582 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000583 const uint32_t regex_start_index = regex_var_list.GetSize();
584 RegularExpression regex (name_cstr);
585 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000586 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000587 size_t num_matches = 0;
Jim Inghame41494a2011-04-16 00:01:13 +0000588 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
589 regex_var_list,
590 num_matches);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000591 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000592 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000593 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
594 regex_idx < end_index;
595 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000596 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000597 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
598 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000599 {
Jim Inghame41494a2011-04-16 00:01:13 +0000600 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, use_dynamic);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000601 if (valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000602 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000603 if (m_options.format != eFormatDefault)
604 valobj_sp->SetFormat (m_options.format);
605
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000606 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
607 {
608 var_sp->GetDeclaration ().DumpStopContext (&s, false);
609 s.PutCString (": ");
610 }
611
612 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000613 valobj_sp.get(),
614 var_sp->GetName().AsCString(),
615 m_options.ptr_depth,
616 0,
617 m_options.max_depth,
618 m_options.show_types,
619 m_options.show_location,
Jim Inghame41494a2011-04-16 00:01:13 +0000620 m_options.use_objc,
621 use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000622 false,
623 m_options.flat_output);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000624 }
625 }
626 }
627 }
628 else if (num_matches == 0)
629 {
630 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
631 }
632 }
633 else
634 {
635 char regex_error[1024];
636 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
637 result.GetErrorStream().Printf ("error: %s\n", regex_error);
638 else
639 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
640 }
641 }
642 else
643 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000644 Error error;
Jim Inghame41494a2011-04-16 00:01:13 +0000645 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
646 if (use_dynamic)
647 expr_path_options |= StackFrame::eExpressionPathOptionsDynamicValue;
648
Greg Claytonc67efa42011-01-20 19:27:18 +0000649 valobj_sp = exe_ctx.frame->GetValueForVariableExpressionPath (name_cstr, expr_path_options, error);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000650 if (valobj_sp)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000651 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000652 if (m_options.format != eFormatDefault)
653 valobj_sp->SetFormat (m_options.format);
654
Greg Claytonc3b61d22010-12-15 05:08:08 +0000655 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000656 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000657 var_sp->GetDeclaration ().DumpStopContext (&s, false);
658 s.PutCString (": ");
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000659 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000660 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Claytonc3b61d22010-12-15 05:08:08 +0000661 valobj_sp.get(),
662 valobj_sp->GetParent() ? name_cstr : NULL,
663 ptr_depth,
664 0,
665 m_options.max_depth,
666 m_options.show_types,
667 m_options.show_location,
Jim Inghame41494a2011-04-16 00:01:13 +0000668 m_options.use_objc,
669 use_dynamic,
Greg Claytonc3b61d22010-12-15 05:08:08 +0000670 false,
671 m_options.flat_output);
Greg Claytonaed58812010-09-13 02:37:44 +0000672 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000673 else
674 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000675 const char *error_cstr = error.AsCString(NULL);
676 if (error_cstr)
677 result.GetErrorStream().Printf("error: %s\n", error_cstr);
678 else
679 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000680 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000681 }
Jim Ingham537926c2010-09-02 00:18:39 +0000682 }
683 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000684 else
685 {
686 const uint32_t num_variables = variable_list->GetSize();
687
688 if (num_variables > 0)
689 {
690 for (uint32_t i=0; i<num_variables; i++)
691 {
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000692 var_sp = variable_list->GetVariableAtIndex(i);
Jim Inghame41494a2011-04-16 00:01:13 +0000693
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000694 bool dump_variable = true;
695
696 switch (var_sp->GetScope())
697 {
698 case eValueTypeVariableGlobal:
699 dump_variable = m_options.show_globals;
700 if (dump_variable && m_options.show_scope)
701 s.PutCString("GLOBAL: ");
702 break;
703
704 case eValueTypeVariableStatic:
705 dump_variable = m_options.show_globals;
706 if (dump_variable && m_options.show_scope)
707 s.PutCString("STATIC: ");
708 break;
709
710 case eValueTypeVariableArgument:
711 dump_variable = m_options.show_args;
712 if (dump_variable && m_options.show_scope)
713 s.PutCString(" ARG: ");
714 break;
715
716 case eValueTypeVariableLocal:
717 dump_variable = m_options.show_locals;
718 if (dump_variable && m_options.show_scope)
719 s.PutCString(" LOCAL: ");
720 break;
721
722 default:
723 break;
724 }
725
726 if (dump_variable)
727 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000728
729 // Use the variable object code to make sure we are
730 // using the same APIs as the the public API will be
731 // using...
Jim Inghame41494a2011-04-16 00:01:13 +0000732 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, use_dynamic);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000733 if (valobj_sp)
734 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000735 if (m_options.format != eFormatDefault)
736 valobj_sp->SetFormat (m_options.format);
737
Greg Claytona357ecf2010-09-14 03:16:58 +0000738 // When dumping all variables, don't print any variables
739 // that are not in scope to avoid extra unneeded output
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000740 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000741 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000742 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
743 {
744 var_sp->GetDeclaration ().DumpStopContext (&s, false);
745 s.PutCString (": ");
746 }
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000747 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000748 valobj_sp.get(),
749 name_cstr,
750 m_options.ptr_depth,
751 0,
752 m_options.max_depth,
753 m_options.show_types,
754 m_options.show_location,
Jim Inghame41494a2011-04-16 00:01:13 +0000755 m_options.use_objc,
756 use_dynamic,
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000757 false,
758 m_options.flat_output);
Greg Claytona357ecf2010-09-14 03:16:58 +0000759 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000760 }
761 }
762 }
763 }
764 }
765 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000766 }
Jim Ingham537926c2010-09-02 00:18:39 +0000767 }
768 return result.Succeeded();
769 }
770protected:
771
772 CommandOptions m_options;
773};
774
Greg Claytonb3448432011-03-24 21:19:54 +0000775OptionDefinition
Jim Ingham537926c2010-09-02 00:18:39 +0000776CommandObjectFrameVariable::CommandOptions::g_option_table[] =
777{
Jim Inghame41494a2011-04-16 00:01:13 +0000778{ 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)."},
779{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
780{ 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)."},
781{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, eArgTypeNone, "Enable verbose debug information."},
782{ 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."},
783{ LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, eArgTypeExprFormat, "Specify the format that the variable output should use."},
784{ 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."},
785{ LLDB_OPT_SET_1, false, "show-globals", 'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
786{ 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)."},
787{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, eArgTypeNone, "Show variable location information."},
788{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
789{ 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."},
790{ 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)."},
791{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."},
792{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
793{ LLDB_OPT_SET_1, false, "show-types", 't', no_argument, NULL, 0, eArgTypeNone, "Show variable types when dumping values."},
794{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, eArgTypeNone, "Omit summary information."},
Caroline Tice4d6675c2010-10-01 19:59:14 +0000795{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Jim Ingham537926c2010-09-02 00:18:39 +0000796};
Chris Lattner24943d22010-06-08 16:52:24 +0000797#pragma mark CommandObjectMultiwordFrame
798
799//-------------------------------------------------------------------------
800// CommandObjectMultiwordFrame
801//-------------------------------------------------------------------------
802
Greg Clayton63094e02010-06-23 01:19:29 +0000803CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000804 CommandObjectMultiword (interpreter,
805 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000806 "A set of commands for operating on the current thread's frames.",
807 "frame <subcommand> [<subcommand-options>]")
808{
Greg Clayton238c0a12010-09-18 01:14:36 +0000809 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
810 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
811 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000812}
813
814CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
815{
816}
817