blob: 20725a68da535359d88d82fedc998f28e6f912f1 [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"
23#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Interpreter/CommandInterpreter.h"
25#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham537926c2010-09-02 00:18:39 +000026#include "lldb/Interpreter/Options.h"
27#include "lldb/Symbol/ClangASTType.h"
28#include "lldb/Symbol/ClangASTContext.h"
29#include "lldb/Symbol/ObjectFile.h"
30#include "lldb/Symbol/SymbolContext.h"
31#include "lldb/Symbol/Type.h"
32#include "lldb/Symbol/Variable.h"
33#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Target/Process.h"
35#include "lldb/Target/StackFrame.h"
36#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000037#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038
39#include "CommandObjectThread.h"
40
41using namespace lldb;
42using namespace lldb_private;
43
44#pragma mark CommandObjectFrameInfo
45
46//-------------------------------------------------------------------------
47// CommandObjectFrameInfo
48//-------------------------------------------------------------------------
49
50class CommandObjectFrameInfo : public CommandObject
51{
52public:
53
Greg Clayton238c0a12010-09-18 01:14:36 +000054 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
55 CommandObject (interpreter,
56 "frame info",
57 "List information about the currently selected frame in the current thread.",
58 "frame info",
59 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000060 {
61 }
62
63 ~CommandObjectFrameInfo ()
64 {
65 }
66
67 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000068 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000069 CommandReturnObject &result)
70 {
Greg Clayton238c0a12010-09-18 01:14:36 +000071 ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +000072 if (exe_ctx.frame)
73 {
Greg Claytona830adb2010-10-04 01:05:56 +000074 exe_ctx.frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000075 result.GetOutputStream().EOL();
76 result.SetStatus (eReturnStatusSuccessFinishResult);
77 }
78 else
79 {
80 result.AppendError ("no current frame");
81 result.SetStatus (eReturnStatusFailed);
82 }
83 return result.Succeeded();
84 }
85};
86
87#pragma mark CommandObjectFrameSelect
88
89//-------------------------------------------------------------------------
90// CommandObjectFrameSelect
91//-------------------------------------------------------------------------
92
93class CommandObjectFrameSelect : public CommandObject
94{
95public:
96
Greg Claytonc12b6b42010-10-10 22:28:11 +000097 class CommandOptions : public Options
98 {
99 public:
100
101 CommandOptions () :
102 Options()
103 {
104 ResetOptionValues ();
105 }
106
107 virtual
108 ~CommandOptions ()
109 {
110 }
111
112 virtual Error
113 SetOptionValue (int option_idx, const char *option_arg)
114 {
115 Error error;
116 bool success = false;
117 char short_option = (char) m_getopt_table[option_idx].val;
118 switch (short_option)
119 {
120 case 'r':
121 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
122 if (!success)
123 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg);
124 break;
125
126 default:
127 ("Invalid short option character '%c'.\n", short_option);
128 break;
129 }
130
131 return error;
132 }
133
134 void
135 ResetOptionValues ()
136 {
137 Options::ResetOptionValues();
138 relative_frame_offset = INT32_MIN;
139 }
140
141 const lldb::OptionDefinition*
142 GetDefinitions ()
143 {
144 return g_option_table;
145 }
146
147 // Options table: Required for subclasses of Options.
148
149 static lldb::OptionDefinition g_option_table[];
150 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
273lldb::OptionDefinition
274CommandObjectFrameSelect::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;
312 case 'n': name = option_arg; break;
313 case 'r': use_regex = true; break;
314 case 'a': show_args = false; break;
315 case 'l': show_locals = false; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000316 case 'g': show_globals = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000317 case 't': show_types = false; break;
318 case 'y': show_summary = false; break;
319 case 'L': show_location= true; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000320 case 'c': show_decl = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000321 case 'D': debug = true; break;
322 case 'd':
323 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
324 if (!success)
325 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
326 break;
327
328 case 'p':
329 ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
330 if (!success)
331 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
332 break;
333
334 case 'G':
Greg Claytonaed58812010-09-13 02:37:44 +0000335 globals.push_back(ConstString (option_arg));
Jim Ingham537926c2010-09-02 00:18:39 +0000336 break;
337
338 case 's':
339 show_scope = true;
340 break;
341
342 default:
343 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
344 break;
345 }
346
347 return error;
348 }
349
350 void
351 ResetOptionValues ()
352 {
353 Options::ResetOptionValues();
354
355 name.clear();
356 use_objc = false;
357 use_regex = false;
358 show_args = true;
359 show_locals = true;
Greg Claytonaed58812010-09-13 02:37:44 +0000360 show_globals = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000361 show_types = true;
362 show_scope = false;
363 show_summary = true;
364 show_location = false;
Greg Claytonaed58812010-09-13 02:37:44 +0000365 show_decl = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000366 debug = false;
367 max_depth = UINT32_MAX;
368 ptr_depth = 0;
369 globals.clear();
370 }
371
372 const lldb::OptionDefinition*
373 GetDefinitions ()
374 {
375 return g_option_table;
376 }
377
378 // Options table: Required for subclasses of Options.
379
380 static lldb::OptionDefinition g_option_table[];
381 std::string name;
Greg Claytonaed58812010-09-13 02:37:44 +0000382 bool use_objc:1,
383 use_regex:1,
384 show_args:1,
385 show_locals:1,
386 show_globals:1,
387 show_types:1,
388 show_scope:1,
389 show_summary:1,
390 show_location:1,
391 show_decl:1,
392 debug: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
395 std::vector<ConstString> globals;
396 // Instance variables to hold the values for command options.
397 };
398
Greg Clayton238c0a12010-09-18 01:14:36 +0000399 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
400 CommandObject (interpreter,
401 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000402 "Show frame variables. All argument and local variables "
403 "that are in scope will be shown when no arguments are given. "
404 "If any arguments are specified, they can be names of "
405 "argument, local, file static and file global variables."
406 "Children of aggregate variables can be specified such as "
407 "'var->child.x'.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000408 NULL)
Jim Ingham537926c2010-09-02 00:18:39 +0000409 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000410 CommandArgumentEntry arg;
411 CommandArgumentData var_name_arg;
412
413 // Define the first (and only) variant of this arg.
414 var_name_arg.arg_type = eArgTypeVarName;
415 var_name_arg.arg_repetition = eArgRepeatStar;
416
417 // There is only one variant this argument could be; put it into the argument entry.
418 arg.push_back (var_name_arg);
419
420 // Push the data for the first argument into the m_arguments vector.
421 m_arguments.push_back (arg);
Jim Ingham537926c2010-09-02 00:18:39 +0000422 }
423
424 virtual
425 ~CommandObjectFrameVariable ()
426 {
427 }
428
429 virtual
430 Options *
431 GetOptions ()
432 {
433 return &m_options;
434 }
435
Jim Ingham537926c2010-09-02 00:18:39 +0000436
437 virtual bool
438 Execute
439 (
Jim Ingham537926c2010-09-02 00:18:39 +0000440 Args& command,
441 CommandReturnObject &result
442 )
443 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000444 ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000445 if (exe_ctx.frame == NULL)
446 {
Greg Claytonaa448052010-09-18 04:06:15 +0000447 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000448 result.SetStatus (eReturnStatusFailed);
449 return false;
450 }
451 else
452 {
Greg Claytonaed58812010-09-13 02:37:44 +0000453 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000454
Greg Claytonaed58812010-09-13 02:37:44 +0000455 bool get_file_globals = true;
456 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
457
Jim Ingham537926c2010-09-02 00:18:39 +0000458 VariableSP var_sp;
459 ValueObjectSP valobj_sp;
460 //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList();
461 const char *name_cstr = NULL;
462 size_t idx;
463 if (!m_options.globals.empty())
464 {
465 uint32_t fail_count = 0;
466 if (exe_ctx.target)
467 {
468 const size_t num_globals = m_options.globals.size();
469 for (idx = 0; idx < num_globals; ++idx)
470 {
471 VariableList global_var_list;
472 const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list);
473
474 if (num_matching_globals == 0)
475 {
476 ++fail_count;
477 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString());
478 }
479 else
480 {
481 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
482 {
483 var_sp = global_var_list.GetVariableAtIndex(global_idx);
484 if (var_sp)
485 {
Greg Clayton17dae082010-09-02 02:59:18 +0000486 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000487 if (!valobj_sp)
Greg Clayton17dae082010-09-02 02:59:18 +0000488 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000489
490 if (valobj_sp)
491 {
Greg Claytonaed58812010-09-13 02:37:44 +0000492 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
493 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000494 var_sp->GetDeclaration ().DumpStopContext (&s, false);
495 s.PutCString (": ");
Greg Claytonaed58812010-09-13 02:37:44 +0000496 }
497
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000498 ValueObject::DumpValueObject (result.GetOutputStream(),
499 exe_ctx.frame,
500 valobj_sp.get(),
501 name_cstr,
502 m_options.ptr_depth,
503 0,
504 m_options.max_depth,
505 m_options.show_types,
506 m_options.show_location,
507 m_options.use_objc,
508 false);
Greg Claytonaed58812010-09-13 02:37:44 +0000509 s.EOL();
Jim Ingham537926c2010-09-02 00:18:39 +0000510 }
511 }
512 }
513 }
514 }
515 }
516 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000517 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000518 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000519 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000520 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000521 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000522 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000523 // If we have any args to the variable command, we will make
524 // variable objects from them...
525 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000526 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000527 uint32_t ptr_depth = m_options.ptr_depth;
528 // If first character is a '*', then show pointer contents
529 if (name_cstr[0] == '*')
Jim Ingham537926c2010-09-02 00:18:39 +0000530 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000531 ++ptr_depth;
532 name_cstr++; // Skip the '*'
533 }
534
535 std::string var_path (name_cstr);
536 size_t separator_idx = var_path.find_first_of(".-[");
537
538 ConstString name_const_string;
539 if (separator_idx == std::string::npos)
540 name_const_string.SetCString (var_path.c_str());
541 else
542 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
543
544 var_sp = variable_list->FindVariable(name_const_string);
545 if (var_sp)
546 {
547 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
548
549 var_path.erase (0, name_const_string.GetLength ());
550 // We are dumping at least one child
551 while (separator_idx != std::string::npos)
Jim Ingham537926c2010-09-02 00:18:39 +0000552 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000553 // Calculate the next separator index ahead of time
554 ValueObjectSP child_valobj_sp;
555 const char separator_type = var_path[0];
556 switch (separator_type)
Jim Ingham537926c2010-09-02 00:18:39 +0000557 {
Jim Ingham537926c2010-09-02 00:18:39 +0000558
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000559 case '-':
560 if (var_path.size() >= 2 && var_path[1] != '>')
Jim Ingham537926c2010-09-02 00:18:39 +0000561 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000562 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
563 var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000564 var_path.clear();
565 valobj_sp.reset();
566 break;
567 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000568 var_path.erase (0, 1); // Remove the '-'
569 // Fall through
570 case '.':
Jim Ingham537926c2010-09-02 00:18:39 +0000571 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000572 var_path.erase (0, 1); // Remove the '.' or '>'
573 separator_idx = var_path.find_first_of(".-[");
574 ConstString child_name;
575 if (separator_idx == std::string::npos)
576 child_name.SetCString (var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000577 else
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000578 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
Jim Ingham537926c2010-09-02 00:18:39 +0000579
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000580 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Jim Ingham537926c2010-09-02 00:18:39 +0000581 if (!child_valobj_sp)
582 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000583 result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n",
584 valobj_sp->GetName().AsCString(),
585 child_name.GetCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000586 var_path.clear();
587 valobj_sp.reset();
588 break;
589 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000590 // Remove the child name from the path
591 var_path.erase(0, child_name.GetLength());
Jim Ingham537926c2010-09-02 00:18:39 +0000592 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000593 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000594
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000595 case '[':
596 // Array member access, or treating pointer as an array
597 if (var_path.size() > 2) // Need at least two brackets and a number
598 {
599 char *end = NULL;
600 int32_t child_index = ::strtol (&var_path[1], &end, 0);
601 if (end && *end == ']')
602 {
Jim Ingham537926c2010-09-02 00:18:39 +0000603
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000604 if (valobj_sp->IsPointerType ())
605 {
606 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
607 }
608 else
609 {
610 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
611 }
612
613 if (!child_valobj_sp)
614 {
615 result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n",
616 child_index,
617 valobj_sp->GetName().AsCString());
618 var_path.clear();
619 valobj_sp.reset();
620 break;
621 }
622
623 // Erase the array member specification '[%i]' where %i is the array index
624 var_path.erase(0, (end - var_path.c_str()) + 1);
625 separator_idx = var_path.find_first_of(".-[");
626
627 // Break out early from the switch since we were able to find the child member
628 break;
629 }
630 }
631 result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n",
632 valobj_sp->GetName().AsCString(),
Jim Ingham537926c2010-09-02 00:18:39 +0000633 var_path.c_str());
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000634 var_path.clear();
635 valobj_sp.reset();
636 break;
637
638 break;
639
640 default:
641 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
642 var_path.c_str());
643 var_path.clear();
644 valobj_sp.reset();
645 separator_idx = std::string::npos;
646 break;
647 }
648
649 if (child_valobj_sp)
650 valobj_sp = child_valobj_sp;
651
652 if (var_path.empty())
653 break;
654
Jim Ingham537926c2010-09-02 00:18:39 +0000655 }
656
Greg Claytonaed58812010-09-13 02:37:44 +0000657 if (valobj_sp)
658 {
Greg Claytonaed58812010-09-13 02:37:44 +0000659 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
660 {
661 var_sp->GetDeclaration ().DumpStopContext (&s, false);
662 s.PutCString (": ");
663 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000664
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000665
666 ValueObject::DumpValueObject (result.GetOutputStream(),
667 exe_ctx.frame,
668 valobj_sp.get(),
669 name_cstr,
670 ptr_depth,
671 0,
672 m_options.max_depth,
673 m_options.show_types,
674 m_options.show_location,
675 m_options.use_objc,
676 false);
Greg Claytonaed58812010-09-13 02:37:44 +0000677
678 s.EOL();
679 }
680 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000681 else
682 {
683 result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr);
684 var_path.clear();
685 }
Jim Ingham537926c2010-09-02 00:18:39 +0000686 }
687 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000688 else
689 {
690 const uint32_t num_variables = variable_list->GetSize();
691
692 if (num_variables > 0)
693 {
694 for (uint32_t i=0; i<num_variables; i++)
695 {
696 VariableSP var_sp (variable_list->GetVariableAtIndex(i));
697 bool dump_variable = true;
698
699 switch (var_sp->GetScope())
700 {
701 case eValueTypeVariableGlobal:
702 dump_variable = m_options.show_globals;
703 if (dump_variable && m_options.show_scope)
704 s.PutCString("GLOBAL: ");
705 break;
706
707 case eValueTypeVariableStatic:
708 dump_variable = m_options.show_globals;
709 if (dump_variable && m_options.show_scope)
710 s.PutCString("STATIC: ");
711 break;
712
713 case eValueTypeVariableArgument:
714 dump_variable = m_options.show_args;
715 if (dump_variable && m_options.show_scope)
716 s.PutCString(" ARG: ");
717 break;
718
719 case eValueTypeVariableLocal:
720 dump_variable = m_options.show_locals;
721 if (dump_variable && m_options.show_scope)
722 s.PutCString(" LOCAL: ");
723 break;
724
725 default:
726 break;
727 }
728
729 if (dump_variable)
730 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000731
732 // Use the variable object code to make sure we are
733 // using the same APIs as the the public API will be
734 // using...
735 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
736 if (valobj_sp)
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
740 if (valobj_sp->IsInScope (exe_ctx.frame))
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(),
748 exe_ctx.frame,
749 valobj_sp.get(),
750 name_cstr,
751 m_options.ptr_depth,
752 0,
753 m_options.max_depth,
754 m_options.show_types,
755 m_options.show_location,
756 m_options.use_objc,
757 false);
758
Greg Claytona357ecf2010-09-14 03:16:58 +0000759 s.EOL();
760 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000761 }
762 }
763 }
764 }
765 }
766 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000767 }
Jim Ingham537926c2010-09-02 00:18:39 +0000768 }
769 return result.Succeeded();
770 }
771protected:
772
773 CommandOptions m_options;
774};
775
776lldb::OptionDefinition
777CommandObjectFrameVariable::CommandOptions::g_option_table[] =
778{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000779{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, eArgTypeNone, "Enable verbose debug information."},
780{ LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."},
781{ LLDB_OPT_SET_1, false, "show-globals",'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
782{ 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)."},
783{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, eArgTypeNone, "Show variable location information."},
784{ 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)."},
785{ LLDB_OPT_SET_1, false, "name", 'n', required_argument, NULL, 0, eArgTypeVarName, "Lookup a variable by name or regex (--regex) for the current execution context."},
786{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
787{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
788{ LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, eArgTypeNone, "Omit variable type names."},
789{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, eArgTypeNone, "Omit summary information."},
790{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
791{ LLDB_OPT_SET_1, false, "objc", 'o', no_argument, NULL, 0, eArgTypeNone, "When looking up a variable by name (--name), print as an Objective-C object."},
792{ 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)."},
793{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, eArgTypeCount, "The <name> argument for name lookups are regular expressions."},
794{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Jim Ingham537926c2010-09-02 00:18:39 +0000795};
Chris Lattner24943d22010-06-08 16:52:24 +0000796#pragma mark CommandObjectMultiwordFrame
797
798//-------------------------------------------------------------------------
799// CommandObjectMultiwordFrame
800//-------------------------------------------------------------------------
801
Greg Clayton63094e02010-06-23 01:19:29 +0000802CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000803 CommandObjectMultiword (interpreter,
804 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000805 "A set of commands for operating on the current thread's frames.",
806 "frame <subcommand> [<subcommand-options>]")
807{
Greg Clayton238c0a12010-09-18 01:14:36 +0000808 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
809 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
810 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000811}
812
813CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
814{
815}
816