blob: 04136642f150539734fad35b90049a195bb352ae [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 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
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.",
101 "frame select <frame-index>",
102 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +0000103 {
104 }
105
106 ~CommandObjectFrameSelect ()
107 {
108 }
109
110 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000111 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000112 CommandReturnObject &result)
113 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000114 ExecutionContext exe_ctx (m_interpreter.GetDebugger().GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000115 if (exe_ctx.thread)
116 {
117 if (command.GetArgumentCount() == 1)
118 {
119 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
120
121 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
122 const uint32_t frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
123 if (frame_idx < num_frames)
124 {
Jim Inghamc8332952010-08-26 21:32:51 +0000125 exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
126 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000127
128 if (exe_ctx.frame)
129 {
Jim Ingham74989e82010-08-30 19:44:40 +0000130 bool already_shown = false;
131 SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
Greg Clayton238c0a12010-09-18 01:14:36 +0000132 if (m_interpreter.GetDebugger().UseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Jim Ingham74989e82010-08-30 19:44:40 +0000133 {
134 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
135 }
136
Chris Lattner24943d22010-06-08 16:52:24 +0000137 if (DisplayFrameForExecutionContext (exe_ctx.thread,
138 exe_ctx.frame,
Greg Clayton238c0a12010-09-18 01:14:36 +0000139 m_interpreter,
Chris Lattner24943d22010-06-08 16:52:24 +0000140 result.GetOutputStream(),
141 true,
Jim Ingham74989e82010-08-30 19:44:40 +0000142 !already_shown,
Chris Lattner24943d22010-06-08 16:52:24 +0000143 3,
144 3))
145 {
146 result.SetStatus (eReturnStatusSuccessFinishResult);
147 return result.Succeeded();
148 }
149 }
150 }
151 if (frame_idx == UINT32_MAX)
152 result.AppendErrorWithFormat ("Invalid frame index: %s.\n", frame_idx_cstr);
153 else
154 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
155 }
156 else
157 {
158 result.AppendError ("invalid arguments");
159 result.AppendErrorWithFormat ("Usage: %s\n", m_cmd_syntax.c_str());
160 }
161 }
162 else
163 {
164 result.AppendError ("no current thread");
165 }
166 result.SetStatus (eReturnStatusFailed);
167 return false;
168 }
169};
170
Jim Ingham537926c2010-09-02 00:18:39 +0000171#pragma mark CommandObjectFrameVariable
172//----------------------------------------------------------------------
173// List images with associated information
174//----------------------------------------------------------------------
175class CommandObjectFrameVariable : public CommandObject
176{
177public:
178
179 class CommandOptions : public Options
180 {
181 public:
182
183 CommandOptions () :
184 Options()
185 {
186 ResetOptionValues ();
187 }
188
189 virtual
190 ~CommandOptions ()
191 {
192 }
193
194 virtual Error
195 SetOptionValue (int option_idx, const char *option_arg)
196 {
197 Error error;
198 bool success;
199 char short_option = (char) m_getopt_table[option_idx].val;
200 switch (short_option)
201 {
202 case 'o': use_objc = true; break;
203 case 'n': name = option_arg; break;
204 case 'r': use_regex = true; break;
205 case 'a': show_args = false; break;
206 case 'l': show_locals = false; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000207 case 'g': show_globals = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000208 case 't': show_types = false; break;
209 case 'y': show_summary = false; break;
210 case 'L': show_location= true; break;
Greg Claytonaed58812010-09-13 02:37:44 +0000211 case 'c': show_decl = true; break;
Jim Ingham537926c2010-09-02 00:18:39 +0000212 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':
Greg Claytonaed58812010-09-13 02:37:44 +0000226 globals.push_back(ConstString (option_arg));
Jim Ingham537926c2010-09-02 00:18:39 +0000227 break;
228
229 case 's':
230 show_scope = true;
231 break;
232
233 default:
234 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
235 break;
236 }
237
238 return error;
239 }
240
241 void
242 ResetOptionValues ()
243 {
244 Options::ResetOptionValues();
245
246 name.clear();
247 use_objc = false;
248 use_regex = false;
249 show_args = true;
250 show_locals = true;
Greg Claytonaed58812010-09-13 02:37:44 +0000251 show_globals = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000252 show_types = true;
253 show_scope = false;
254 show_summary = true;
255 show_location = false;
Greg Claytonaed58812010-09-13 02:37:44 +0000256 show_decl = false;
Jim Ingham537926c2010-09-02 00:18:39 +0000257 debug = false;
258 max_depth = UINT32_MAX;
259 ptr_depth = 0;
260 globals.clear();
261 }
262
263 const lldb::OptionDefinition*
264 GetDefinitions ()
265 {
266 return g_option_table;
267 }
268
269 // Options table: Required for subclasses of Options.
270
271 static lldb::OptionDefinition g_option_table[];
272 std::string name;
Greg Claytonaed58812010-09-13 02:37:44 +0000273 bool use_objc:1,
274 use_regex:1,
275 show_args:1,
276 show_locals:1,
277 show_globals:1,
278 show_types:1,
279 show_scope:1,
280 show_summary:1,
281 show_location:1,
282 show_decl:1,
283 debug:1;
Jim Ingham537926c2010-09-02 00:18:39 +0000284 uint32_t max_depth; // The depth to print when dumping concrete (not pointers) aggreate values
285 uint32_t ptr_depth; // The default depth that is dumped when we find pointers
286 std::vector<ConstString> globals;
287 // Instance variables to hold the values for command options.
288 };
289
Greg Clayton238c0a12010-09-18 01:14:36 +0000290 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
291 CommandObject (interpreter,
292 "frame variable",
293 "Show specified argument, local variable, static variable or global variable for the current frame. If none specified, list them all.",
294 "frame variable [<cmd-options>] [<var-name1> [<var-name2>...]]")
Jim Ingham537926c2010-09-02 00:18:39 +0000295 {
296 }
297
298 virtual
299 ~CommandObjectFrameVariable ()
300 {
301 }
302
303 virtual
304 Options *
305 GetOptions ()
306 {
307 return &m_options;
308 }
309
310 void
Jim Ingham537926c2010-09-02 00:18:39 +0000311 DumpValueObject (CommandReturnObject &result,
312 ExecutionContextScope *exe_scope,
313 ValueObject *valobj,
314 const char *root_valobj_name,
315 uint32_t ptr_depth,
316 uint32_t curr_depth,
317 uint32_t max_depth,
Greg Claytona357ecf2010-09-14 03:16:58 +0000318 bool use_objc,
319 bool scope_already_checked)
Jim Ingham537926c2010-09-02 00:18:39 +0000320 {
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
Greg Claytona357ecf2010-09-14 03:16:58 +0000341 if (!scope_already_checked && !valobj->IsInScope(exe_scope->CalculateStackFrame()))
342 {
343 s.PutCString("error: out of scope");
344 return;
345 }
346
Jim Ingham537926c2010-09-02 00:18:39 +0000347 const char *val_cstr = valobj->GetValueAsCString(exe_scope);
348 const char *err_cstr = valobj->GetError().AsCString();
349
350 if (err_cstr)
351 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000352 s.Printf ("error: %s", err_cstr);
Jim Ingham537926c2010-09-02 00:18:39 +0000353 }
354 else
355 {
356 const char *sum_cstr = valobj->GetSummaryAsCString(exe_scope);
357
358 const bool is_aggregate = ClangASTContext::IsAggregateType (valobj->GetOpaqueClangQualType());
359
360 if (val_cstr)
361 s.PutCString(val_cstr);
362
363 if (sum_cstr)
364 s.Printf(" %s", sum_cstr);
365
366 if (use_objc)
367 {
Jim Ingham4ae51962010-09-10 23:12:17 +0000368 const char *object_desc = valobj->GetObjectDescription(exe_scope);
369 if (object_desc)
370 s.Printf("\n%s\n", object_desc);
371 else
372 s.Printf ("No description available.\n");
Jim Ingham537926c2010-09-02 00:18:39 +0000373 return;
374 }
375
376
377 if (curr_depth < max_depth)
378 {
379 if (is_aggregate)
380 s.PutChar('{');
381
382 bool is_ptr_or_ref = ClangASTContext::IsPointerOrReferenceType (valobj->GetOpaqueClangQualType());
383
384 if (is_ptr_or_ref && ptr_depth == 0)
385 return;
386
387 const uint32_t num_children = valobj->GetNumChildren();
388 if (num_children)
389 {
390 s.IndentMore();
391 for (uint32_t idx=0; idx<num_children; ++idx)
392 {
393 ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true));
394 if (child_sp.get())
395 {
396 s.EOL();
397 DumpValueObject (result,
398 exe_scope,
399 child_sp.get(),
400 NULL,
401 is_ptr_or_ref ? ptr_depth - 1 : ptr_depth,
402 curr_depth + 1,
403 max_depth,
Greg Claytona357ecf2010-09-14 03:16:58 +0000404 false,
405 true);
Jim Ingham537926c2010-09-02 00:18:39 +0000406 if (idx + 1 < num_children)
407 s.PutChar(',');
408 }
409 }
410 s.IndentLess();
411 }
412 if (is_aggregate)
413 {
414 s.EOL();
415 s.Indent("}");
416 }
417 }
418 else
419 {
420 if (is_aggregate)
421 {
422 s.PutCString("{...}");
423 }
424 }
425
426 }
427 }
428 }
429
430 virtual bool
431 Execute
432 (
Jim Ingham537926c2010-09-02 00:18:39 +0000433 Args& command,
434 CommandReturnObject &result
435 )
436 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000437 ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000438 if (exe_ctx.frame == NULL)
439 {
440 result.AppendError ("invalid frame");
441 result.SetStatus (eReturnStatusFailed);
442 return false;
443 }
444 else
445 {
Greg Claytonaed58812010-09-13 02:37:44 +0000446 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000447
Greg Claytonaed58812010-09-13 02:37:44 +0000448 bool get_file_globals = true;
449 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
450
Jim Ingham537926c2010-09-02 00:18:39 +0000451 VariableSP var_sp;
452 ValueObjectSP valobj_sp;
453 //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList();
454 const char *name_cstr = NULL;
455 size_t idx;
456 if (!m_options.globals.empty())
457 {
458 uint32_t fail_count = 0;
459 if (exe_ctx.target)
460 {
461 const size_t num_globals = m_options.globals.size();
462 for (idx = 0; idx < num_globals; ++idx)
463 {
464 VariableList global_var_list;
465 const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list);
466
467 if (num_matching_globals == 0)
468 {
469 ++fail_count;
470 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString());
471 }
472 else
473 {
474 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
475 {
476 var_sp = global_var_list.GetVariableAtIndex(global_idx);
477 if (var_sp)
478 {
Greg Clayton17dae082010-09-02 02:59:18 +0000479 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000480 if (!valobj_sp)
Greg Clayton17dae082010-09-02 02:59:18 +0000481 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000482
483 if (valobj_sp)
484 {
Greg Claytonaed58812010-09-13 02:37:44 +0000485 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
486 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000487 var_sp->GetDeclaration ().DumpStopContext (&s, false);
488 s.PutCString (": ");
Greg Claytonaed58812010-09-13 02:37:44 +0000489 }
490
Greg Claytona357ecf2010-09-14 03:16:58 +0000491 DumpValueObject (result,
492 exe_ctx.frame,
493 valobj_sp.get(),
494 name_cstr,
495 m_options.ptr_depth,
496 0,
497 m_options.max_depth,
498 m_options.use_objc,
499 false);
500
Greg Claytonaed58812010-09-13 02:37:44 +0000501 s.EOL();
Jim Ingham537926c2010-09-02 00:18:39 +0000502 }
503 }
504 }
505 }
506 }
507 }
508 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000509 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000510 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000511 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000512 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000513 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000514 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000515 // If we have any args to the variable command, we will make
516 // variable objects from them...
517 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000518 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000519 uint32_t ptr_depth = m_options.ptr_depth;
520 // If first character is a '*', then show pointer contents
521 if (name_cstr[0] == '*')
Jim Ingham537926c2010-09-02 00:18:39 +0000522 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000523 ++ptr_depth;
524 name_cstr++; // Skip the '*'
525 }
526
527 std::string var_path (name_cstr);
528 size_t separator_idx = var_path.find_first_of(".-[");
529
530 ConstString name_const_string;
531 if (separator_idx == std::string::npos)
532 name_const_string.SetCString (var_path.c_str());
533 else
534 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
535
536 var_sp = variable_list->FindVariable(name_const_string);
537 if (var_sp)
538 {
539 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
540
541 var_path.erase (0, name_const_string.GetLength ());
542 // We are dumping at least one child
543 while (separator_idx != std::string::npos)
Jim Ingham537926c2010-09-02 00:18:39 +0000544 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000545 // Calculate the next separator index ahead of time
546 ValueObjectSP child_valobj_sp;
547 const char separator_type = var_path[0];
548 switch (separator_type)
Jim Ingham537926c2010-09-02 00:18:39 +0000549 {
Jim Ingham537926c2010-09-02 00:18:39 +0000550
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000551 case '-':
552 if (var_path.size() >= 2 && var_path[1] != '>')
Jim Ingham537926c2010-09-02 00:18:39 +0000553 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000554 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
555 var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000556 var_path.clear();
557 valobj_sp.reset();
558 break;
559 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000560 var_path.erase (0, 1); // Remove the '-'
561 // Fall through
562 case '.':
Jim Ingham537926c2010-09-02 00:18:39 +0000563 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000564 var_path.erase (0, 1); // Remove the '.' or '>'
565 separator_idx = var_path.find_first_of(".-[");
566 ConstString child_name;
567 if (separator_idx == std::string::npos)
568 child_name.SetCString (var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000569 else
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000570 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
Jim Ingham537926c2010-09-02 00:18:39 +0000571
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000572 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Jim Ingham537926c2010-09-02 00:18:39 +0000573 if (!child_valobj_sp)
574 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000575 result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n",
576 valobj_sp->GetName().AsCString(),
577 child_name.GetCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000578 var_path.clear();
579 valobj_sp.reset();
580 break;
581 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000582 // Remove the child name from the path
583 var_path.erase(0, child_name.GetLength());
Jim Ingham537926c2010-09-02 00:18:39 +0000584 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000585 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000586
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000587 case '[':
588 // Array member access, or treating pointer as an array
589 if (var_path.size() > 2) // Need at least two brackets and a number
590 {
591 char *end = NULL;
592 int32_t child_index = ::strtol (&var_path[1], &end, 0);
593 if (end && *end == ']')
594 {
Jim Ingham537926c2010-09-02 00:18:39 +0000595
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000596 if (valobj_sp->IsPointerType ())
597 {
598 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
599 }
600 else
601 {
602 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
603 }
604
605 if (!child_valobj_sp)
606 {
607 result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n",
608 child_index,
609 valobj_sp->GetName().AsCString());
610 var_path.clear();
611 valobj_sp.reset();
612 break;
613 }
614
615 // Erase the array member specification '[%i]' where %i is the array index
616 var_path.erase(0, (end - var_path.c_str()) + 1);
617 separator_idx = var_path.find_first_of(".-[");
618
619 // Break out early from the switch since we were able to find the child member
620 break;
621 }
622 }
623 result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n",
624 valobj_sp->GetName().AsCString(),
Jim Ingham537926c2010-09-02 00:18:39 +0000625 var_path.c_str());
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000626 var_path.clear();
627 valobj_sp.reset();
628 break;
629
630 break;
631
632 default:
633 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
634 var_path.c_str());
635 var_path.clear();
636 valobj_sp.reset();
637 separator_idx = std::string::npos;
638 break;
639 }
640
641 if (child_valobj_sp)
642 valobj_sp = child_valobj_sp;
643
644 if (var_path.empty())
645 break;
646
Jim Ingham537926c2010-09-02 00:18:39 +0000647 }
648
Greg Claytonaed58812010-09-13 02:37:44 +0000649 if (valobj_sp)
650 {
Greg Claytonaed58812010-09-13 02:37:44 +0000651 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
652 {
653 var_sp->GetDeclaration ().DumpStopContext (&s, false);
654 s.PutCString (": ");
655 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000656
Greg Claytonaed58812010-09-13 02:37:44 +0000657 DumpValueObject (result,
658 exe_ctx.frame,
659 valobj_sp.get(),
660 name_cstr,
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000661 ptr_depth,
Greg Claytonaed58812010-09-13 02:37:44 +0000662 0,
663 m_options.max_depth,
Greg Claytona357ecf2010-09-14 03:16:58 +0000664 m_options.use_objc,
665 false);
Greg Claytonaed58812010-09-13 02:37:44 +0000666
667 s.EOL();
668 }
669 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000670 else
671 {
672 result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr);
673 var_path.clear();
674 }
Jim Ingham537926c2010-09-02 00:18:39 +0000675 }
676 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000677 else
678 {
679 const uint32_t num_variables = variable_list->GetSize();
680
681 if (num_variables > 0)
682 {
683 for (uint32_t i=0; i<num_variables; i++)
684 {
685 VariableSP var_sp (variable_list->GetVariableAtIndex(i));
686 bool dump_variable = true;
687
688 switch (var_sp->GetScope())
689 {
690 case eValueTypeVariableGlobal:
691 dump_variable = m_options.show_globals;
692 if (dump_variable && m_options.show_scope)
693 s.PutCString("GLOBAL: ");
694 break;
695
696 case eValueTypeVariableStatic:
697 dump_variable = m_options.show_globals;
698 if (dump_variable && m_options.show_scope)
699 s.PutCString("STATIC: ");
700 break;
701
702 case eValueTypeVariableArgument:
703 dump_variable = m_options.show_args;
704 if (dump_variable && m_options.show_scope)
705 s.PutCString(" ARG: ");
706 break;
707
708 case eValueTypeVariableLocal:
709 dump_variable = m_options.show_locals;
710 if (dump_variable && m_options.show_scope)
711 s.PutCString(" LOCAL: ");
712 break;
713
714 default:
715 break;
716 }
717
718 if (dump_variable)
719 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000720
721 // Use the variable object code to make sure we are
722 // using the same APIs as the the public API will be
723 // using...
724 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
725 if (valobj_sp)
726 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000727 // When dumping all variables, don't print any variables
728 // that are not in scope to avoid extra unneeded output
729 if (valobj_sp->IsInScope (exe_ctx.frame))
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000730 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000731 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
732 {
733 var_sp->GetDeclaration ().DumpStopContext (&s, false);
734 s.PutCString (": ");
735 }
736 DumpValueObject (result,
737 exe_ctx.frame,
738 valobj_sp.get(),
739 name_cstr,
740 m_options.ptr_depth,
741 0,
742 m_options.max_depth,
743 m_options.use_objc,
744 true);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000745
Greg Claytona357ecf2010-09-14 03:16:58 +0000746 s.EOL();
747 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000748 }
749 }
750 }
751 }
752 }
753 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000754 }
Jim Ingham537926c2010-09-02 00:18:39 +0000755 }
756 return result.Succeeded();
757 }
758protected:
759
760 CommandOptions m_options;
761};
762
763lldb::OptionDefinition
764CommandObjectFrameVariable::CommandOptions::g_option_table[] =
765{
Greg Claytonaed58812010-09-13 02:37:44 +0000766{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, NULL, "Enable verbose debug information."},
Jim Ingham537926c2010-09-02 00:18:39 +0000767{ 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 +0000768{ LLDB_OPT_SET_1, false, "show-globals",'g', no_argument, NULL, 0, NULL, "Show the current frame source file global and static variables."},
769{ 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 +0000770{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, NULL, "Show variable location information."},
Greg Claytonaed58812010-09-13 02:37:44 +0000771{ 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 +0000772{ 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."},
773{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, NULL, "Omit function arguments."},
774{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, NULL, "Omit local variables."},
775{ LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, NULL, "Omit variable type names."},
776{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, NULL, "Omit summary information."},
777{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, NULL, "Show variable scope (argument, local, global, static)."},
778{ 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."},
779{ 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)."},
780{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."},
781{ 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL }
782};
Chris Lattner24943d22010-06-08 16:52:24 +0000783#pragma mark CommandObjectMultiwordFrame
784
785//-------------------------------------------------------------------------
786// CommandObjectMultiwordFrame
787//-------------------------------------------------------------------------
788
Greg Clayton63094e02010-06-23 01:19:29 +0000789CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000790 CommandObjectMultiword (interpreter,
791 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000792 "A set of commands for operating on the current thread's frames.",
793 "frame <subcommand> [<subcommand-options>]")
794{
Greg Clayton238c0a12010-09-18 01:14:36 +0000795 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
796 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
797 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000798}
799
800CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
801{
802}
803