blob: e79937bfbf4f507376660ab74a3d7b5f0fe89cfb [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,
319 bool use_objc)
320 {
321 if (valobj)
322 {
323 Stream &s = result.GetOutputStream();
324
325 //const char *loc_cstr = valobj->GetLocationAsCString();
326 if (m_options.show_location)
327 {
328 s.Printf("@ %s: ", valobj->GetLocationAsCString(exe_scope));
329 }
330 if (m_options.debug)
331 s.Printf ("%p ValueObject{%u} ", valobj, valobj->GetID());
332
333 s.Indent();
334
335 if (m_options.show_types)
336 s.Printf("(%s) ", valobj->GetTypeName().AsCString());
337
338 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
339 s.Printf ("%s = ", name_cstr);
340
341 const char *val_cstr = valobj->GetValueAsCString(exe_scope);
342 const char *err_cstr = valobj->GetError().AsCString();
343
344 if (err_cstr)
345 {
346 s.Printf ("error: %s\n", err_cstr);
347 }
348 else
349 {
350 const char *sum_cstr = valobj->GetSummaryAsCString(exe_scope);
351
352 const bool is_aggregate = ClangASTContext::IsAggregateType (valobj->GetOpaqueClangQualType());
353
354 if (val_cstr)
355 s.PutCString(val_cstr);
356
357 if (sum_cstr)
358 s.Printf(" %s", sum_cstr);
359
360 if (use_objc)
361 {
Jim Ingham4ae51962010-09-10 23:12:17 +0000362 const char *object_desc = valobj->GetObjectDescription(exe_scope);
363 if (object_desc)
364 s.Printf("\n%s\n", object_desc);
365 else
366 s.Printf ("No description available.\n");
Jim Ingham537926c2010-09-02 00:18:39 +0000367 return;
368 }
369
370
371 if (curr_depth < max_depth)
372 {
373 if (is_aggregate)
374 s.PutChar('{');
375
376 bool is_ptr_or_ref = ClangASTContext::IsPointerOrReferenceType (valobj->GetOpaqueClangQualType());
377
378 if (is_ptr_or_ref && ptr_depth == 0)
379 return;
380
381 const uint32_t num_children = valobj->GetNumChildren();
382 if (num_children)
383 {
384 s.IndentMore();
385 for (uint32_t idx=0; idx<num_children; ++idx)
386 {
387 ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true));
388 if (child_sp.get())
389 {
390 s.EOL();
391 DumpValueObject (result,
392 exe_scope,
393 child_sp.get(),
394 NULL,
395 is_ptr_or_ref ? ptr_depth - 1 : ptr_depth,
396 curr_depth + 1,
397 max_depth,
398 false);
399 if (idx + 1 < num_children)
400 s.PutChar(',');
401 }
402 }
403 s.IndentLess();
404 }
405 if (is_aggregate)
406 {
407 s.EOL();
408 s.Indent("}");
409 }
410 }
411 else
412 {
413 if (is_aggregate)
414 {
415 s.PutCString("{...}");
416 }
417 }
418
419 }
420 }
421 }
422
423 virtual bool
424 Execute
425 (
426 CommandInterpreter &interpreter,
427 Args& command,
428 CommandReturnObject &result
429 )
430 {
431 ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext());
432 if (exe_ctx.frame == NULL)
433 {
434 result.AppendError ("invalid frame");
435 result.SetStatus (eReturnStatusFailed);
436 return false;
437 }
438 else
439 {
Greg Claytonaed58812010-09-13 02:37:44 +0000440 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000441
Greg Claytonaed58812010-09-13 02:37:44 +0000442 bool get_file_globals = true;
443 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
444
Jim Ingham537926c2010-09-02 00:18:39 +0000445 VariableSP var_sp;
446 ValueObjectSP valobj_sp;
447 //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList();
448 const char *name_cstr = NULL;
449 size_t idx;
450 if (!m_options.globals.empty())
451 {
452 uint32_t fail_count = 0;
453 if (exe_ctx.target)
454 {
455 const size_t num_globals = m_options.globals.size();
456 for (idx = 0; idx < num_globals; ++idx)
457 {
458 VariableList global_var_list;
459 const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list);
460
461 if (num_matching_globals == 0)
462 {
463 ++fail_count;
464 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString());
465 }
466 else
467 {
468 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
469 {
470 var_sp = global_var_list.GetVariableAtIndex(global_idx);
471 if (var_sp)
472 {
Greg Clayton17dae082010-09-02 02:59:18 +0000473 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000474 if (!valobj_sp)
Greg Clayton17dae082010-09-02 02:59:18 +0000475 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000476
477 if (valobj_sp)
478 {
Jim Ingham537926c2010-09-02 00:18:39 +0000479 DumpValueObject (result, exe_ctx.frame, valobj_sp.get(), name_cstr, m_options.ptr_depth, 0, m_options.max_depth, false);
Greg Claytonaed58812010-09-13 02:37:44 +0000480
481 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
482 {
483 var_sp->GetDeclaration ().Dump (&s);
484 }
485
486 s.EOL();
Jim Ingham537926c2010-09-02 00:18:39 +0000487 }
488 }
489 }
490 }
491 }
492 }
493 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000494 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000495 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000496 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000497 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000498 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000499 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000500 // If we have any args to the variable command, we will make
501 // variable objects from them...
502 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000503 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000504 uint32_t ptr_depth = m_options.ptr_depth;
505 // If first character is a '*', then show pointer contents
506 if (name_cstr[0] == '*')
Jim Ingham537926c2010-09-02 00:18:39 +0000507 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000508 ++ptr_depth;
509 name_cstr++; // Skip the '*'
510 }
511
512 std::string var_path (name_cstr);
513 size_t separator_idx = var_path.find_first_of(".-[");
514
515 ConstString name_const_string;
516 if (separator_idx == std::string::npos)
517 name_const_string.SetCString (var_path.c_str());
518 else
519 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
520
521 var_sp = variable_list->FindVariable(name_const_string);
522 if (var_sp)
523 {
524 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
525
526 var_path.erase (0, name_const_string.GetLength ());
527 // We are dumping at least one child
528 while (separator_idx != std::string::npos)
Jim Ingham537926c2010-09-02 00:18:39 +0000529 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000530 // Calculate the next separator index ahead of time
531 ValueObjectSP child_valobj_sp;
532 const char separator_type = var_path[0];
533 switch (separator_type)
Jim Ingham537926c2010-09-02 00:18:39 +0000534 {
Jim Ingham537926c2010-09-02 00:18:39 +0000535
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000536 case '-':
537 if (var_path.size() >= 2 && var_path[1] != '>')
Jim Ingham537926c2010-09-02 00:18:39 +0000538 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000539 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
540 var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000541 var_path.clear();
542 valobj_sp.reset();
543 break;
544 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000545 var_path.erase (0, 1); // Remove the '-'
546 // Fall through
547 case '.':
Jim Ingham537926c2010-09-02 00:18:39 +0000548 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000549 var_path.erase (0, 1); // Remove the '.' or '>'
550 separator_idx = var_path.find_first_of(".-[");
551 ConstString child_name;
552 if (separator_idx == std::string::npos)
553 child_name.SetCString (var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000554 else
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000555 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
Jim Ingham537926c2010-09-02 00:18:39 +0000556
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000557 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Jim Ingham537926c2010-09-02 00:18:39 +0000558 if (!child_valobj_sp)
559 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000560 result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n",
561 valobj_sp->GetName().AsCString(),
562 child_name.GetCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000563 var_path.clear();
564 valobj_sp.reset();
565 break;
566 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000567 // Remove the child name from the path
568 var_path.erase(0, child_name.GetLength());
Jim Ingham537926c2010-09-02 00:18:39 +0000569 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000570 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000571
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000572 case '[':
573 // Array member access, or treating pointer as an array
574 if (var_path.size() > 2) // Need at least two brackets and a number
575 {
576 char *end = NULL;
577 int32_t child_index = ::strtol (&var_path[1], &end, 0);
578 if (end && *end == ']')
579 {
Jim Ingham537926c2010-09-02 00:18:39 +0000580
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000581 if (valobj_sp->IsPointerType ())
582 {
583 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
584 }
585 else
586 {
587 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
588 }
589
590 if (!child_valobj_sp)
591 {
592 result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n",
593 child_index,
594 valobj_sp->GetName().AsCString());
595 var_path.clear();
596 valobj_sp.reset();
597 break;
598 }
599
600 // Erase the array member specification '[%i]' where %i is the array index
601 var_path.erase(0, (end - var_path.c_str()) + 1);
602 separator_idx = var_path.find_first_of(".-[");
603
604 // Break out early from the switch since we were able to find the child member
605 break;
606 }
607 }
608 result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n",
609 valobj_sp->GetName().AsCString(),
Jim Ingham537926c2010-09-02 00:18:39 +0000610 var_path.c_str());
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000611 var_path.clear();
612 valobj_sp.reset();
613 break;
614
615 break;
616
617 default:
618 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
619 var_path.c_str());
620 var_path.clear();
621 valobj_sp.reset();
622 separator_idx = std::string::npos;
623 break;
624 }
625
626 if (child_valobj_sp)
627 valobj_sp = child_valobj_sp;
628
629 if (var_path.empty())
630 break;
631
Jim Ingham537926c2010-09-02 00:18:39 +0000632 }
633
Greg Claytonaed58812010-09-13 02:37:44 +0000634 if (valobj_sp)
635 {
Greg Claytonaed58812010-09-13 02:37:44 +0000636 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
637 {
638 var_sp->GetDeclaration ().DumpStopContext (&s, false);
639 s.PutCString (": ");
640 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000641
Greg Claytonaed58812010-09-13 02:37:44 +0000642 DumpValueObject (result,
643 exe_ctx.frame,
644 valobj_sp.get(),
645 name_cstr,
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000646 ptr_depth,
Greg Claytonaed58812010-09-13 02:37:44 +0000647 0,
648 m_options.max_depth,
649 m_options.use_objc);
650
651 s.EOL();
652 }
653 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000654 else
655 {
656 result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr);
657 var_path.clear();
658 }
Jim Ingham537926c2010-09-02 00:18:39 +0000659 }
660 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000661 else
662 {
663 const uint32_t num_variables = variable_list->GetSize();
664
665 if (num_variables > 0)
666 {
667 for (uint32_t i=0; i<num_variables; i++)
668 {
669 VariableSP var_sp (variable_list->GetVariableAtIndex(i));
670 bool dump_variable = true;
671
672 switch (var_sp->GetScope())
673 {
674 case eValueTypeVariableGlobal:
675 dump_variable = m_options.show_globals;
676 if (dump_variable && m_options.show_scope)
677 s.PutCString("GLOBAL: ");
678 break;
679
680 case eValueTypeVariableStatic:
681 dump_variable = m_options.show_globals;
682 if (dump_variable && m_options.show_scope)
683 s.PutCString("STATIC: ");
684 break;
685
686 case eValueTypeVariableArgument:
687 dump_variable = m_options.show_args;
688 if (dump_variable && m_options.show_scope)
689 s.PutCString(" ARG: ");
690 break;
691
692 case eValueTypeVariableLocal:
693 dump_variable = m_options.show_locals;
694 if (dump_variable && m_options.show_scope)
695 s.PutCString(" LOCAL: ");
696 break;
697
698 default:
699 break;
700 }
701
702 if (dump_variable)
703 {
704 //DumpVariable (result, &exe_ctx, var_sp.get());
705
706 // Use the variable object code to make sure we are
707 // using the same APIs as the the public API will be
708 // using...
709 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
710 if (valobj_sp)
711 {
712
713 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
714 {
715 var_sp->GetDeclaration ().DumpStopContext (&s, false);
716 s.PutCString (": ");
717 }
718 DumpValueObject (result,
719 exe_ctx.frame,
720 valobj_sp.get(),
721 name_cstr,
722 m_options.ptr_depth,
723 0,
724 m_options.max_depth,
725 m_options.use_objc);
726
727 s.EOL();
728 }
729 }
730 }
731 }
732 }
733 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000734 }
Jim Ingham537926c2010-09-02 00:18:39 +0000735 }
736 return result.Succeeded();
737 }
738protected:
739
740 CommandOptions m_options;
741};
742
743lldb::OptionDefinition
744CommandObjectFrameVariable::CommandOptions::g_option_table[] =
745{
Greg Claytonaed58812010-09-13 02:37:44 +0000746{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, NULL, "Enable verbose debug information."},
Jim Ingham537926c2010-09-02 00:18:39 +0000747{ 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 +0000748{ LLDB_OPT_SET_1, false, "show-globals",'g', no_argument, NULL, 0, NULL, "Show the current frame source file global and static variables."},
749{ 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 +0000750{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, NULL, "Show variable location information."},
Greg Claytonaed58812010-09-13 02:37:44 +0000751{ 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 +0000752{ 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."},
753{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, NULL, "Omit function arguments."},
754{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, NULL, "Omit local variables."},
755{ LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, NULL, "Omit variable type names."},
756{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, NULL, "Omit summary information."},
757{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, NULL, "Show variable scope (argument, local, global, static)."},
758{ 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."},
759{ 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)."},
760{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."},
761{ 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL }
762};
Chris Lattner24943d22010-06-08 16:52:24 +0000763#pragma mark CommandObjectMultiwordFrame
764
765//-------------------------------------------------------------------------
766// CommandObjectMultiwordFrame
767//-------------------------------------------------------------------------
768
Greg Clayton63094e02010-06-23 01:19:29 +0000769CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Chris Lattner24943d22010-06-08 16:52:24 +0000770 CommandObjectMultiword ("frame",
771 "A set of commands for operating on the current thread's frames.",
772 "frame <subcommand> [<subcommand-options>]")
773{
Greg Clayton63094e02010-06-23 01:19:29 +0000774 LoadSubCommand (interpreter, "info", CommandObjectSP (new CommandObjectFrameInfo ()));
775 LoadSubCommand (interpreter, "select", CommandObjectSP (new CommandObjectFrameSelect ()));
Jim Ingham537926c2010-09-02 00:18:39 +0000776 LoadSubCommand (interpreter, "variable", CommandObjectSP (new CommandObjectFrameVariable ()));
Chris Lattner24943d22010-06-08 16:52:24 +0000777}
778
779CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
780{
781}
782