blob: ae1cad4eaa1b58e5245c100320515fb6fc446e53 [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 Clayton238c0a12010-09-18 01:14:36 +000097 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
98 CommandObject (interpreter,
99 "frame select",
100 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000101 NULL,
Greg Clayton238c0a12010-09-18 01:14:36 +0000102 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +0000103 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000104 CommandArgumentEntry arg;
105 CommandArgumentData index_arg;
106
107 // Define the first (and only) variant of this arg.
108 index_arg.arg_type = eArgTypeFrameIndex;
109 index_arg.arg_repetition = eArgRepeatPlain;
110
111 // There is only one variant this argument could be; put it into the argument entry.
112 arg.push_back (index_arg);
113
114 // Push the data for the first argument into the m_arguments vector.
115 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000116 }
117
118 ~CommandObjectFrameSelect ()
119 {
120 }
121
122 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000123 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000124 CommandReturnObject &result)
125 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000126 ExecutionContext exe_ctx (m_interpreter.GetDebugger().GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000127 if (exe_ctx.thread)
128 {
129 if (command.GetArgumentCount() == 1)
130 {
131 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
132
133 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
134 const uint32_t frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
135 if (frame_idx < num_frames)
136 {
Jim Inghamc8332952010-08-26 21:32:51 +0000137 exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
138 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000139
140 if (exe_ctx.frame)
141 {
Jim Ingham74989e82010-08-30 19:44:40 +0000142 bool already_shown = false;
143 SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
Caroline Tice5bc8c972010-09-20 20:44:43 +0000144 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Jim Ingham74989e82010-08-30 19:44:40 +0000145 {
146 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
147 }
148
Chris Lattner24943d22010-06-08 16:52:24 +0000149 if (DisplayFrameForExecutionContext (exe_ctx.thread,
150 exe_ctx.frame,
Greg Clayton238c0a12010-09-18 01:14:36 +0000151 m_interpreter,
Chris Lattner24943d22010-06-08 16:52:24 +0000152 result.GetOutputStream(),
153 true,
Jim Ingham74989e82010-08-30 19:44:40 +0000154 !already_shown,
Chris Lattner24943d22010-06-08 16:52:24 +0000155 3,
156 3))
157 {
158 result.SetStatus (eReturnStatusSuccessFinishResult);
159 return result.Succeeded();
160 }
161 }
162 }
163 if (frame_idx == UINT32_MAX)
164 result.AppendErrorWithFormat ("Invalid frame index: %s.\n", frame_idx_cstr);
165 else
166 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
167 }
168 else
169 {
170 result.AppendError ("invalid arguments");
171 result.AppendErrorWithFormat ("Usage: %s\n", m_cmd_syntax.c_str());
172 }
173 }
174 else
175 {
176 result.AppendError ("no current thread");
177 }
178 result.SetStatus (eReturnStatusFailed);
179 return false;
180 }
181};
182
Jim Ingham537926c2010-09-02 00:18:39 +0000183#pragma mark CommandObjectFrameVariable
184//----------------------------------------------------------------------
185// List images with associated information
186//----------------------------------------------------------------------
187class CommandObjectFrameVariable : public CommandObject
188{
189public:
190
191 class CommandOptions : public Options
192 {
193 public:
194
195 CommandOptions () :
196 Options()
197 {
198 ResetOptionValues ();
199 }
200
201 virtual
202 ~CommandOptions ()
203 {
204 }
205
206 virtual Error
207 SetOptionValue (int option_idx, const char *option_arg)
208 {
209 Error error;
210 bool success;
211 char short_option = (char) m_getopt_table[option_idx].val;
212 switch (short_option)
213 {
214 case 'o': use_objc = true; break;
215 case 'n': name = option_arg; break;
216 case 'r': use_regex = true; break;
217 case 'a': show_args = false; break;
218 case 'l': show_locals = false; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000219 case 'g': show_globals = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000220 case 't': show_types = false; break;
221 case 'y': show_summary = false; break;
222 case 'L': show_location= true; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000223 case 'c': show_decl = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000224 case 'D': debug = true; break;
225 case 'd':
226 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
227 if (!success)
228 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
229 break;
230
231 case 'p':
232 ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
233 if (!success)
234 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
235 break;
236
237 case 'G':
Greg Claytonaed58812010-09-13 02:37:44 +0000238 globals.push_back(ConstString (option_arg));
Jim Ingham537926c2010-09-02 00:18:39 +0000239 break;
240
241 case 's':
242 show_scope = true;
243 break;
244
245 default:
246 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
247 break;
248 }
249
250 return error;
251 }
252
253 void
254 ResetOptionValues ()
255 {
256 Options::ResetOptionValues();
257
258 name.clear();
259 use_objc = false;
260 use_regex = false;
261 show_args = true;
262 show_locals = true;
Greg Claytonaed58812010-09-13 02:37:44 +0000263 show_globals = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000264 show_types = true;
265 show_scope = false;
266 show_summary = true;
267 show_location = false;
Greg Claytonaed58812010-09-13 02:37:44 +0000268 show_decl = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000269 debug = false;
270 max_depth = UINT32_MAX;
271 ptr_depth = 0;
272 globals.clear();
273 }
274
275 const lldb::OptionDefinition*
276 GetDefinitions ()
277 {
278 return g_option_table;
279 }
280
281 // Options table: Required for subclasses of Options.
282
283 static lldb::OptionDefinition g_option_table[];
284 std::string name;
Greg Claytonaed58812010-09-13 02:37:44 +0000285 bool use_objc:1,
286 use_regex:1,
287 show_args:1,
288 show_locals:1,
289 show_globals:1,
290 show_types:1,
291 show_scope:1,
292 show_summary:1,
293 show_location:1,
294 show_decl:1,
295 debug:1;
Jim Ingham537926c2010-09-02 00:18:39 +0000296 uint32_t max_depth; // The depth to print when dumping concrete (not pointers) aggreate values
297 uint32_t ptr_depth; // The default depth that is dumped when we find pointers
298 std::vector<ConstString> globals;
299 // Instance variables to hold the values for command options.
300 };
301
Greg Clayton238c0a12010-09-18 01:14:36 +0000302 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
303 CommandObject (interpreter,
304 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000305 "Show frame variables. All argument and local variables "
306 "that are in scope will be shown when no arguments are given. "
307 "If any arguments are specified, they can be names of "
308 "argument, local, file static and file global variables."
309 "Children of aggregate variables can be specified such as "
310 "'var->child.x'.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000311 NULL)
Jim Ingham537926c2010-09-02 00:18:39 +0000312 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000313 CommandArgumentEntry arg;
314 CommandArgumentData var_name_arg;
315
316 // Define the first (and only) variant of this arg.
317 var_name_arg.arg_type = eArgTypeVarName;
318 var_name_arg.arg_repetition = eArgRepeatStar;
319
320 // There is only one variant this argument could be; put it into the argument entry.
321 arg.push_back (var_name_arg);
322
323 // Push the data for the first argument into the m_arguments vector.
324 m_arguments.push_back (arg);
Jim Ingham537926c2010-09-02 00:18:39 +0000325 }
326
327 virtual
328 ~CommandObjectFrameVariable ()
329 {
330 }
331
332 virtual
333 Options *
334 GetOptions ()
335 {
336 return &m_options;
337 }
338
Jim Ingham537926c2010-09-02 00:18:39 +0000339
340 virtual bool
341 Execute
342 (
Jim Ingham537926c2010-09-02 00:18:39 +0000343 Args& command,
344 CommandReturnObject &result
345 )
346 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000347 ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000348 if (exe_ctx.frame == NULL)
349 {
Greg Claytonaa448052010-09-18 04:06:15 +0000350 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000351 result.SetStatus (eReturnStatusFailed);
352 return false;
353 }
354 else
355 {
Greg Claytonaed58812010-09-13 02:37:44 +0000356 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000357
Greg Claytonaed58812010-09-13 02:37:44 +0000358 bool get_file_globals = true;
359 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
360
Jim Ingham537926c2010-09-02 00:18:39 +0000361 VariableSP var_sp;
362 ValueObjectSP valobj_sp;
363 //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList();
364 const char *name_cstr = NULL;
365 size_t idx;
366 if (!m_options.globals.empty())
367 {
368 uint32_t fail_count = 0;
369 if (exe_ctx.target)
370 {
371 const size_t num_globals = m_options.globals.size();
372 for (idx = 0; idx < num_globals; ++idx)
373 {
374 VariableList global_var_list;
375 const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list);
376
377 if (num_matching_globals == 0)
378 {
379 ++fail_count;
380 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString());
381 }
382 else
383 {
384 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
385 {
386 var_sp = global_var_list.GetVariableAtIndex(global_idx);
387 if (var_sp)
388 {
Greg Clayton17dae082010-09-02 02:59:18 +0000389 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000390 if (!valobj_sp)
Greg Clayton17dae082010-09-02 02:59:18 +0000391 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000392
393 if (valobj_sp)
394 {
Greg Claytonaed58812010-09-13 02:37:44 +0000395 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
396 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000397 var_sp->GetDeclaration ().DumpStopContext (&s, false);
398 s.PutCString (": ");
Greg Claytonaed58812010-09-13 02:37:44 +0000399 }
400
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000401 ValueObject::DumpValueObject (result.GetOutputStream(),
402 exe_ctx.frame,
403 valobj_sp.get(),
404 name_cstr,
405 m_options.ptr_depth,
406 0,
407 m_options.max_depth,
408 m_options.show_types,
409 m_options.show_location,
410 m_options.use_objc,
411 false);
Greg Claytonaed58812010-09-13 02:37:44 +0000412 s.EOL();
Jim Ingham537926c2010-09-02 00:18:39 +0000413 }
414 }
415 }
416 }
417 }
418 }
419 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000420 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000421 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000422 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000423 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000424 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000425 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000426 // If we have any args to the variable command, we will make
427 // variable objects from them...
428 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000429 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000430 uint32_t ptr_depth = m_options.ptr_depth;
431 // If first character is a '*', then show pointer contents
432 if (name_cstr[0] == '*')
Jim Ingham537926c2010-09-02 00:18:39 +0000433 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000434 ++ptr_depth;
435 name_cstr++; // Skip the '*'
436 }
437
438 std::string var_path (name_cstr);
439 size_t separator_idx = var_path.find_first_of(".-[");
440
441 ConstString name_const_string;
442 if (separator_idx == std::string::npos)
443 name_const_string.SetCString (var_path.c_str());
444 else
445 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
446
447 var_sp = variable_list->FindVariable(name_const_string);
448 if (var_sp)
449 {
450 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
451
452 var_path.erase (0, name_const_string.GetLength ());
453 // We are dumping at least one child
454 while (separator_idx != std::string::npos)
Jim Ingham537926c2010-09-02 00:18:39 +0000455 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000456 // Calculate the next separator index ahead of time
457 ValueObjectSP child_valobj_sp;
458 const char separator_type = var_path[0];
459 switch (separator_type)
Jim Ingham537926c2010-09-02 00:18:39 +0000460 {
Jim Ingham537926c2010-09-02 00:18:39 +0000461
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000462 case '-':
463 if (var_path.size() >= 2 && var_path[1] != '>')
Jim Ingham537926c2010-09-02 00:18:39 +0000464 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000465 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
466 var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000467 var_path.clear();
468 valobj_sp.reset();
469 break;
470 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000471 var_path.erase (0, 1); // Remove the '-'
472 // Fall through
473 case '.':
Jim Ingham537926c2010-09-02 00:18:39 +0000474 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000475 var_path.erase (0, 1); // Remove the '.' or '>'
476 separator_idx = var_path.find_first_of(".-[");
477 ConstString child_name;
478 if (separator_idx == std::string::npos)
479 child_name.SetCString (var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000480 else
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000481 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
Jim Ingham537926c2010-09-02 00:18:39 +0000482
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000483 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Jim Ingham537926c2010-09-02 00:18:39 +0000484 if (!child_valobj_sp)
485 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000486 result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n",
487 valobj_sp->GetName().AsCString(),
488 child_name.GetCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000489 var_path.clear();
490 valobj_sp.reset();
491 break;
492 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000493 // Remove the child name from the path
494 var_path.erase(0, child_name.GetLength());
Jim Ingham537926c2010-09-02 00:18:39 +0000495 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000496 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000497
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000498 case '[':
499 // Array member access, or treating pointer as an array
500 if (var_path.size() > 2) // Need at least two brackets and a number
501 {
502 char *end = NULL;
503 int32_t child_index = ::strtol (&var_path[1], &end, 0);
504 if (end && *end == ']')
505 {
Jim Ingham537926c2010-09-02 00:18:39 +0000506
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000507 if (valobj_sp->IsPointerType ())
508 {
509 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
510 }
511 else
512 {
513 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
514 }
515
516 if (!child_valobj_sp)
517 {
518 result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n",
519 child_index,
520 valobj_sp->GetName().AsCString());
521 var_path.clear();
522 valobj_sp.reset();
523 break;
524 }
525
526 // Erase the array member specification '[%i]' where %i is the array index
527 var_path.erase(0, (end - var_path.c_str()) + 1);
528 separator_idx = var_path.find_first_of(".-[");
529
530 // Break out early from the switch since we were able to find the child member
531 break;
532 }
533 }
534 result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n",
535 valobj_sp->GetName().AsCString(),
Jim Ingham537926c2010-09-02 00:18:39 +0000536 var_path.c_str());
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000537 var_path.clear();
538 valobj_sp.reset();
539 break;
540
541 break;
542
543 default:
544 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
545 var_path.c_str());
546 var_path.clear();
547 valobj_sp.reset();
548 separator_idx = std::string::npos;
549 break;
550 }
551
552 if (child_valobj_sp)
553 valobj_sp = child_valobj_sp;
554
555 if (var_path.empty())
556 break;
557
Jim Ingham537926c2010-09-02 00:18:39 +0000558 }
559
Greg Claytonaed58812010-09-13 02:37:44 +0000560 if (valobj_sp)
561 {
Greg Claytonaed58812010-09-13 02:37:44 +0000562 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
563 {
564 var_sp->GetDeclaration ().DumpStopContext (&s, false);
565 s.PutCString (": ");
566 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000567
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000568
569 ValueObject::DumpValueObject (result.GetOutputStream(),
570 exe_ctx.frame,
571 valobj_sp.get(),
572 name_cstr,
573 ptr_depth,
574 0,
575 m_options.max_depth,
576 m_options.show_types,
577 m_options.show_location,
578 m_options.use_objc,
579 false);
Greg Claytonaed58812010-09-13 02:37:44 +0000580
581 s.EOL();
582 }
583 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000584 else
585 {
586 result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr);
587 var_path.clear();
588 }
Jim Ingham537926c2010-09-02 00:18:39 +0000589 }
590 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000591 else
592 {
593 const uint32_t num_variables = variable_list->GetSize();
594
595 if (num_variables > 0)
596 {
597 for (uint32_t i=0; i<num_variables; i++)
598 {
599 VariableSP var_sp (variable_list->GetVariableAtIndex(i));
600 bool dump_variable = true;
601
602 switch (var_sp->GetScope())
603 {
604 case eValueTypeVariableGlobal:
605 dump_variable = m_options.show_globals;
606 if (dump_variable && m_options.show_scope)
607 s.PutCString("GLOBAL: ");
608 break;
609
610 case eValueTypeVariableStatic:
611 dump_variable = m_options.show_globals;
612 if (dump_variable && m_options.show_scope)
613 s.PutCString("STATIC: ");
614 break;
615
616 case eValueTypeVariableArgument:
617 dump_variable = m_options.show_args;
618 if (dump_variable && m_options.show_scope)
619 s.PutCString(" ARG: ");
620 break;
621
622 case eValueTypeVariableLocal:
623 dump_variable = m_options.show_locals;
624 if (dump_variable && m_options.show_scope)
625 s.PutCString(" LOCAL: ");
626 break;
627
628 default:
629 break;
630 }
631
632 if (dump_variable)
633 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000634
635 // Use the variable object code to make sure we are
636 // using the same APIs as the the public API will be
637 // using...
638 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
639 if (valobj_sp)
640 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000641 // When dumping all variables, don't print any variables
642 // that are not in scope to avoid extra unneeded output
643 if (valobj_sp->IsInScope (exe_ctx.frame))
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000644 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000645 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
646 {
647 var_sp->GetDeclaration ().DumpStopContext (&s, false);
648 s.PutCString (": ");
649 }
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000650 ValueObject::DumpValueObject (result.GetOutputStream(),
651 exe_ctx.frame,
652 valobj_sp.get(),
653 name_cstr,
654 m_options.ptr_depth,
655 0,
656 m_options.max_depth,
657 m_options.show_types,
658 m_options.show_location,
659 m_options.use_objc,
660 false);
661
Greg Claytona357ecf2010-09-14 03:16:58 +0000662 s.EOL();
663 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000664 }
665 }
666 }
667 }
668 }
669 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000670 }
Jim Ingham537926c2010-09-02 00:18:39 +0000671 }
672 return result.Succeeded();
673 }
674protected:
675
676 CommandOptions m_options;
677};
678
679lldb::OptionDefinition
680CommandObjectFrameVariable::CommandOptions::g_option_table[] =
681{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000682{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, eArgTypeNone, "Enable verbose debug information."},
683{ LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."},
684{ LLDB_OPT_SET_1, false, "show-globals",'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
685{ 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)."},
686{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, eArgTypeNone, "Show variable location information."},
687{ 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)."},
688{ 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."},
689{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
690{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
691{ LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, eArgTypeNone, "Omit variable type names."},
692{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, eArgTypeNone, "Omit summary information."},
693{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
694{ 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."},
695{ 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)."},
696{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, eArgTypeCount, "The <name> argument for name lookups are regular expressions."},
697{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Jim Ingham537926c2010-09-02 00:18:39 +0000698};
Chris Lattner24943d22010-06-08 16:52:24 +0000699#pragma mark CommandObjectMultiwordFrame
700
701//-------------------------------------------------------------------------
702// CommandObjectMultiwordFrame
703//-------------------------------------------------------------------------
704
Greg Clayton63094e02010-06-23 01:19:29 +0000705CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000706 CommandObjectMultiword (interpreter,
707 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000708 "A set of commands for operating on the current thread's frames.",
709 "frame <subcommand> [<subcommand-options>]")
710{
Greg Clayton238c0a12010-09-18 01:14:36 +0000711 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
712 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
713 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000714}
715
716CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
717{
718}
719