blob: d214439f8ce66c1f80263a5475e5567bf9908dfb [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
Enrico Granata0be2e9b2011-08-22 22:03:47 +000016#include "lldb/Core/DataVisualization.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Core/Debugger.h"
Jim Ingham537926c2010-09-02 00:18:39 +000018#include "lldb/Core/Module.h"
19#include "lldb/Core/StreamFile.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Core/Timer.h"
Jim Ingham537926c2010-09-02 00:18:39 +000021#include "lldb/Core/Value.h"
22#include "lldb/Core/ValueObject.h"
23#include "lldb/Core/ValueObjectVariable.h"
Greg Claytoncd548032011-02-01 01:31:41 +000024#include "lldb/Host/Host.h"
Jim Ingham537926c2010-09-02 00:18:39 +000025#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Interpreter/CommandInterpreter.h"
27#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham537926c2010-09-02 00:18:39 +000028#include "lldb/Interpreter/Options.h"
Jim Ingham10de7d12011-05-04 03:43:18 +000029#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton368f8222011-07-07 04:38:25 +000030#include "lldb/Interpreter/OptionGroupVariable.h"
Johnny Chen58dba3c2011-09-09 23:25:26 +000031#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Jim Ingham537926c2010-09-02 00:18:39 +000032#include "lldb/Symbol/ClangASTType.h"
33#include "lldb/Symbol/ClangASTContext.h"
34#include "lldb/Symbol/ObjectFile.h"
35#include "lldb/Symbol/SymbolContext.h"
36#include "lldb/Symbol/Type.h"
37#include "lldb/Symbol/Variable.h"
38#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000039#include "lldb/Target/Process.h"
40#include "lldb/Target/StackFrame.h"
41#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000042#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000043
Chris Lattner24943d22010-06-08 16:52:24 +000044using namespace lldb;
45using namespace lldb_private;
46
47#pragma mark CommandObjectFrameInfo
48
49//-------------------------------------------------------------------------
50// CommandObjectFrameInfo
51//-------------------------------------------------------------------------
52
53class CommandObjectFrameInfo : public CommandObject
54{
55public:
56
Greg Clayton238c0a12010-09-18 01:14:36 +000057 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
58 CommandObject (interpreter,
59 "frame info",
60 "List information about the currently selected frame in the current thread.",
61 "frame info",
62 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000063 {
64 }
65
66 ~CommandObjectFrameInfo ()
67 {
68 }
69
70 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000071 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000072 CommandReturnObject &result)
73 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000074 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +000075 if (exe_ctx.frame)
76 {
Greg Claytona830adb2010-10-04 01:05:56 +000077 exe_ctx.frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000078 result.SetStatus (eReturnStatusSuccessFinishResult);
79 }
80 else
81 {
82 result.AppendError ("no current frame");
83 result.SetStatus (eReturnStatusFailed);
84 }
85 return result.Succeeded();
86 }
87};
88
89#pragma mark CommandObjectFrameSelect
90
91//-------------------------------------------------------------------------
92// CommandObjectFrameSelect
93//-------------------------------------------------------------------------
94
95class CommandObjectFrameSelect : public CommandObject
96{
97public:
98
Greg Claytonc12b6b42010-10-10 22:28:11 +000099 class CommandOptions : public Options
100 {
101 public:
102
Greg Claytonf15996e2011-04-07 22:46:35 +0000103 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000104 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000105 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000106 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000107 }
108
109 virtual
110 ~CommandOptions ()
111 {
112 }
113
114 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000115 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000116 {
117 Error error;
118 bool success = false;
119 char short_option = (char) m_getopt_table[option_idx].val;
120 switch (short_option)
121 {
122 case 'r':
123 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
124 if (!success)
125 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg);
126 break;
127
128 default:
Benjamin Kramerfddc25a2010-11-10 20:16:47 +0000129 error.SetErrorStringWithFormat ("Invalid short option character '%c'.\n", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000130 break;
131 }
132
133 return error;
134 }
135
136 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000137 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000138 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000139 relative_frame_offset = INT32_MIN;
140 }
141
Greg Claytonb3448432011-03-24 21:19:54 +0000142 const OptionDefinition*
Greg Claytonc12b6b42010-10-10 22:28:11 +0000143 GetDefinitions ()
144 {
145 return g_option_table;
146 }
147
148 // Options table: Required for subclasses of Options.
149
Greg Claytonb3448432011-03-24 21:19:54 +0000150 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000151 int32_t relative_frame_offset;
152 };
153
Greg Clayton238c0a12010-09-18 01:14:36 +0000154 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
155 CommandObject (interpreter,
156 "frame select",
157 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000158 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000159 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
160 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000161 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000162 CommandArgumentEntry arg;
163 CommandArgumentData index_arg;
164
165 // Define the first (and only) variant of this arg.
166 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000167 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000168
169 // There is only one variant this argument could be; put it into the argument entry.
170 arg.push_back (index_arg);
171
172 // Push the data for the first argument into the m_arguments vector.
173 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000174 }
175
176 ~CommandObjectFrameSelect ()
177 {
178 }
179
Greg Claytonc12b6b42010-10-10 22:28:11 +0000180 virtual
181 Options *
182 GetOptions ()
183 {
184 return &m_options;
185 }
186
187
Chris Lattner24943d22010-06-08 16:52:24 +0000188 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000189 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000190 CommandReturnObject &result)
191 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000192 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000193 if (exe_ctx.thread)
194 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000195 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
196 uint32_t frame_idx = UINT32_MAX;
197 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000198 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000199 // The one and only argument is a signed relative frame index
200 frame_idx = exe_ctx.thread->GetSelectedFrameIndex ();
201 if (frame_idx == UINT32_MAX)
202 frame_idx = 0;
203
204 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000205 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000206 if (frame_idx >= -m_options.relative_frame_offset)
207 frame_idx += m_options.relative_frame_offset;
208 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000209 {
210 if (frame_idx == 0)
211 {
212 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
213 result.AppendError("Already at the bottom of the stack");
214 result.SetStatus(eReturnStatusFailed);
215 return false;
216 }
217 else
218 frame_idx = 0;
219 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000220 }
221 else if (m_options.relative_frame_offset > 0)
222 {
223 if (num_frames - frame_idx > m_options.relative_frame_offset)
224 frame_idx += m_options.relative_frame_offset;
225 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000226 {
227 if (frame_idx == num_frames - 1)
228 {
229 //If we are already at the top of the stack, just warn and don't reset the frame.
230 result.AppendError("Already at the top of the stack");
231 result.SetStatus(eReturnStatusFailed);
232 return false;
233 }
234 else
235 frame_idx = num_frames - 1;
236 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000237 }
238 }
239 else
240 {
241 if (command.GetArgumentCount() == 1)
242 {
243 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
244 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
245 }
246 else
247 {
248 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000249 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000250 }
251 }
252
253 if (frame_idx < num_frames)
254 {
255 exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
256 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000257
Greg Claytonc12b6b42010-10-10 22:28:11 +0000258 if (exe_ctx.frame)
259 {
260 bool already_shown = false;
261 SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
262 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000263 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000264 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
265 }
Jim Ingham74989e82010-08-30 19:44:40 +0000266
Greg Claytonabe0fed2011-04-18 08:33:37 +0000267 bool show_frame_info = true;
268 bool show_source = !already_shown;
269 uint32_t source_lines_before = 3;
270 uint32_t source_lines_after = 3;
271 if (exe_ctx.frame->GetStatus(result.GetOutputStream(),
272 show_frame_info,
273 show_source,
274 source_lines_before,
275 source_lines_after))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000276 {
277 result.SetStatus (eReturnStatusSuccessFinishResult);
278 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000279 }
280 }
Chris Lattner24943d22010-06-08 16:52:24 +0000281 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000282 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000283 }
284 else
285 {
286 result.AppendError ("no current thread");
287 }
288 result.SetStatus (eReturnStatusFailed);
289 return false;
290 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000291protected:
292
293 CommandOptions m_options;
294};
295
Greg Claytonb3448432011-03-24 21:19:54 +0000296OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000297CommandObjectFrameSelect::CommandOptions::g_option_table[] =
298{
299{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
300{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000301};
302
Jim Ingham537926c2010-09-02 00:18:39 +0000303#pragma mark CommandObjectFrameVariable
304//----------------------------------------------------------------------
305// List images with associated information
306//----------------------------------------------------------------------
307class CommandObjectFrameVariable : public CommandObject
308{
309public:
310
Greg Clayton238c0a12010-09-18 01:14:36 +0000311 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
312 CommandObject (interpreter,
313 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000314 "Show frame variables. All argument and local variables "
315 "that are in scope will be shown when no arguments are given. "
316 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000317 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000318 "Children of aggregate variables can be specified such as "
Johnny Chen58dba3c2011-09-09 23:25:26 +0000319 "'var->child.x'. "
320 "NOTE that '-w' option is not working yet!!! "
321 "You can choose to watch a variable with the '-w' option. "
322 "Note that hardware resources for watching are often limited.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000323 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000324 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Jim Ingham10de7d12011-05-04 03:43:18 +0000325 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000326 m_option_variable(true), // Include the frame specific options by passing "true"
Johnny Chen58dba3c2011-09-09 23:25:26 +0000327 m_option_watchpoint(),
Jim Ingham10de7d12011-05-04 03:43:18 +0000328 m_varobj_options()
Jim Ingham537926c2010-09-02 00:18:39 +0000329 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000330 CommandArgumentEntry arg;
331 CommandArgumentData var_name_arg;
332
333 // Define the first (and only) variant of this arg.
334 var_name_arg.arg_type = eArgTypeVarName;
335 var_name_arg.arg_repetition = eArgRepeatStar;
336
337 // There is only one variant this argument could be; put it into the argument entry.
338 arg.push_back (var_name_arg);
339
340 // Push the data for the first argument into the m_arguments vector.
341 m_arguments.push_back (arg);
Jim Ingham10de7d12011-05-04 03:43:18 +0000342
Greg Clayton368f8222011-07-07 04:38:25 +0000343 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Johnny Chen58dba3c2011-09-09 23:25:26 +0000344 m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Jim Ingham10de7d12011-05-04 03:43:18 +0000345 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
346 m_option_group.Finalize();
Jim Ingham537926c2010-09-02 00:18:39 +0000347 }
348
349 virtual
350 ~CommandObjectFrameVariable ()
351 {
352 }
353
354 virtual
355 Options *
356 GetOptions ()
357 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000358 return &m_option_group;
Jim Ingham537926c2010-09-02 00:18:39 +0000359 }
360
Jim Ingham537926c2010-09-02 00:18:39 +0000361
362 virtual bool
363 Execute
364 (
Jim Ingham537926c2010-09-02 00:18:39 +0000365 Args& command,
366 CommandReturnObject &result
367 )
368 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000369 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000370 if (exe_ctx.frame == NULL)
371 {
Greg Claytonaa448052010-09-18 04:06:15 +0000372 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000373 result.SetStatus (eReturnStatusFailed);
374 return false;
375 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000376
377 Stream &s = result.GetOutputStream();
378
379 bool get_file_globals = true;
380
381 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
382 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
383
384 StackFrameSP frame_sp = exe_ctx.frame->GetSP();
385
386 VariableList *variable_list = frame_sp->GetVariableList (get_file_globals);
387
388 VariableSP var_sp;
389 ValueObjectSP valobj_sp;
390
391 const char *name_cstr = NULL;
392 size_t idx;
393
394 SummaryFormatSP summary_format_sp;
395 if (!m_option_variable.summary.empty())
396 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.c_str()), summary_format_sp);
397
398 ValueObject::DumpValueObjectOptions options;
399
400 options.SetPointerDepth(m_varobj_options.ptr_depth)
401 .SetMaximumDepth(m_varobj_options.max_depth)
402 .SetShowTypes(m_varobj_options.show_types)
403 .SetShowLocation(m_varobj_options.show_location)
404 .SetUseObjectiveC(m_varobj_options.use_objc)
405 .SetUseDynamicType(m_varobj_options.use_dynamic)
406 .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth)
407 .SetFlatOutput(m_varobj_options.flat_output)
408 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
409 .SetIgnoreCap(m_varobj_options.ignore_cap);
410
411 if (m_varobj_options.be_raw)
412 options.SetRawDisplay(true);
413
414 if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000415 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000416 // If watching a variable, there are certain restrictions to be followed.
417 if (m_option_watchpoint.watch_variable)
Jim Ingham537926c2010-09-02 00:18:39 +0000418 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000419 if (command.GetArgumentCount() != 1) {
420 result.GetErrorStream().Printf("error: specify exactly one variable when using the '-w' option\n");
421 result.SetStatus(eReturnStatusFailed);
422 return false;
423 } else if (m_option_variable.use_regex) {
424 result.GetErrorStream().Printf("error: specify your variable name exactly (no regex) when using the '-w' option\n");
425 result.SetStatus(eReturnStatusFailed);
426 return false;
Johnny Chen3066b252011-09-12 19:12:06 +0000427 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000428
Johnny Chen649d3f12011-09-12 23:58:53 +0000429 // Things have checked out ok...
430 // m_option_watchpoint.watch_mode specifies the mode for watching.
431 }
432 if (command.GetArgumentCount() > 0)
433 {
434 VariableList regex_var_list;
435
436 // If we have any args to the variable command, we will make
437 // variable objects from them...
438 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
439 {
440 if (m_option_variable.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000441 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000442 const uint32_t regex_start_index = regex_var_list.GetSize();
443 RegularExpression regex (name_cstr);
444 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000445 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000446 size_t num_matches = 0;
447 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
448 regex_var_list,
449 num_matches);
450 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000451 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000452 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
453 regex_idx < end_index;
454 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000455 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000456 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
457 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000458 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000459 valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
460 if (valobj_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000461 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000462 if (m_option_variable.format != eFormatDefault)
463 valobj_sp->SetFormat (m_option_variable.format);
464
465 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
466 {
467 bool show_fullpaths = false;
468 bool show_module = true;
469 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
470 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000471 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000472 if (summary_format_sp)
473 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
474 ValueObject::DumpValueObject (result.GetOutputStream(),
475 valobj_sp.get(),
476 options);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000477 }
478 }
479 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000480 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000481 else if (num_matches == 0)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000482 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000483 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000484 }
485 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000486 else
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000487 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000488 char regex_error[1024];
489 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
490 result.GetErrorStream().Printf ("error: %s\n", regex_error);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000491 else
Johnny Chen649d3f12011-09-12 23:58:53 +0000492 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
493 }
494 }
495 else // No regex, either exact variable names or variable expressions.
496 {
497 Error error;
498 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
499 lldb::VariableSP var_sp;
500 valobj_sp = frame_sp->GetValueForVariableExpressionPath (name_cstr,
501 m_varobj_options.use_dynamic,
502 expr_path_options,
503 var_sp,
504 error);
505 if (valobj_sp)
506 {
507 if (m_option_variable.format != eFormatDefault)
508 valobj_sp->SetFormat (m_option_variable.format);
509 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000510 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000511 var_sp->GetDeclaration ().DumpStopContext (&s, false);
512 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000513 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000514 if (summary_format_sp)
515 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
516
517 Stream &output_stream = result.GetOutputStream();
518 ValueObject::DumpValueObject (output_stream,
519 valobj_sp.get(),
520 valobj_sp->GetParent() ? name_cstr : NULL,
521 options);
522 // Process watchpoint if necessary.
523 if (m_option_watchpoint.watch_variable)
524 {
525 lldb::addr_t addr = LLDB_INVALID_ADDRESS;
526 size_t size = 0;
527 uint32_t watch_type = m_option_watchpoint.watch_type;
528 WatchpointLocation *wp_loc =
529 exe_ctx.target->CreateWatchpointLocation(addr, size, watch_type).get();
530 if (wp_loc)
531 {
532 output_stream.Printf("Watchpoint created: ");
533 wp_loc->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
534 output_stream.EOL();
535 result.SetStatus(eReturnStatusSuccessFinishResult);
536 }
537 else
538 {
539 result.AppendErrorWithFormat("Watchpoint creation failed.\n");
540 result.SetStatus(eReturnStatusFailed);
541 }
542 return (wp_loc != NULL);
543 }
544 }
545 else
546 {
547 const char *error_cstr = error.AsCString(NULL);
548 if (error_cstr)
549 result.GetErrorStream().Printf("error: %s\n", error_cstr);
550 else
551 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000552 }
Jim Ingham537926c2010-09-02 00:18:39 +0000553 }
554 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000555 }
556 else // No command arg specified. Use variable_list, instead.
557 {
558 const uint32_t num_variables = variable_list->GetSize();
559 if (num_variables > 0)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000560 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000561 for (uint32_t i=0; i<num_variables; i++)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000562 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000563 var_sp = variable_list->GetVariableAtIndex(i);
564 bool dump_variable = true;
565 switch (var_sp->GetScope())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000566 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000567 case eValueTypeVariableGlobal:
Greg Clayton368f8222011-07-07 04:38:25 +0000568 dump_variable = m_option_variable.show_globals;
569 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000570 s.PutCString("GLOBAL: ");
571 break;
572
573 case eValueTypeVariableStatic:
Greg Clayton368f8222011-07-07 04:38:25 +0000574 dump_variable = m_option_variable.show_globals;
575 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000576 s.PutCString("STATIC: ");
577 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000578
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000579 case eValueTypeVariableArgument:
Greg Clayton368f8222011-07-07 04:38:25 +0000580 dump_variable = m_option_variable.show_args;
581 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000582 s.PutCString(" ARG: ");
583 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000584
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000585 case eValueTypeVariableLocal:
Greg Clayton368f8222011-07-07 04:38:25 +0000586 dump_variable = m_option_variable.show_locals;
587 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000588 s.PutCString(" LOCAL: ");
589 break;
590
591 default:
592 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000593 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000594
Johnny Chen649d3f12011-09-12 23:58:53 +0000595 if (dump_variable)
596 {
597 // Use the variable object code to make sure we are
598 // using the same APIs as the the public API will be
599 // using...
600 valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp,
601 m_varobj_options.use_dynamic);
602 if (valobj_sp)
603 {
604 if (m_option_variable.format != eFormatDefault)
605 valobj_sp->SetFormat (m_option_variable.format);
606
607 // When dumping all variables, don't print any variables
608 // that are not in scope to avoid extra unneeded output
609 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000610 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000611 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000612 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000613 var_sp->GetDeclaration ().DumpStopContext (&s, false);
614 s.PutCString (": ");
Greg Claytona357ecf2010-09-14 03:16:58 +0000615 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000616 if (summary_format_sp)
617 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
618 ValueObject::DumpValueObject (result.GetOutputStream(),
619 valobj_sp.get(),
620 name_cstr,
621 options);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000622 }
623 }
624 }
625 }
626 }
Jim Ingham537926c2010-09-02 00:18:39 +0000627 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000628 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000629 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000630
631 if (m_interpreter.TruncationWarningNecessary())
632 {
633 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
634 m_cmd_name.c_str());
635 m_interpreter.TruncationWarningGiven();
636 }
637
Jim Ingham537926c2010-09-02 00:18:39 +0000638 return result.Succeeded();
639 }
640protected:
641
Jim Ingham10de7d12011-05-04 03:43:18 +0000642 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000643 OptionGroupVariable m_option_variable;
Johnny Chen58dba3c2011-09-09 23:25:26 +0000644 OptionGroupWatchpoint m_option_watchpoint;
Jim Ingham10de7d12011-05-04 03:43:18 +0000645 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham537926c2010-09-02 00:18:39 +0000646};
647
Jim Ingham10de7d12011-05-04 03:43:18 +0000648
Chris Lattner24943d22010-06-08 16:52:24 +0000649#pragma mark CommandObjectMultiwordFrame
650
651//-------------------------------------------------------------------------
652// CommandObjectMultiwordFrame
653//-------------------------------------------------------------------------
654
Greg Clayton63094e02010-06-23 01:19:29 +0000655CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000656 CommandObjectMultiword (interpreter,
657 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000658 "A set of commands for operating on the current thread's frames.",
659 "frame <subcommand> [<subcommand-options>]")
660{
Greg Clayton238c0a12010-09-18 01:14:36 +0000661 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
662 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
663 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000664}
665
666CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
667{
668}
669