blob: 1593488f4c1b11ff9e69af427a4ae90b976de571 [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
54 CommandObjectFrameInfo () :
55 CommandObject ("frame info",
Caroline Ticeabb507a2010-09-08 21:06:11 +000056 "List information about the currently selected frame in the current thread.",
Chris Lattner24943d22010-06-08 16:52:24 +000057 "frame info",
58 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
59 {
60 }
61
62 ~CommandObjectFrameInfo ()
63 {
64 }
65
66 bool
Greg Clayton63094e02010-06-23 01:19:29 +000067 Execute (CommandInterpreter &interpreter,
68 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000069 CommandReturnObject &result)
70 {
Greg Clayton63094e02010-06-23 01:19:29 +000071 ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +000072 if (exe_ctx.frame)
73 {
Greg Clayton72b71582010-09-02 21:44:10 +000074 exe_ctx.frame->Dump (&result.GetOutputStream(), true, false);
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
97 CommandObjectFrameSelect () :
98 CommandObject ("frame select",
Caroline Ticeabb507a2010-09-08 21:06:11 +000099 //"Select the current frame by index in the current thread.",
100 "Select a frame by index from within the current thread and make it the current frame.",
Chris Lattner24943d22010-06-08 16:52:24 +0000101 "frame select <frame-index>",
102 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
103 {
104 }
105
106 ~CommandObjectFrameSelect ()
107 {
108 }
109
110 bool
Greg Clayton63094e02010-06-23 01:19:29 +0000111 Execute (CommandInterpreter &interpreter,
112 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000113 CommandReturnObject &result)
114 {
Greg Clayton63094e02010-06-23 01:19:29 +0000115 ExecutionContext exe_ctx (interpreter.GetDebugger().GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000116 if (exe_ctx.thread)
117 {
118 if (command.GetArgumentCount() == 1)
119 {
120 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
121
122 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
123 const uint32_t frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
124 if (frame_idx < num_frames)
125 {
Jim Inghamc8332952010-08-26 21:32:51 +0000126 exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
127 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000128
129 if (exe_ctx.frame)
130 {
Jim Ingham74989e82010-08-30 19:44:40 +0000131 bool already_shown = false;
132 SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
133 if (interpreter.GetDebugger().UseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
134 {
135 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
136 }
137
Chris Lattner24943d22010-06-08 16:52:24 +0000138 if (DisplayFrameForExecutionContext (exe_ctx.thread,
139 exe_ctx.frame,
140 interpreter,
141 result.GetOutputStream(),
142 true,
Jim Ingham74989e82010-08-30 19:44:40 +0000143 !already_shown,
Chris Lattner24943d22010-06-08 16:52:24 +0000144 3,
145 3))
146 {
147 result.SetStatus (eReturnStatusSuccessFinishResult);
148 return result.Succeeded();
149 }
150 }
151 }
152 if (frame_idx == UINT32_MAX)
153 result.AppendErrorWithFormat ("Invalid frame index: %s.\n", frame_idx_cstr);
154 else
155 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
156 }
157 else
158 {
159 result.AppendError ("invalid arguments");
160 result.AppendErrorWithFormat ("Usage: %s\n", m_cmd_syntax.c_str());
161 }
162 }
163 else
164 {
165 result.AppendError ("no current thread");
166 }
167 result.SetStatus (eReturnStatusFailed);
168 return false;
169 }
170};
171
Jim Ingham537926c2010-09-02 00:18:39 +0000172#pragma mark CommandObjectFrameVariable
173//----------------------------------------------------------------------
174// List images with associated information
175//----------------------------------------------------------------------
176class CommandObjectFrameVariable : public CommandObject
177{
178public:
179
180 class CommandOptions : public Options
181 {
182 public:
183
184 CommandOptions () :
185 Options()
186 {
187 ResetOptionValues ();
188 }
189
190 virtual
191 ~CommandOptions ()
192 {
193 }
194
195 virtual Error
196 SetOptionValue (int option_idx, const char *option_arg)
197 {
198 Error error;
199 bool success;
200 char short_option = (char) m_getopt_table[option_idx].val;
201 switch (short_option)
202 {
203 case 'o': use_objc = true; break;
204 case 'n': name = option_arg; break;
205 case 'r': use_regex = true; break;
206 case 'a': show_args = false; break;
207 case 'l': show_locals = false; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000208 case 'g': show_globals = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000209 case 't': show_types = false; break;
210 case 'y': show_summary = false; break;
211 case 'L': show_location= true; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000212 case 'c': show_decl = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000213 case 'D': debug = true; break;
214 case 'd':
215 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
216 if (!success)
217 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
218 break;
219
220 case 'p':
221 ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
222 if (!success)
223 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
224 break;
225
226 case 'G':
Greg Claytonaed58812010-09-13 02:37:44 +0000227 globals.push_back(ConstString (option_arg));
Jim Ingham537926c2010-09-02 00:18:39 +0000228 break;
229
230 case 's':
231 show_scope = true;
232 break;
233
234 default:
235 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
236 break;
237 }
238
239 return error;
240 }
241
242 void
243 ResetOptionValues ()
244 {
245 Options::ResetOptionValues();
246
247 name.clear();
248 use_objc = false;
249 use_regex = false;
250 show_args = true;
251 show_locals = true;
Greg Claytonaed58812010-09-13 02:37:44 +0000252 show_globals = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000253 show_types = true;
254 show_scope = false;
255 show_summary = true;
256 show_location = false;
Greg Claytonaed58812010-09-13 02:37:44 +0000257 show_decl = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000258 debug = false;
259 max_depth = UINT32_MAX;
260 ptr_depth = 0;
261 globals.clear();
262 }
263
264 const lldb::OptionDefinition*
265 GetDefinitions ()
266 {
267 return g_option_table;
268 }
269
270 // Options table: Required for subclasses of Options.
271
272 static lldb::OptionDefinition g_option_table[];
273 std::string name;
Greg Claytonaed58812010-09-13 02:37:44 +0000274 bool use_objc:1,
275 use_regex:1,
276 show_args:1,
277 show_locals:1,
278 show_globals:1,
279 show_types:1,
280 show_scope:1,
281 show_summary:1,
282 show_location:1,
283 show_decl:1,
284 debug:1;
Jim Ingham537926c2010-09-02 00:18:39 +0000285 uint32_t max_depth; // The depth to print when dumping concrete (not pointers) aggreate values
286 uint32_t ptr_depth; // The default depth that is dumped when we find pointers
287 std::vector<ConstString> globals;
288 // Instance variables to hold the values for command options.
289 };
290
291 CommandObjectFrameVariable () :
292 CommandObject (
293 "frame variable",
294 "Show specified argument, local variable, static variable or global variable for the current frame. If none specified, list them all.",
295 "frame variable [<cmd-options>] [<var-name1> [<var-name2>...]]")
296 {
297 }
298
299 virtual
300 ~CommandObjectFrameVariable ()
301 {
302 }
303
304 virtual
305 Options *
306 GetOptions ()
307 {
308 return &m_options;
309 }
310
311 void
Jim Ingham537926c2010-09-02 00:18:39 +0000312 DumpValueObject (CommandReturnObject &result,
313 ExecutionContextScope *exe_scope,
314 ValueObject *valobj,
315 const char *root_valobj_name,
316 uint32_t ptr_depth,
317 uint32_t curr_depth,
318 uint32_t max_depth,
Greg Claytona357ecf2010-09-14 03:16:58 +0000319 bool use_objc,
320 bool scope_already_checked)
Jim Ingham537926c2010-09-02 00:18:39 +0000321 {
322 if (valobj)
323 {
324 Stream &s = result.GetOutputStream();
325
326 //const char *loc_cstr = valobj->GetLocationAsCString();
327 if (m_options.show_location)
328 {
329 s.Printf("@ %s: ", valobj->GetLocationAsCString(exe_scope));
330 }
331 if (m_options.debug)
332 s.Printf ("%p ValueObject{%u} ", valobj, valobj->GetID());
333
334 s.Indent();
335
336 if (m_options.show_types)
337 s.Printf("(%s) ", valobj->GetTypeName().AsCString());
338
339 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
340 s.Printf ("%s = ", name_cstr);
341
Greg Claytona357ecf2010-09-14 03:16:58 +0000342 if (!scope_already_checked && !valobj->IsInScope(exe_scope->CalculateStackFrame()))
343 {
344 s.PutCString("error: out of scope");
345 return;
346 }
347
Jim Ingham537926c2010-09-02 00:18:39 +0000348 const char *val_cstr = valobj->GetValueAsCString(exe_scope);
349 const char *err_cstr = valobj->GetError().AsCString();
350
351 if (err_cstr)
352 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000353 s.Printf ("error: %s", err_cstr);
Jim Ingham537926c2010-09-02 00:18:39 +0000354 }
355 else
356 {
357 const char *sum_cstr = valobj->GetSummaryAsCString(exe_scope);
358
359 const bool is_aggregate = ClangASTContext::IsAggregateType (valobj->GetOpaqueClangQualType());
360
361 if (val_cstr)
362 s.PutCString(val_cstr);
363
364 if (sum_cstr)
365 s.Printf(" %s", sum_cstr);
366
367 if (use_objc)
368 {
Jim Ingham4ae51962010-09-10 23:12:17 +0000369 const char *object_desc = valobj->GetObjectDescription(exe_scope);
370 if (object_desc)
371 s.Printf("\n%s\n", object_desc);
372 else
373 s.Printf ("No description available.\n");
Jim Ingham537926c2010-09-02 00:18:39 +0000374 return;
375 }
376
377
378 if (curr_depth < max_depth)
379 {
380 if (is_aggregate)
381 s.PutChar('{');
382
383 bool is_ptr_or_ref = ClangASTContext::IsPointerOrReferenceType (valobj->GetOpaqueClangQualType());
384
385 if (is_ptr_or_ref && ptr_depth == 0)
386 return;
387
388 const uint32_t num_children = valobj->GetNumChildren();
389 if (num_children)
390 {
391 s.IndentMore();
392 for (uint32_t idx=0; idx<num_children; ++idx)
393 {
394 ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true));
395 if (child_sp.get())
396 {
397 s.EOL();
398 DumpValueObject (result,
399 exe_scope,
400 child_sp.get(),
401 NULL,
402 is_ptr_or_ref ? ptr_depth - 1 : ptr_depth,
403 curr_depth + 1,
404 max_depth,
Greg Claytona357ecf2010-09-14 03:16:58 +0000405 false,
406 true);
Jim Ingham537926c2010-09-02 00:18:39 +0000407 if (idx + 1 < num_children)
408 s.PutChar(',');
409 }
410 }
411 s.IndentLess();
412 }
413 if (is_aggregate)
414 {
415 s.EOL();
416 s.Indent("}");
417 }
418 }
419 else
420 {
421 if (is_aggregate)
422 {
423 s.PutCString("{...}");
424 }
425 }
426
427 }
428 }
429 }
430
431 virtual bool
432 Execute
433 (
434 CommandInterpreter &interpreter,
435 Args& command,
436 CommandReturnObject &result
437 )
438 {
439 ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext());
440 if (exe_ctx.frame == NULL)
441 {
442 result.AppendError ("invalid frame");
443 result.SetStatus (eReturnStatusFailed);
444 return false;
445 }
446 else
447 {
Greg Claytonaed58812010-09-13 02:37:44 +0000448 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000449
Greg Claytonaed58812010-09-13 02:37:44 +0000450 bool get_file_globals = true;
451 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
452
Jim Ingham537926c2010-09-02 00:18:39 +0000453 VariableSP var_sp;
454 ValueObjectSP valobj_sp;
455 //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList();
456 const char *name_cstr = NULL;
457 size_t idx;
458 if (!m_options.globals.empty())
459 {
460 uint32_t fail_count = 0;
461 if (exe_ctx.target)
462 {
463 const size_t num_globals = m_options.globals.size();
464 for (idx = 0; idx < num_globals; ++idx)
465 {
466 VariableList global_var_list;
467 const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list);
468
469 if (num_matching_globals == 0)
470 {
471 ++fail_count;
472 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString());
473 }
474 else
475 {
476 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
477 {
478 var_sp = global_var_list.GetVariableAtIndex(global_idx);
479 if (var_sp)
480 {
Greg Clayton17dae082010-09-02 02:59:18 +0000481 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000482 if (!valobj_sp)
Greg Clayton17dae082010-09-02 02:59:18 +0000483 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000484
485 if (valobj_sp)
486 {
Greg Claytonaed58812010-09-13 02:37:44 +0000487 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
488 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000489 var_sp->GetDeclaration ().DumpStopContext (&s, false);
490 s.PutCString (": ");
Greg Claytonaed58812010-09-13 02:37:44 +0000491 }
492
Greg Claytona357ecf2010-09-14 03:16:58 +0000493 DumpValueObject (result,
494 exe_ctx.frame,
495 valobj_sp.get(),
496 name_cstr,
497 m_options.ptr_depth,
498 0,
499 m_options.max_depth,
500 m_options.use_objc,
501 false);
502
Greg Claytonaed58812010-09-13 02:37:44 +0000503 s.EOL();
Jim Ingham537926c2010-09-02 00:18:39 +0000504 }
505 }
506 }
507 }
508 }
509 }
510 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000511 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000512 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000513 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000514 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000515 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000516 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000517 // If we have any args to the variable command, we will make
518 // variable objects from them...
519 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000520 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000521 uint32_t ptr_depth = m_options.ptr_depth;
522 // If first character is a '*', then show pointer contents
523 if (name_cstr[0] == '*')
Jim Ingham537926c2010-09-02 00:18:39 +0000524 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000525 ++ptr_depth;
526 name_cstr++; // Skip the '*'
527 }
528
529 std::string var_path (name_cstr);
530 size_t separator_idx = var_path.find_first_of(".-[");
531
532 ConstString name_const_string;
533 if (separator_idx == std::string::npos)
534 name_const_string.SetCString (var_path.c_str());
535 else
536 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
537
538 var_sp = variable_list->FindVariable(name_const_string);
539 if (var_sp)
540 {
541 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
542
543 var_path.erase (0, name_const_string.GetLength ());
544 // We are dumping at least one child
545 while (separator_idx != std::string::npos)
Jim Ingham537926c2010-09-02 00:18:39 +0000546 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000547 // Calculate the next separator index ahead of time
548 ValueObjectSP child_valobj_sp;
549 const char separator_type = var_path[0];
550 switch (separator_type)
Jim Ingham537926c2010-09-02 00:18:39 +0000551 {
Jim Ingham537926c2010-09-02 00:18:39 +0000552
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000553 case '-':
554 if (var_path.size() >= 2 && var_path[1] != '>')
Jim Ingham537926c2010-09-02 00:18:39 +0000555 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000556 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
557 var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000558 var_path.clear();
559 valobj_sp.reset();
560 break;
561 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000562 var_path.erase (0, 1); // Remove the '-'
563 // Fall through
564 case '.':
Jim Ingham537926c2010-09-02 00:18:39 +0000565 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000566 var_path.erase (0, 1); // Remove the '.' or '>'
567 separator_idx = var_path.find_first_of(".-[");
568 ConstString child_name;
569 if (separator_idx == std::string::npos)
570 child_name.SetCString (var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000571 else
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000572 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
Jim Ingham537926c2010-09-02 00:18:39 +0000573
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000574 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Jim Ingham537926c2010-09-02 00:18:39 +0000575 if (!child_valobj_sp)
576 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000577 result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n",
578 valobj_sp->GetName().AsCString(),
579 child_name.GetCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000580 var_path.clear();
581 valobj_sp.reset();
582 break;
583 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000584 // Remove the child name from the path
585 var_path.erase(0, child_name.GetLength());
Jim Ingham537926c2010-09-02 00:18:39 +0000586 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000587 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000588
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000589 case '[':
590 // Array member access, or treating pointer as an array
591 if (var_path.size() > 2) // Need at least two brackets and a number
592 {
593 char *end = NULL;
594 int32_t child_index = ::strtol (&var_path[1], &end, 0);
595 if (end && *end == ']')
596 {
Jim Ingham537926c2010-09-02 00:18:39 +0000597
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000598 if (valobj_sp->IsPointerType ())
599 {
600 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
601 }
602 else
603 {
604 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
605 }
606
607 if (!child_valobj_sp)
608 {
609 result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n",
610 child_index,
611 valobj_sp->GetName().AsCString());
612 var_path.clear();
613 valobj_sp.reset();
614 break;
615 }
616
617 // Erase the array member specification '[%i]' where %i is the array index
618 var_path.erase(0, (end - var_path.c_str()) + 1);
619 separator_idx = var_path.find_first_of(".-[");
620
621 // Break out early from the switch since we were able to find the child member
622 break;
623 }
624 }
625 result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n",
626 valobj_sp->GetName().AsCString(),
Jim Ingham537926c2010-09-02 00:18:39 +0000627 var_path.c_str());
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000628 var_path.clear();
629 valobj_sp.reset();
630 break;
631
632 break;
633
634 default:
635 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
636 var_path.c_str());
637 var_path.clear();
638 valobj_sp.reset();
639 separator_idx = std::string::npos;
640 break;
641 }
642
643 if (child_valobj_sp)
644 valobj_sp = child_valobj_sp;
645
646 if (var_path.empty())
647 break;
648
Jim Ingham537926c2010-09-02 00:18:39 +0000649 }
650
Greg Claytonaed58812010-09-13 02:37:44 +0000651 if (valobj_sp)
652 {
Greg Claytonaed58812010-09-13 02:37:44 +0000653 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
654 {
655 var_sp->GetDeclaration ().DumpStopContext (&s, false);
656 s.PutCString (": ");
657 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000658
Greg Claytonaed58812010-09-13 02:37:44 +0000659 DumpValueObject (result,
660 exe_ctx.frame,
661 valobj_sp.get(),
662 name_cstr,
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000663 ptr_depth,
Greg Claytonaed58812010-09-13 02:37:44 +0000664 0,
665 m_options.max_depth,
Greg Claytona357ecf2010-09-14 03:16:58 +0000666 m_options.use_objc,
667 false);
Greg Claytonaed58812010-09-13 02:37:44 +0000668
669 s.EOL();
670 }
671 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000672 else
673 {
674 result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr);
675 var_path.clear();
676 }
Jim Ingham537926c2010-09-02 00:18:39 +0000677 }
678 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000679 else
680 {
681 const uint32_t num_variables = variable_list->GetSize();
682
683 if (num_variables > 0)
684 {
685 for (uint32_t i=0; i<num_variables; i++)
686 {
687 VariableSP var_sp (variable_list->GetVariableAtIndex(i));
688 bool dump_variable = true;
689
690 switch (var_sp->GetScope())
691 {
692 case eValueTypeVariableGlobal:
693 dump_variable = m_options.show_globals;
694 if (dump_variable && m_options.show_scope)
695 s.PutCString("GLOBAL: ");
696 break;
697
698 case eValueTypeVariableStatic:
699 dump_variable = m_options.show_globals;
700 if (dump_variable && m_options.show_scope)
701 s.PutCString("STATIC: ");
702 break;
703
704 case eValueTypeVariableArgument:
705 dump_variable = m_options.show_args;
706 if (dump_variable && m_options.show_scope)
707 s.PutCString(" ARG: ");
708 break;
709
710 case eValueTypeVariableLocal:
711 dump_variable = m_options.show_locals;
712 if (dump_variable && m_options.show_scope)
713 s.PutCString(" LOCAL: ");
714 break;
715
716 default:
717 break;
718 }
719
720 if (dump_variable)
721 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000722
723 // Use the variable object code to make sure we are
724 // using the same APIs as the the public API will be
725 // using...
726 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
727 if (valobj_sp)
728 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000729 // When dumping all variables, don't print any variables
730 // that are not in scope to avoid extra unneeded output
731 if (valobj_sp->IsInScope (exe_ctx.frame))
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000732 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000733 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
734 {
735 var_sp->GetDeclaration ().DumpStopContext (&s, false);
736 s.PutCString (": ");
737 }
738 DumpValueObject (result,
739 exe_ctx.frame,
740 valobj_sp.get(),
741 name_cstr,
742 m_options.ptr_depth,
743 0,
744 m_options.max_depth,
745 m_options.use_objc,
746 true);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000747
Greg Claytona357ecf2010-09-14 03:16:58 +0000748 s.EOL();
749 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000750 }
751 }
752 }
753 }
754 }
755 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000756 }
Jim Ingham537926c2010-09-02 00:18:39 +0000757 }
758 return result.Succeeded();
759 }
760protected:
761
762 CommandOptions m_options;
763};
764
765lldb::OptionDefinition
766CommandObjectFrameVariable::CommandOptions::g_option_table[] =
767{
Greg Claytonaed58812010-09-13 02:37:44 +0000768{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, NULL, "Enable verbose debug information."},
Jim Ingham537926c2010-09-02 00:18:39 +0000769{ LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, "<count>", "Set the max recurse depth when dumping aggregate types (default is infinity)."},
Greg Claytonaed58812010-09-13 02:37:44 +0000770{ LLDB_OPT_SET_1, false, "show-globals",'g', no_argument, NULL, 0, NULL, "Show the current frame source file global and static variables."},
771{ LLDB_OPT_SET_1, false, "find-global",'G', required_argument, NULL, 0, NULL, "Find a global variable by name (which might not be in the current stack frame source file)."},
Jim Ingham537926c2010-09-02 00:18:39 +0000772{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, NULL, "Show variable location information."},
Greg Claytonaed58812010-09-13 02:37:44 +0000773{ LLDB_OPT_SET_1, false, "show-declaration", 'c', no_argument, NULL, 0, NULL, "Show variable declaration information (source file and line where the variable was declared)."},
Jim Ingham537926c2010-09-02 00:18:39 +0000774{ LLDB_OPT_SET_1, false, "name", 'n', required_argument, NULL, 0, "<name>", "Lookup a variable by name or regex (--regex) for the current execution context."},
775{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, NULL, "Omit function arguments."},
776{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, NULL, "Omit local variables."},
777{ LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, NULL, "Omit variable type names."},
778{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, NULL, "Omit summary information."},
779{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, NULL, "Show variable scope (argument, local, global, static)."},
780{ LLDB_OPT_SET_1, false, "objc", 'o', no_argument, NULL, 0, NULL, "When looking up a variable by name (--name), print as an Objective-C object."},
781{ LLDB_OPT_SET_1, false, "ptr-depth", 'p', required_argument, NULL, 0, "<count>", "The number of pointers to be traversed when dumping values (default is zero)."},
782{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."},
783{ 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL }
784};
Chris Lattner24943d22010-06-08 16:52:24 +0000785#pragma mark CommandObjectMultiwordFrame
786
787//-------------------------------------------------------------------------
788// CommandObjectMultiwordFrame
789//-------------------------------------------------------------------------
790
Greg Clayton63094e02010-06-23 01:19:29 +0000791CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Chris Lattner24943d22010-06-08 16:52:24 +0000792 CommandObjectMultiword ("frame",
793 "A set of commands for operating on the current thread's frames.",
794 "frame <subcommand> [<subcommand-options>]")
795{
Greg Clayton63094e02010-06-23 01:19:29 +0000796 LoadSubCommand (interpreter, "info", CommandObjectSP (new CommandObjectFrameInfo ()));
797 LoadSubCommand (interpreter, "select", CommandObjectSP (new CommandObjectFrameSelect ()));
Jim Ingham537926c2010-09-02 00:18:39 +0000798 LoadSubCommand (interpreter, "variable", CommandObjectSP (new CommandObjectFrameVariable ()));
Chris Lattner24943d22010-06-08 16:52:24 +0000799}
800
801CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
802{
803}
804