blob: 013e8c908a1a0099adaa9f2247a673b56fd6ff47 [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;
208 case 'g': show_globals = false; break;
209 case 't': show_types = false; break;
210 case 'y': show_summary = false; break;
211 case 'L': show_location= true; break;
212 case 'D': debug = true; break;
213 case 'd':
214 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
215 if (!success)
216 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
217 break;
218
219 case 'p':
220 ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
221 if (!success)
222 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
223 break;
224
225 case 'G':
226 {
227 ConstString const_string (option_arg);
228 globals.push_back(const_string);
229 }
230 break;
231
232 case 's':
233 show_scope = true;
234 break;
235
236 default:
237 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
238 break;
239 }
240
241 return error;
242 }
243
244 void
245 ResetOptionValues ()
246 {
247 Options::ResetOptionValues();
248
249 name.clear();
250 use_objc = false;
251 use_regex = false;
252 show_args = true;
253 show_locals = true;
254 show_globals = true;
255 show_types = true;
256 show_scope = false;
257 show_summary = true;
258 show_location = false;
259 debug = false;
260 max_depth = UINT32_MAX;
261 ptr_depth = 0;
262 globals.clear();
263 }
264
265 const lldb::OptionDefinition*
266 GetDefinitions ()
267 {
268 return g_option_table;
269 }
270
271 // Options table: Required for subclasses of Options.
272
273 static lldb::OptionDefinition g_option_table[];
274 std::string name;
275 bool use_objc;
276 bool use_regex;
277 bool show_args;
278 bool show_locals;
279 bool show_globals;
280 bool show_types;
281 bool show_scope; // local/arg/global/static
282 bool show_summary;
283 bool show_location;
284 bool debug;
285 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
312 DumpVariable (CommandReturnObject &result, ExecutionContext *exe_ctx, Variable *variable)
313 {
314 if (variable)
315 {
316 Stream &s = result.GetOutputStream();
317 DWARFExpression &expr = variable->LocationExpression();
318 Value expr_result;
319 Error expr_error;
320 Type *variable_type = variable->GetType();
321 bool expr_success = expr.Evaluate(exe_ctx, NULL, NULL, expr_result, &expr_error);
322
323 if (m_options.debug)
324 s.Printf ("Variable{0x%8.8x}: ", variable->GetID());
325
326 if (!expr_success)
327 s.Printf ("%s = ERROR: %s\n", variable->GetName().AsCString(NULL), expr_error.AsCString());
328 else
329 {
330 Value::ValueType expr_value_type = expr_result.GetValueType();
331 switch (expr_value_type)
332 {
333 case Value::eValueTypeScalar:
334 s.Printf ("%s = ", variable->GetName().AsCString(NULL));
335 if (variable_type)
336 {
337 DataExtractor data;
338 if (expr_result.ResolveValue (exe_ctx, NULL).GetData (data))
339 variable_type->DumpValue (exe_ctx, &s, data, 0, m_options.show_types, m_options.show_summary, m_options.debug);
340 }
341 break;
342
343 case Value::eValueTypeFileAddress:
344 case Value::eValueTypeLoadAddress:
345 case Value::eValueTypeHostAddress:
346 {
347 s.Printf ("%s = ", variable->GetName().AsCString(NULL));
348 lldb::addr_t addr = LLDB_INVALID_ADDRESS;
349 lldb::AddressType addr_type = eAddressTypeLoad;
350
351 if (expr_value_type == Value::eValueTypeFileAddress)
352 {
353 lldb::addr_t file_addr = expr_result.ResolveValue (exe_ctx, NULL).ULongLong(LLDB_INVALID_ADDRESS);
354 SymbolContext var_sc;
355 variable->CalculateSymbolContext(&var_sc);
356 if (var_sc.module_sp)
357 {
358 ObjectFile *objfile = var_sc.module_sp->GetObjectFile();
359 if (objfile)
360 {
361 Address so_addr(file_addr, objfile->GetSectionList());
362 addr = so_addr.GetLoadAddress(exe_ctx->process);
363 }
364 if (addr == LLDB_INVALID_ADDRESS)
365 {
Caroline Ticeabb507a2010-09-08 21:06:11 +0000366 result.GetErrorStream().Printf ("error: %s is not loaded\n",
367 var_sc.module_sp->GetFileSpec().GetFilename().AsCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000368 }
369 }
370 else
371 {
Caroline Ticeabb507a2010-09-08 21:06:11 +0000372 result.GetErrorStream().Printf ("error: unable to resolve the variable address 0x%llx\n", file_addr);
Jim Ingham537926c2010-09-02 00:18:39 +0000373 }
374 }
375 else
376 {
377 if (expr_value_type == Value::eValueTypeHostAddress)
378 addr_type = eAddressTypeHost;
379 addr = expr_result.ResolveValue (exe_ctx, NULL).ULongLong(LLDB_INVALID_ADDRESS);
380 }
381
382 if (addr != LLDB_INVALID_ADDRESS)
383 {
384 if (m_options.debug)
385 s.Printf("@ 0x%8.8llx, value = ", addr);
386 variable_type->DumpValueInMemory (exe_ctx, &s, addr, addr_type, m_options.show_types, m_options.show_summary, m_options.debug);
387 }
388 }
389 break;
390 }
391 s.EOL();
392 }
393 }
394 }
395
396 void
397 DumpValueObject (CommandReturnObject &result,
398 ExecutionContextScope *exe_scope,
399 ValueObject *valobj,
400 const char *root_valobj_name,
401 uint32_t ptr_depth,
402 uint32_t curr_depth,
403 uint32_t max_depth,
404 bool use_objc)
405 {
406 if (valobj)
407 {
408 Stream &s = result.GetOutputStream();
409
410 //const char *loc_cstr = valobj->GetLocationAsCString();
411 if (m_options.show_location)
412 {
413 s.Printf("@ %s: ", valobj->GetLocationAsCString(exe_scope));
414 }
415 if (m_options.debug)
416 s.Printf ("%p ValueObject{%u} ", valobj, valobj->GetID());
417
418 s.Indent();
419
420 if (m_options.show_types)
421 s.Printf("(%s) ", valobj->GetTypeName().AsCString());
422
423 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
424 s.Printf ("%s = ", name_cstr);
425
426 const char *val_cstr = valobj->GetValueAsCString(exe_scope);
427 const char *err_cstr = valobj->GetError().AsCString();
428
429 if (err_cstr)
430 {
431 s.Printf ("error: %s\n", err_cstr);
432 }
433 else
434 {
435 const char *sum_cstr = valobj->GetSummaryAsCString(exe_scope);
436
437 const bool is_aggregate = ClangASTContext::IsAggregateType (valobj->GetOpaqueClangQualType());
438
439 if (val_cstr)
440 s.PutCString(val_cstr);
441
442 if (sum_cstr)
443 s.Printf(" %s", sum_cstr);
444
445 if (use_objc)
446 {
447 if (!ClangASTContext::IsPointerType (valobj->GetOpaqueClangQualType()))
448 return;
449
450 if (!valobj->GetValueIsValid())
451 return;
452
453 Process *process = exe_scope->CalculateProcess();
454
455 if (!process)
456 return;
457
458 Scalar scalar;
459
460 if (!ClangASTType::GetValueAsScalar (valobj->GetClangAST(),
461 valobj->GetOpaqueClangQualType(),
462 valobj->GetDataExtractor(),
463 0,
464 valobj->GetByteSize(),
465 scalar))
466 return;
467
468 ConstString po_output;
469
470 ExecutionContext exe_ctx;
471 exe_scope->Calculate(exe_ctx);
472
473 Value val(scalar);
474 val.SetContext(Value::eContextTypeOpaqueClangQualType,
475 ClangASTContext::GetVoidPtrType(valobj->GetClangAST(), false));
476
477 if (!process->GetObjCObjectPrinter().PrintObject(po_output, val, exe_ctx))
478 return;
479
480 s.Printf("\n%s\n", po_output.GetCString());
481
482 return;
483 }
484
485
486 if (curr_depth < max_depth)
487 {
488 if (is_aggregate)
489 s.PutChar('{');
490
491 bool is_ptr_or_ref = ClangASTContext::IsPointerOrReferenceType (valobj->GetOpaqueClangQualType());
492
493 if (is_ptr_or_ref && ptr_depth == 0)
494 return;
495
496 const uint32_t num_children = valobj->GetNumChildren();
497 if (num_children)
498 {
499 s.IndentMore();
500 for (uint32_t idx=0; idx<num_children; ++idx)
501 {
502 ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true));
503 if (child_sp.get())
504 {
505 s.EOL();
506 DumpValueObject (result,
507 exe_scope,
508 child_sp.get(),
509 NULL,
510 is_ptr_or_ref ? ptr_depth - 1 : ptr_depth,
511 curr_depth + 1,
512 max_depth,
513 false);
514 if (idx + 1 < num_children)
515 s.PutChar(',');
516 }
517 }
518 s.IndentLess();
519 }
520 if (is_aggregate)
521 {
522 s.EOL();
523 s.Indent("}");
524 }
525 }
526 else
527 {
528 if (is_aggregate)
529 {
530 s.PutCString("{...}");
531 }
532 }
533
534 }
535 }
536 }
537
538 virtual bool
539 Execute
540 (
541 CommandInterpreter &interpreter,
542 Args& command,
543 CommandReturnObject &result
544 )
545 {
546 ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext());
547 if (exe_ctx.frame == NULL)
548 {
549 result.AppendError ("invalid frame");
550 result.SetStatus (eReturnStatusFailed);
551 return false;
552 }
553 else
554 {
555 VariableList variable_list;
556
557 bool show_inlined = true; // TODO: Get this from the process
558 SymbolContext frame_sc = exe_ctx.frame->GetSymbolContext (eSymbolContextEverything);
559 if (exe_ctx.frame && frame_sc.block)
560 frame_sc.block->AppendVariables(true, true, show_inlined, &variable_list);
561 VariableSP var_sp;
562 ValueObjectSP valobj_sp;
563 //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList();
564 const char *name_cstr = NULL;
565 size_t idx;
566 if (!m_options.globals.empty())
567 {
568 uint32_t fail_count = 0;
569 if (exe_ctx.target)
570 {
571 const size_t num_globals = m_options.globals.size();
572 for (idx = 0; idx < num_globals; ++idx)
573 {
574 VariableList global_var_list;
575 const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list);
576
577 if (num_matching_globals == 0)
578 {
579 ++fail_count;
580 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString());
581 }
582 else
583 {
584 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
585 {
586 var_sp = global_var_list.GetVariableAtIndex(global_idx);
587 if (var_sp)
588 {
Greg Clayton17dae082010-09-02 02:59:18 +0000589 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000590 if (!valobj_sp)
Greg Clayton17dae082010-09-02 02:59:18 +0000591 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000592
593 if (valobj_sp)
594 {
Jim Ingham537926c2010-09-02 00:18:39 +0000595 DumpValueObject (result, exe_ctx.frame, valobj_sp.get(), name_cstr, m_options.ptr_depth, 0, m_options.max_depth, false);
596 result.GetOutputStream().EOL();
597 }
598 }
599 }
600 }
601 }
602 }
603 if (fail_count)
604 {
605 result.SetStatus (eReturnStatusFailed);
606 }
607 }
608
609 if (command.GetArgumentCount() > 0)
610 {
611 // If we have any args to the variable command, we will make
612 // variable objects from them...
613 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
614 {
615 uint32_t ptr_depth = m_options.ptr_depth;
616 // If first character is a '*', then show pointer contents
617 if (name_cstr[0] == '*')
618 {
619 ++ptr_depth;
620 name_cstr++; // Skip the '*'
621 }
622
623 std::string var_path (name_cstr);
624 size_t separator_idx = var_path.find_first_of(".-[");
625
626 ConstString name_const_string;
627 if (separator_idx == std::string::npos)
628 name_const_string.SetCString (var_path.c_str());
629 else
630 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
631
632 var_sp = variable_list.FindVariable(name_const_string);
633 if (var_sp)
634 {
Greg Clayton17dae082010-09-02 02:59:18 +0000635 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000636
637 var_path.erase (0, name_const_string.GetLength ());
638 // We are dumping at least one child
639 while (separator_idx != std::string::npos)
640 {
641 // Calculate the next separator index ahead of time
642 ValueObjectSP child_valobj_sp;
643 const char separator_type = var_path[0];
644 switch (separator_type)
645 {
646
647 case '-':
648 if (var_path.size() >= 2 && var_path[1] != '>')
649 {
650 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
651 var_path.c_str());
652 var_path.clear();
653 valobj_sp.reset();
654 break;
655 }
656 var_path.erase (0, 1); // Remove the '-'
657 // Fall through
658 case '.':
659 {
660 var_path.erase (0, 1); // Remove the '.' or '>'
661 separator_idx = var_path.find_first_of(".-[");
662 ConstString child_name;
663 if (separator_idx == std::string::npos)
664 child_name.SetCString (var_path.c_str());
665 else
666 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
667
668 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
669 if (!child_valobj_sp)
670 {
671 result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n",
672 valobj_sp->GetName().AsCString(),
673 child_name.GetCString());
674 var_path.clear();
675 valobj_sp.reset();
676 break;
677 }
678 // Remove the child name from the path
679 var_path.erase(0, child_name.GetLength());
680 }
681 break;
682
683 case '[':
684 // Array member access, or treating pointer as an array
685 if (var_path.size() > 2) // Need at least two brackets and a number
686 {
687 char *end = NULL;
688 int32_t child_index = ::strtol (&var_path[1], &end, 0);
689 if (end && *end == ']')
690 {
691
692 if (valobj_sp->IsPointerType ())
693 {
694 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
695 }
696 else
697 {
698 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
699 }
700
701 if (!child_valobj_sp)
702 {
703 result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n",
704 child_index,
705 valobj_sp->GetName().AsCString());
706 var_path.clear();
707 valobj_sp.reset();
708 break;
709 }
710
711 // Erase the array member specification '[%i]' where %i is the array index
712 var_path.erase(0, (end - var_path.c_str()) + 1);
713 separator_idx = var_path.find_first_of(".-[");
714
715 // Break out early from the switch since we were able to find the child member
716 break;
717 }
718 }
719 result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n",
720 valobj_sp->GetName().AsCString(),
721 var_path.c_str());
722 var_path.clear();
723 valobj_sp.reset();
724 break;
725
726 break;
727
728 default:
729 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
730 var_path.c_str());
731 var_path.clear();
732 valobj_sp.reset();
733 separator_idx = std::string::npos;
734 break;
735 }
736
737 if (child_valobj_sp)
738 valobj_sp = child_valobj_sp;
739
740 if (var_path.empty())
741 break;
742
743 }
744
745 if (valobj_sp)
746 {
747 DumpValueObject (result, exe_ctx.frame, valobj_sp.get(), name_cstr, ptr_depth, 0, m_options.max_depth, m_options.use_objc);
748 result.GetOutputStream().EOL();
749 }
750 }
751 else
752 {
753 result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr);
754 var_path.clear();
755 }
756 }
757 }
758 else
759 {
760
761 if (m_options.show_globals)
762 {
763 if (frame_sc.comp_unit)
764 {
765 variable_list.AddVariables (frame_sc.comp_unit->GetVariableList(true).get());
766 }
767 }
768
769 const uint32_t num_variables = variable_list.GetSize();
770
771 if (num_variables > 0)
772 {
773 for (uint32_t i=0; i<num_variables; i++)
774 {
775 Variable *variable = variable_list.GetVariableAtIndex(i).get();
776 bool dump_variable = true;
777
778 switch (variable->GetScope())
779 {
780 case eValueTypeVariableGlobal:
781 dump_variable = m_options.show_globals;
782 if (dump_variable && m_options.show_scope)
783 result.GetOutputStream().PutCString("GLOBAL: ");
784 break;
785
786 case eValueTypeVariableStatic:
787 dump_variable = m_options.show_globals;
788 if (dump_variable && m_options.show_scope)
789 result.GetOutputStream().PutCString("STATIC: ");
790 break;
791
792 case eValueTypeVariableArgument:
793 dump_variable = m_options.show_args;
794 if (dump_variable && m_options.show_scope)
795 result.GetOutputStream().PutCString(" ARG: ");
796 break;
797
798 case eValueTypeVariableLocal:
799 dump_variable = m_options.show_locals;
800 if (dump_variable && m_options.show_scope)
801 result.GetOutputStream().PutCString(" LOCAL: ");
802 break;
803
804 default:
805 break;
806 }
807
808 if (dump_variable)
809 DumpVariable (result, &exe_ctx, variable);
810 }
811 }
812 }
813 result.SetStatus (eReturnStatusSuccessFinishResult);
814 }
815 return result.Succeeded();
816 }
817protected:
818
819 CommandOptions m_options;
820};
821
822lldb::OptionDefinition
823CommandObjectFrameVariable::CommandOptions::g_option_table[] =
824{
825{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, NULL, "Show verbose debug information."},
826{ LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, "<count>", "Set the max recurse depth when dumping aggregate types (default is infinity)."},
827{ LLDB_OPT_SET_1, false, "globals", 'g', no_argument, NULL, 0, NULL, "List global and static variables for the current stack frame source file."},
828{ LLDB_OPT_SET_1, false, "global", 'G', required_argument, NULL, 0, NULL, "Find a global variable by name (which might not be in the current stack frame source file)."},
829{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, NULL, "Show variable location information."},
830{ 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."},
831{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, NULL, "Omit function arguments."},
832{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, NULL, "Omit local variables."},
833{ LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, NULL, "Omit variable type names."},
834{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, NULL, "Omit summary information."},
835{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, NULL, "Show variable scope (argument, local, global, static)."},
836{ 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."},
837{ 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)."},
838{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."},
839{ 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL }
840};
Chris Lattner24943d22010-06-08 16:52:24 +0000841#pragma mark CommandObjectMultiwordFrame
842
843//-------------------------------------------------------------------------
844// CommandObjectMultiwordFrame
845//-------------------------------------------------------------------------
846
Greg Clayton63094e02010-06-23 01:19:29 +0000847CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Chris Lattner24943d22010-06-08 16:52:24 +0000848 CommandObjectMultiword ("frame",
849 "A set of commands for operating on the current thread's frames.",
850 "frame <subcommand> [<subcommand-options>]")
851{
Greg Clayton63094e02010-06-23 01:19:29 +0000852 LoadSubCommand (interpreter, "info", CommandObjectSP (new CommandObjectFrameInfo ()));
853 LoadSubCommand (interpreter, "select", CommandObjectSP (new CommandObjectFrameSelect ()));
Jim Ingham537926c2010-09-02 00:18:39 +0000854 LoadSubCommand (interpreter, "variable", CommandObjectSP (new CommandObjectFrameVariable ()));
Chris Lattner24943d22010-06-08 16:52:24 +0000855}
856
857CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
858{
859}
860