blob: 0ff7e673cf960ef8ebce2ef68094dc0367ad85a6 [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));
Caroline Tice5bc8c972010-09-20 20:44:43 +0000132 if (m_interpreter.GetDebugger().GetUseExternalEditor() && 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",
Greg Claytonfe424a92010-09-18 03:37:20 +0000293 "Show frame variables. All argument and local variables "
294 "that are in scope will be shown when no arguments are given. "
295 "If any arguments are specified, they can be names of "
296 "argument, local, file static and file global variables."
297 "Children of aggregate variables can be specified such as "
298 "'var->child.x'.",
Greg Clayton238c0a12010-09-18 01:14:36 +0000299 "frame variable [<cmd-options>] [<var-name1> [<var-name2>...]]")
Jim Ingham537926c2010-09-02 00:18:39 +0000300 {
301 }
302
303 virtual
304 ~CommandObjectFrameVariable ()
305 {
306 }
307
308 virtual
309 Options *
310 GetOptions ()
311 {
312 return &m_options;
313 }
314
315 void
Jim Ingham537926c2010-09-02 00:18:39 +0000316 DumpValueObject (CommandReturnObject &result,
317 ExecutionContextScope *exe_scope,
318 ValueObject *valobj,
319 const char *root_valobj_name,
320 uint32_t ptr_depth,
321 uint32_t curr_depth,
322 uint32_t max_depth,
Greg Claytona357ecf2010-09-14 03:16:58 +0000323 bool use_objc,
324 bool scope_already_checked)
Jim Ingham537926c2010-09-02 00:18:39 +0000325 {
326 if (valobj)
327 {
328 Stream &s = result.GetOutputStream();
329
330 //const char *loc_cstr = valobj->GetLocationAsCString();
331 if (m_options.show_location)
332 {
Greg Clayton1e30afd2010-09-18 04:00:06 +0000333 s.Printf("%s: ", valobj->GetLocationAsCString(exe_scope));
Jim Ingham537926c2010-09-02 00:18:39 +0000334 }
335 if (m_options.debug)
336 s.Printf ("%p ValueObject{%u} ", valobj, valobj->GetID());
337
338 s.Indent();
339
340 if (m_options.show_types)
341 s.Printf("(%s) ", valobj->GetTypeName().AsCString());
342
343 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
344 s.Printf ("%s = ", name_cstr);
345
Greg Claytona357ecf2010-09-14 03:16:58 +0000346 if (!scope_already_checked && !valobj->IsInScope(exe_scope->CalculateStackFrame()))
347 {
348 s.PutCString("error: out of scope");
349 return;
350 }
351
Jim Ingham537926c2010-09-02 00:18:39 +0000352 const char *val_cstr = valobj->GetValueAsCString(exe_scope);
353 const char *err_cstr = valobj->GetError().AsCString();
354
355 if (err_cstr)
356 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000357 s.Printf ("error: %s", err_cstr);
Jim Ingham537926c2010-09-02 00:18:39 +0000358 }
359 else
360 {
361 const char *sum_cstr = valobj->GetSummaryAsCString(exe_scope);
362
Greg Clayton462d4142010-09-29 01:12:09 +0000363 const bool is_aggregate = ClangASTContext::IsAggregateType (valobj->GetClangType());
Jim Ingham537926c2010-09-02 00:18:39 +0000364
365 if (val_cstr)
366 s.PutCString(val_cstr);
367
368 if (sum_cstr)
369 s.Printf(" %s", sum_cstr);
370
371 if (use_objc)
372 {
Jim Ingham4ae51962010-09-10 23:12:17 +0000373 const char *object_desc = valobj->GetObjectDescription(exe_scope);
374 if (object_desc)
375 s.Printf("\n%s\n", object_desc);
376 else
377 s.Printf ("No description available.\n");
Jim Ingham537926c2010-09-02 00:18:39 +0000378 return;
379 }
380
381
382 if (curr_depth < max_depth)
383 {
384 if (is_aggregate)
385 s.PutChar('{');
386
Greg Clayton462d4142010-09-29 01:12:09 +0000387 bool is_ptr_or_ref = ClangASTContext::IsPointerOrReferenceType (valobj->GetClangType());
Jim Ingham537926c2010-09-02 00:18:39 +0000388
389 if (is_ptr_or_ref && ptr_depth == 0)
390 return;
391
392 const uint32_t num_children = valobj->GetNumChildren();
393 if (num_children)
394 {
395 s.IndentMore();
396 for (uint32_t idx=0; idx<num_children; ++idx)
397 {
398 ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true));
399 if (child_sp.get())
400 {
401 s.EOL();
402 DumpValueObject (result,
403 exe_scope,
404 child_sp.get(),
405 NULL,
406 is_ptr_or_ref ? ptr_depth - 1 : ptr_depth,
407 curr_depth + 1,
408 max_depth,
Greg Claytona357ecf2010-09-14 03:16:58 +0000409 false,
410 true);
Jim Ingham537926c2010-09-02 00:18:39 +0000411 if (idx + 1 < num_children)
412 s.PutChar(',');
413 }
414 }
415 s.IndentLess();
416 }
417 if (is_aggregate)
418 {
419 s.EOL();
420 s.Indent("}");
421 }
422 }
423 else
424 {
425 if (is_aggregate)
426 {
427 s.PutCString("{...}");
428 }
429 }
430
431 }
432 }
433 }
434
435 virtual bool
436 Execute
437 (
Jim Ingham537926c2010-09-02 00:18:39 +0000438 Args& command,
439 CommandReturnObject &result
440 )
441 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000442 ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000443 if (exe_ctx.frame == NULL)
444 {
Greg Claytonaa448052010-09-18 04:06:15 +0000445 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000446 result.SetStatus (eReturnStatusFailed);
447 return false;
448 }
449 else
450 {
Greg Claytonaed58812010-09-13 02:37:44 +0000451 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000452
Greg Claytonaed58812010-09-13 02:37:44 +0000453 bool get_file_globals = true;
454 VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals);
455
Jim Ingham537926c2010-09-02 00:18:39 +0000456 VariableSP var_sp;
457 ValueObjectSP valobj_sp;
458 //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList();
459 const char *name_cstr = NULL;
460 size_t idx;
461 if (!m_options.globals.empty())
462 {
463 uint32_t fail_count = 0;
464 if (exe_ctx.target)
465 {
466 const size_t num_globals = m_options.globals.size();
467 for (idx = 0; idx < num_globals; ++idx)
468 {
469 VariableList global_var_list;
470 const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list);
471
472 if (num_matching_globals == 0)
473 {
474 ++fail_count;
475 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString());
476 }
477 else
478 {
479 for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
480 {
481 var_sp = global_var_list.GetVariableAtIndex(global_idx);
482 if (var_sp)
483 {
Greg Clayton17dae082010-09-02 02:59:18 +0000484 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000485 if (!valobj_sp)
Greg Clayton17dae082010-09-02 02:59:18 +0000486 valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp);
Jim Ingham537926c2010-09-02 00:18:39 +0000487
488 if (valobj_sp)
489 {
Greg Claytonaed58812010-09-13 02:37:44 +0000490 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
491 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000492 var_sp->GetDeclaration ().DumpStopContext (&s, false);
493 s.PutCString (": ");
Greg Claytonaed58812010-09-13 02:37:44 +0000494 }
495
Greg Claytona357ecf2010-09-14 03:16:58 +0000496 DumpValueObject (result,
497 exe_ctx.frame,
498 valobj_sp.get(),
499 name_cstr,
500 m_options.ptr_depth,
501 0,
502 m_options.max_depth,
503 m_options.use_objc,
504 false);
505
Greg Claytonaed58812010-09-13 02:37:44 +0000506 s.EOL();
Jim Ingham537926c2010-09-02 00:18:39 +0000507 }
508 }
509 }
510 }
511 }
512 }
513 if (fail_count)
Jim Ingham537926c2010-09-02 00:18:39 +0000514 result.SetStatus (eReturnStatusFailed);
Jim Ingham537926c2010-09-02 00:18:39 +0000515 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000516 else if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000517 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000518 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000519 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000520 // If we have any args to the variable command, we will make
521 // variable objects from them...
522 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000523 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000524 uint32_t ptr_depth = m_options.ptr_depth;
525 // If first character is a '*', then show pointer contents
526 if (name_cstr[0] == '*')
Jim Ingham537926c2010-09-02 00:18:39 +0000527 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000528 ++ptr_depth;
529 name_cstr++; // Skip the '*'
530 }
531
532 std::string var_path (name_cstr);
533 size_t separator_idx = var_path.find_first_of(".-[");
534
535 ConstString name_const_string;
536 if (separator_idx == std::string::npos)
537 name_const_string.SetCString (var_path.c_str());
538 else
539 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
540
541 var_sp = variable_list->FindVariable(name_const_string);
542 if (var_sp)
543 {
544 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
545
546 var_path.erase (0, name_const_string.GetLength ());
547 // We are dumping at least one child
548 while (separator_idx != std::string::npos)
Jim Ingham537926c2010-09-02 00:18:39 +0000549 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000550 // Calculate the next separator index ahead of time
551 ValueObjectSP child_valobj_sp;
552 const char separator_type = var_path[0];
553 switch (separator_type)
Jim Ingham537926c2010-09-02 00:18:39 +0000554 {
Jim Ingham537926c2010-09-02 00:18:39 +0000555
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000556 case '-':
557 if (var_path.size() >= 2 && var_path[1] != '>')
Jim Ingham537926c2010-09-02 00:18:39 +0000558 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000559 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
560 var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000561 var_path.clear();
562 valobj_sp.reset();
563 break;
564 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000565 var_path.erase (0, 1); // Remove the '-'
566 // Fall through
567 case '.':
Jim Ingham537926c2010-09-02 00:18:39 +0000568 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000569 var_path.erase (0, 1); // Remove the '.' or '>'
570 separator_idx = var_path.find_first_of(".-[");
571 ConstString child_name;
572 if (separator_idx == std::string::npos)
573 child_name.SetCString (var_path.c_str());
Jim Ingham537926c2010-09-02 00:18:39 +0000574 else
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000575 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
Jim Ingham537926c2010-09-02 00:18:39 +0000576
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000577 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Jim Ingham537926c2010-09-02 00:18:39 +0000578 if (!child_valobj_sp)
579 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000580 result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n",
581 valobj_sp->GetName().AsCString(),
582 child_name.GetCString());
Jim Ingham537926c2010-09-02 00:18:39 +0000583 var_path.clear();
584 valobj_sp.reset();
585 break;
586 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000587 // Remove the child name from the path
588 var_path.erase(0, child_name.GetLength());
Jim Ingham537926c2010-09-02 00:18:39 +0000589 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000590 break;
Jim Ingham537926c2010-09-02 00:18:39 +0000591
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000592 case '[':
593 // Array member access, or treating pointer as an array
594 if (var_path.size() > 2) // Need at least two brackets and a number
595 {
596 char *end = NULL;
597 int32_t child_index = ::strtol (&var_path[1], &end, 0);
598 if (end && *end == ']')
599 {
Jim Ingham537926c2010-09-02 00:18:39 +0000600
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000601 if (valobj_sp->IsPointerType ())
602 {
603 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
604 }
605 else
606 {
607 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
608 }
609
610 if (!child_valobj_sp)
611 {
612 result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n",
613 child_index,
614 valobj_sp->GetName().AsCString());
615 var_path.clear();
616 valobj_sp.reset();
617 break;
618 }
619
620 // Erase the array member specification '[%i]' where %i is the array index
621 var_path.erase(0, (end - var_path.c_str()) + 1);
622 separator_idx = var_path.find_first_of(".-[");
623
624 // Break out early from the switch since we were able to find the child member
625 break;
626 }
627 }
628 result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n",
629 valobj_sp->GetName().AsCString(),
Jim Ingham537926c2010-09-02 00:18:39 +0000630 var_path.c_str());
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000631 var_path.clear();
632 valobj_sp.reset();
633 break;
634
635 break;
636
637 default:
638 result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n",
639 var_path.c_str());
640 var_path.clear();
641 valobj_sp.reset();
642 separator_idx = std::string::npos;
643 break;
644 }
645
646 if (child_valobj_sp)
647 valobj_sp = child_valobj_sp;
648
649 if (var_path.empty())
650 break;
651
Jim Ingham537926c2010-09-02 00:18:39 +0000652 }
653
Greg Claytonaed58812010-09-13 02:37:44 +0000654 if (valobj_sp)
655 {
Greg Claytonaed58812010-09-13 02:37:44 +0000656 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
657 {
658 var_sp->GetDeclaration ().DumpStopContext (&s, false);
659 s.PutCString (": ");
660 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000661
Greg Claytonaed58812010-09-13 02:37:44 +0000662 DumpValueObject (result,
663 exe_ctx.frame,
664 valobj_sp.get(),
665 name_cstr,
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000666 ptr_depth,
Greg Claytonaed58812010-09-13 02:37:44 +0000667 0,
668 m_options.max_depth,
Greg Claytona357ecf2010-09-14 03:16:58 +0000669 m_options.use_objc,
670 false);
Greg Claytonaed58812010-09-13 02:37:44 +0000671
672 s.EOL();
673 }
674 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000675 else
676 {
677 result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr);
678 var_path.clear();
679 }
Jim Ingham537926c2010-09-02 00:18:39 +0000680 }
681 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000682 else
683 {
684 const uint32_t num_variables = variable_list->GetSize();
685
686 if (num_variables > 0)
687 {
688 for (uint32_t i=0; i<num_variables; i++)
689 {
690 VariableSP var_sp (variable_list->GetVariableAtIndex(i));
691 bool dump_variable = true;
692
693 switch (var_sp->GetScope())
694 {
695 case eValueTypeVariableGlobal:
696 dump_variable = m_options.show_globals;
697 if (dump_variable && m_options.show_scope)
698 s.PutCString("GLOBAL: ");
699 break;
700
701 case eValueTypeVariableStatic:
702 dump_variable = m_options.show_globals;
703 if (dump_variable && m_options.show_scope)
704 s.PutCString("STATIC: ");
705 break;
706
707 case eValueTypeVariableArgument:
708 dump_variable = m_options.show_args;
709 if (dump_variable && m_options.show_scope)
710 s.PutCString(" ARG: ");
711 break;
712
713 case eValueTypeVariableLocal:
714 dump_variable = m_options.show_locals;
715 if (dump_variable && m_options.show_scope)
716 s.PutCString(" LOCAL: ");
717 break;
718
719 default:
720 break;
721 }
722
723 if (dump_variable)
724 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000725
726 // Use the variable object code to make sure we are
727 // using the same APIs as the the public API will be
728 // using...
729 valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp);
730 if (valobj_sp)
731 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000732 // When dumping all variables, don't print any variables
733 // that are not in scope to avoid extra unneeded output
734 if (valobj_sp->IsInScope (exe_ctx.frame))
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000735 {
Greg Claytona357ecf2010-09-14 03:16:58 +0000736 if (m_options.show_decl && var_sp->GetDeclaration ().GetFile())
737 {
738 var_sp->GetDeclaration ().DumpStopContext (&s, false);
739 s.PutCString (": ");
740 }
741 DumpValueObject (result,
742 exe_ctx.frame,
743 valobj_sp.get(),
744 name_cstr,
745 m_options.ptr_depth,
746 0,
747 m_options.max_depth,
748 m_options.use_objc,
749 true);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000750
Greg Claytona357ecf2010-09-14 03:16:58 +0000751 s.EOL();
752 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000753 }
754 }
755 }
756 }
757 }
758 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000759 }
Jim Ingham537926c2010-09-02 00:18:39 +0000760 }
761 return result.Succeeded();
762 }
763protected:
764
765 CommandOptions m_options;
766};
767
768lldb::OptionDefinition
769CommandObjectFrameVariable::CommandOptions::g_option_table[] =
770{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000771{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, eArgTypeNone, "Enable verbose debug information."},
772{ LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."},
773{ LLDB_OPT_SET_1, false, "show-globals",'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
774{ LLDB_OPT_SET_1, false, "find-global",'G', required_argument, NULL, 0, eArgTypeVarName, "Find a global variable by name (which might not be in the current stack frame source file)."},
775{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, eArgTypeNone, "Show variable location information."},
776{ LLDB_OPT_SET_1, false, "show-declaration", 'c', no_argument, NULL, 0, eArgTypeNone, "Show variable declaration information (source file and line where the variable was declared)."},
777{ LLDB_OPT_SET_1, false, "name", 'n', required_argument, NULL, 0, eArgTypeVarName, "Lookup a variable by name or regex (--regex) for the current execution context."},
778{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
779{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
780{ LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, eArgTypeNone, "Omit variable type names."},
781{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, eArgTypeNone, "Omit summary information."},
782{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
783{ LLDB_OPT_SET_1, false, "objc", 'o', no_argument, NULL, 0, eArgTypeNone, "When looking up a variable by name (--name), print as an Objective-C object."},
784{ LLDB_OPT_SET_1, false, "ptr-depth", 'p', required_argument, NULL, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."},
785{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, eArgTypeCount, "The <name> argument for name lookups are regular expressions."},
786{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Jim Ingham537926c2010-09-02 00:18:39 +0000787};
Chris Lattner24943d22010-06-08 16:52:24 +0000788#pragma mark CommandObjectMultiwordFrame
789
790//-------------------------------------------------------------------------
791// CommandObjectMultiwordFrame
792//-------------------------------------------------------------------------
793
Greg Clayton63094e02010-06-23 01:19:29 +0000794CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000795 CommandObjectMultiword (interpreter,
796 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000797 "A set of commands for operating on the current thread's frames.",
798 "frame <subcommand> [<subcommand-options>]")
799{
Greg Clayton238c0a12010-09-18 01:14:36 +0000800 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
801 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
802 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000803}
804
805CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
806{
807}
808