blob: 4982bfb55a4780f2260ca292dc655f164e51c844 [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
Johnny Chen10b12b32011-09-16 21:41:42 +000014#include <string>
Chris Lattner24943d22010-06-08 16:52:24 +000015// Other libraries and framework includes
16// Project includes
Enrico Granata0be2e9b2011-08-22 22:03:47 +000017#include "lldb/Core/DataVisualization.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Core/Debugger.h"
Jim Ingham537926c2010-09-02 00:18:39 +000019#include "lldb/Core/Module.h"
20#include "lldb/Core/StreamFile.h"
Johnny Chen10b12b32011-09-16 21:41:42 +000021#include "lldb/Core/StreamString.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Timer.h"
Jim Ingham537926c2010-09-02 00:18:39 +000023#include "lldb/Core/Value.h"
24#include "lldb/Core/ValueObject.h"
25#include "lldb/Core/ValueObjectVariable.h"
Greg Claytoncd548032011-02-01 01:31:41 +000026#include "lldb/Host/Host.h"
Jim Ingham537926c2010-09-02 00:18:39 +000027#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028#include "lldb/Interpreter/CommandInterpreter.h"
29#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham537926c2010-09-02 00:18:39 +000030#include "lldb/Interpreter/Options.h"
Jim Ingham10de7d12011-05-04 03:43:18 +000031#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton368f8222011-07-07 04:38:25 +000032#include "lldb/Interpreter/OptionGroupVariable.h"
Johnny Chen58dba3c2011-09-09 23:25:26 +000033#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Jim Ingham537926c2010-09-02 00:18:39 +000034#include "lldb/Symbol/ClangASTType.h"
35#include "lldb/Symbol/ClangASTContext.h"
36#include "lldb/Symbol/ObjectFile.h"
37#include "lldb/Symbol/SymbolContext.h"
38#include "lldb/Symbol/Type.h"
39#include "lldb/Symbol/Variable.h"
40#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000041#include "lldb/Target/Process.h"
42#include "lldb/Target/StackFrame.h"
43#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000044#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000045
Chris Lattner24943d22010-06-08 16:52:24 +000046using namespace lldb;
47using namespace lldb_private;
48
49#pragma mark CommandObjectFrameInfo
50
51//-------------------------------------------------------------------------
52// CommandObjectFrameInfo
53//-------------------------------------------------------------------------
54
55class CommandObjectFrameInfo : public CommandObject
56{
57public:
58
Greg Clayton238c0a12010-09-18 01:14:36 +000059 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
60 CommandObject (interpreter,
61 "frame info",
62 "List information about the currently selected frame in the current thread.",
63 "frame info",
64 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000065 {
66 }
67
68 ~CommandObjectFrameInfo ()
69 {
70 }
71
72 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000073 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000074 CommandReturnObject &result)
75 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000076 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +000077 if (exe_ctx.frame)
78 {
Greg Claytona830adb2010-10-04 01:05:56 +000079 exe_ctx.frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000080 result.SetStatus (eReturnStatusSuccessFinishResult);
81 }
82 else
83 {
84 result.AppendError ("no current frame");
85 result.SetStatus (eReturnStatusFailed);
86 }
87 return result.Succeeded();
88 }
89};
90
91#pragma mark CommandObjectFrameSelect
92
93//-------------------------------------------------------------------------
94// CommandObjectFrameSelect
95//-------------------------------------------------------------------------
96
97class CommandObjectFrameSelect : public CommandObject
98{
99public:
100
Greg Claytonc12b6b42010-10-10 22:28:11 +0000101 class CommandOptions : public Options
102 {
103 public:
104
Greg Claytonf15996e2011-04-07 22:46:35 +0000105 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000106 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000107 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000108 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000109 }
110
111 virtual
112 ~CommandOptions ()
113 {
114 }
115
116 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000117 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000118 {
119 Error error;
120 bool success = false;
121 char short_option = (char) m_getopt_table[option_idx].val;
122 switch (short_option)
123 {
124 case 'r':
125 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
126 if (!success)
127 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg);
128 break;
129
130 default:
Benjamin Kramerfddc25a2010-11-10 20:16:47 +0000131 error.SetErrorStringWithFormat ("Invalid short option character '%c'.\n", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000132 break;
133 }
134
135 return error;
136 }
137
138 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000139 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000140 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000141 relative_frame_offset = INT32_MIN;
142 }
143
Greg Claytonb3448432011-03-24 21:19:54 +0000144 const OptionDefinition*
Greg Claytonc12b6b42010-10-10 22:28:11 +0000145 GetDefinitions ()
146 {
147 return g_option_table;
148 }
149
150 // Options table: Required for subclasses of Options.
151
Greg Claytonb3448432011-03-24 21:19:54 +0000152 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000153 int32_t relative_frame_offset;
154 };
155
Greg Clayton238c0a12010-09-18 01:14:36 +0000156 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
157 CommandObject (interpreter,
158 "frame select",
159 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000160 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000161 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
162 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000163 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000164 CommandArgumentEntry arg;
165 CommandArgumentData index_arg;
166
167 // Define the first (and only) variant of this arg.
168 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000169 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000170
171 // There is only one variant this argument could be; put it into the argument entry.
172 arg.push_back (index_arg);
173
174 // Push the data for the first argument into the m_arguments vector.
175 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000176 }
177
178 ~CommandObjectFrameSelect ()
179 {
180 }
181
Greg Claytonc12b6b42010-10-10 22:28:11 +0000182 virtual
183 Options *
184 GetOptions ()
185 {
186 return &m_options;
187 }
188
189
Chris Lattner24943d22010-06-08 16:52:24 +0000190 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000191 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000192 CommandReturnObject &result)
193 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000194 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000195 if (exe_ctx.thread)
196 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000197 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
198 uint32_t frame_idx = UINT32_MAX;
199 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000200 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000201 // The one and only argument is a signed relative frame index
202 frame_idx = exe_ctx.thread->GetSelectedFrameIndex ();
203 if (frame_idx == UINT32_MAX)
204 frame_idx = 0;
205
206 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000207 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000208 if (frame_idx >= -m_options.relative_frame_offset)
209 frame_idx += m_options.relative_frame_offset;
210 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000211 {
212 if (frame_idx == 0)
213 {
214 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
215 result.AppendError("Already at the bottom of the stack");
216 result.SetStatus(eReturnStatusFailed);
217 return false;
218 }
219 else
220 frame_idx = 0;
221 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000222 }
223 else if (m_options.relative_frame_offset > 0)
224 {
225 if (num_frames - frame_idx > m_options.relative_frame_offset)
226 frame_idx += m_options.relative_frame_offset;
227 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000228 {
229 if (frame_idx == num_frames - 1)
230 {
231 //If we are already at the top of the stack, just warn and don't reset the frame.
232 result.AppendError("Already at the top of the stack");
233 result.SetStatus(eReturnStatusFailed);
234 return false;
235 }
236 else
237 frame_idx = num_frames - 1;
238 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000239 }
240 }
241 else
242 {
243 if (command.GetArgumentCount() == 1)
244 {
245 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
246 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
247 }
248 else
249 {
250 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000251 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000252 }
253 }
254
255 if (frame_idx < num_frames)
256 {
257 exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
258 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000259
Greg Claytonc12b6b42010-10-10 22:28:11 +0000260 if (exe_ctx.frame)
261 {
262 bool already_shown = false;
263 SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
264 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000265 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000266 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
267 }
Jim Ingham74989e82010-08-30 19:44:40 +0000268
Greg Claytonabe0fed2011-04-18 08:33:37 +0000269 bool show_frame_info = true;
270 bool show_source = !already_shown;
271 uint32_t source_lines_before = 3;
272 uint32_t source_lines_after = 3;
273 if (exe_ctx.frame->GetStatus(result.GetOutputStream(),
274 show_frame_info,
275 show_source,
276 source_lines_before,
277 source_lines_after))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000278 {
279 result.SetStatus (eReturnStatusSuccessFinishResult);
280 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000281 }
282 }
Chris Lattner24943d22010-06-08 16:52:24 +0000283 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000284 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000285 }
286 else
287 {
288 result.AppendError ("no current thread");
289 }
290 result.SetStatus (eReturnStatusFailed);
291 return false;
292 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000293protected:
294
295 CommandOptions m_options;
296};
297
Greg Claytonb3448432011-03-24 21:19:54 +0000298OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000299CommandObjectFrameSelect::CommandOptions::g_option_table[] =
300{
301{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
302{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000303};
304
Jim Ingham537926c2010-09-02 00:18:39 +0000305#pragma mark CommandObjectFrameVariable
306//----------------------------------------------------------------------
307// List images with associated information
308//----------------------------------------------------------------------
309class CommandObjectFrameVariable : public CommandObject
310{
311public:
312
Greg Clayton238c0a12010-09-18 01:14:36 +0000313 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
314 CommandObject (interpreter,
315 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000316 "Show frame variables. All argument and local variables "
317 "that are in scope will be shown when no arguments are given. "
318 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000319 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000320 "Children of aggregate variables can be specified such as "
Johnny Chen58dba3c2011-09-09 23:25:26 +0000321 "'var->child.x'. "
322 "NOTE that '-w' option is not working yet!!! "
323 "You can choose to watch a variable with the '-w' option. "
324 "Note that hardware resources for watching are often limited.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000325 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000326 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Jim Ingham10de7d12011-05-04 03:43:18 +0000327 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000328 m_option_variable(true), // Include the frame specific options by passing "true"
Johnny Chen58dba3c2011-09-09 23:25:26 +0000329 m_option_watchpoint(),
Jim Ingham10de7d12011-05-04 03:43:18 +0000330 m_varobj_options()
Jim Ingham537926c2010-09-02 00:18:39 +0000331 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000332 CommandArgumentEntry arg;
333 CommandArgumentData var_name_arg;
334
335 // Define the first (and only) variant of this arg.
336 var_name_arg.arg_type = eArgTypeVarName;
337 var_name_arg.arg_repetition = eArgRepeatStar;
338
339 // There is only one variant this argument could be; put it into the argument entry.
340 arg.push_back (var_name_arg);
341
342 // Push the data for the first argument into the m_arguments vector.
343 m_arguments.push_back (arg);
Jim Ingham10de7d12011-05-04 03:43:18 +0000344
Greg Clayton368f8222011-07-07 04:38:25 +0000345 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Johnny Chen58dba3c2011-09-09 23:25:26 +0000346 m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Jim Ingham10de7d12011-05-04 03:43:18 +0000347 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
348 m_option_group.Finalize();
Jim Ingham537926c2010-09-02 00:18:39 +0000349 }
350
351 virtual
352 ~CommandObjectFrameVariable ()
353 {
354 }
355
356 virtual
357 Options *
358 GetOptions ()
359 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000360 return &m_option_group;
Jim Ingham537926c2010-09-02 00:18:39 +0000361 }
362
Jim Ingham537926c2010-09-02 00:18:39 +0000363
364 virtual bool
365 Execute
366 (
Jim Ingham537926c2010-09-02 00:18:39 +0000367 Args& command,
368 CommandReturnObject &result
369 )
370 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000371 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000372 if (exe_ctx.frame == NULL)
373 {
Greg Claytonaa448052010-09-18 04:06:15 +0000374 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000375 result.SetStatus (eReturnStatusFailed);
376 return false;
377 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000378
379 Stream &s = result.GetOutputStream();
380
381 bool get_file_globals = true;
382
383 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
384 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
385
386 StackFrameSP frame_sp = exe_ctx.frame->GetSP();
387
388 VariableList *variable_list = frame_sp->GetVariableList (get_file_globals);
389
390 VariableSP var_sp;
391 ValueObjectSP valobj_sp;
392
393 const char *name_cstr = NULL;
394 size_t idx;
395
396 SummaryFormatSP summary_format_sp;
397 if (!m_option_variable.summary.empty())
398 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.c_str()), summary_format_sp);
399
400 ValueObject::DumpValueObjectOptions options;
401
402 options.SetPointerDepth(m_varobj_options.ptr_depth)
403 .SetMaximumDepth(m_varobj_options.max_depth)
404 .SetShowTypes(m_varobj_options.show_types)
405 .SetShowLocation(m_varobj_options.show_location)
406 .SetUseObjectiveC(m_varobj_options.use_objc)
407 .SetUseDynamicType(m_varobj_options.use_dynamic)
408 .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth)
409 .SetFlatOutput(m_varobj_options.flat_output)
410 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
411 .SetIgnoreCap(m_varobj_options.ignore_cap);
412
413 if (m_varobj_options.be_raw)
414 options.SetRawDisplay(true);
415
416 if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000417 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000418 // If watching a variable, there are certain restrictions to be followed.
419 if (m_option_watchpoint.watch_variable)
Jim Ingham537926c2010-09-02 00:18:39 +0000420 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000421 if (command.GetArgumentCount() != 1) {
422 result.GetErrorStream().Printf("error: specify exactly one variable when using the '-w' option\n");
423 result.SetStatus(eReturnStatusFailed);
424 return false;
425 } else if (m_option_variable.use_regex) {
426 result.GetErrorStream().Printf("error: specify your variable name exactly (no regex) when using the '-w' option\n");
427 result.SetStatus(eReturnStatusFailed);
428 return false;
Johnny Chen3066b252011-09-12 19:12:06 +0000429 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000430
Johnny Chen649d3f12011-09-12 23:58:53 +0000431 // Things have checked out ok...
432 // m_option_watchpoint.watch_mode specifies the mode for watching.
433 }
434 if (command.GetArgumentCount() > 0)
435 {
436 VariableList regex_var_list;
437
438 // If we have any args to the variable command, we will make
439 // variable objects from them...
440 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
441 {
442 if (m_option_variable.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000443 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000444 const uint32_t regex_start_index = regex_var_list.GetSize();
445 RegularExpression regex (name_cstr);
446 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000447 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000448 size_t num_matches = 0;
449 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
450 regex_var_list,
451 num_matches);
452 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000453 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000454 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
455 regex_idx < end_index;
456 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000457 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000458 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
459 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000460 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000461 valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
462 if (valobj_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000463 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000464 if (m_option_variable.format != eFormatDefault)
465 valobj_sp->SetFormat (m_option_variable.format);
466
467 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
468 {
469 bool show_fullpaths = false;
470 bool show_module = true;
471 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
472 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000473 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000474 if (summary_format_sp)
475 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
476 ValueObject::DumpValueObject (result.GetOutputStream(),
477 valobj_sp.get(),
478 options);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000479 }
480 }
481 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000482 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000483 else if (num_matches == 0)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000484 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000485 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000486 }
487 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000488 else
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000489 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000490 char regex_error[1024];
491 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
492 result.GetErrorStream().Printf ("error: %s\n", regex_error);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000493 else
Johnny Chen649d3f12011-09-12 23:58:53 +0000494 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
495 }
496 }
497 else // No regex, either exact variable names or variable expressions.
498 {
499 Error error;
500 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
501 lldb::VariableSP var_sp;
502 valobj_sp = frame_sp->GetValueForVariableExpressionPath (name_cstr,
503 m_varobj_options.use_dynamic,
504 expr_path_options,
505 var_sp,
506 error);
507 if (valobj_sp)
508 {
509 if (m_option_variable.format != eFormatDefault)
510 valobj_sp->SetFormat (m_option_variable.format);
511 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000512 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000513 var_sp->GetDeclaration ().DumpStopContext (&s, false);
514 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000515 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000516 if (summary_format_sp)
517 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
518
519 Stream &output_stream = result.GetOutputStream();
520 ValueObject::DumpValueObject (output_stream,
521 valobj_sp.get(),
522 valobj_sp->GetParent() ? name_cstr : NULL,
523 options);
524 // Process watchpoint if necessary.
525 if (m_option_watchpoint.watch_variable)
526 {
Johnny Chen61286a52011-09-13 18:30:59 +0000527 AddressType addr_type;
528 lldb::addr_t addr = valobj_sp->GetAddressOf(false, &addr_type);
Johnny Chen649d3f12011-09-12 23:58:53 +0000529 size_t size = 0;
Johnny Chen61286a52011-09-13 18:30:59 +0000530 if (addr_type == eAddressTypeLoad) {
531 // We're in business.
532 // Find out the size of this variable.
533 size = valobj_sp->GetByteSize();
534 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000535 uint32_t watch_type = m_option_watchpoint.watch_type;
536 WatchpointLocation *wp_loc =
537 exe_ctx.target->CreateWatchpointLocation(addr, size, watch_type).get();
538 if (wp_loc)
539 {
Johnny Chen10b12b32011-09-16 21:41:42 +0000540 if (var_sp && var_sp->GetDeclaration().GetFile())
541 {
542 StreamString ss;
Johnny Chen26ec8742011-09-16 21:46:38 +0000543 // True to show fullpath for declaration file.
Johnny Chen10b12b32011-09-16 21:41:42 +0000544 var_sp->GetDeclaration().DumpStopContext(&ss, true);
545 wp_loc->SetDeclInfo(ss.GetString());
546 }
547 StreamString ss;
Johnny Chen649d3f12011-09-12 23:58:53 +0000548 output_stream.Printf("Watchpoint created: ");
Johnny Chen10b12b32011-09-16 21:41:42 +0000549 wp_loc->GetDescription(&output_stream, lldb::eDescriptionLevelFull);
Johnny Chen649d3f12011-09-12 23:58:53 +0000550 output_stream.EOL();
551 result.SetStatus(eReturnStatusSuccessFinishResult);
552 }
553 else
554 {
555 result.AppendErrorWithFormat("Watchpoint creation failed.\n");
556 result.SetStatus(eReturnStatusFailed);
557 }
558 return (wp_loc != NULL);
559 }
560 }
561 else
562 {
563 const char *error_cstr = error.AsCString(NULL);
564 if (error_cstr)
565 result.GetErrorStream().Printf("error: %s\n", error_cstr);
566 else
567 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000568 }
Jim Ingham537926c2010-09-02 00:18:39 +0000569 }
570 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000571 }
572 else // No command arg specified. Use variable_list, instead.
573 {
574 const uint32_t num_variables = variable_list->GetSize();
575 if (num_variables > 0)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000576 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000577 for (uint32_t i=0; i<num_variables; i++)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000578 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000579 var_sp = variable_list->GetVariableAtIndex(i);
580 bool dump_variable = true;
581 switch (var_sp->GetScope())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000582 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000583 case eValueTypeVariableGlobal:
Greg Clayton368f8222011-07-07 04:38:25 +0000584 dump_variable = m_option_variable.show_globals;
585 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000586 s.PutCString("GLOBAL: ");
587 break;
588
589 case eValueTypeVariableStatic:
Greg Clayton368f8222011-07-07 04:38:25 +0000590 dump_variable = m_option_variable.show_globals;
591 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000592 s.PutCString("STATIC: ");
593 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000594
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000595 case eValueTypeVariableArgument:
Greg Clayton368f8222011-07-07 04:38:25 +0000596 dump_variable = m_option_variable.show_args;
597 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000598 s.PutCString(" ARG: ");
599 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000600
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000601 case eValueTypeVariableLocal:
Greg Clayton368f8222011-07-07 04:38:25 +0000602 dump_variable = m_option_variable.show_locals;
603 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000604 s.PutCString(" LOCAL: ");
605 break;
606
607 default:
608 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000609 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000610
Johnny Chen649d3f12011-09-12 23:58:53 +0000611 if (dump_variable)
612 {
613 // Use the variable object code to make sure we are
614 // using the same APIs as the the public API will be
615 // using...
616 valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp,
617 m_varobj_options.use_dynamic);
618 if (valobj_sp)
619 {
620 if (m_option_variable.format != eFormatDefault)
621 valobj_sp->SetFormat (m_option_variable.format);
622
623 // When dumping all variables, don't print any variables
624 // that are not in scope to avoid extra unneeded output
625 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000626 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000627 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000628 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000629 var_sp->GetDeclaration ().DumpStopContext (&s, false);
630 s.PutCString (": ");
Greg Claytona357ecf2010-09-14 03:16:58 +0000631 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000632 if (summary_format_sp)
633 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
634 ValueObject::DumpValueObject (result.GetOutputStream(),
635 valobj_sp.get(),
636 name_cstr,
637 options);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000638 }
639 }
640 }
641 }
642 }
Jim Ingham537926c2010-09-02 00:18:39 +0000643 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000644 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000645 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000646
647 if (m_interpreter.TruncationWarningNecessary())
648 {
649 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
650 m_cmd_name.c_str());
651 m_interpreter.TruncationWarningGiven();
652 }
653
Jim Ingham537926c2010-09-02 00:18:39 +0000654 return result.Succeeded();
655 }
656protected:
657
Jim Ingham10de7d12011-05-04 03:43:18 +0000658 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000659 OptionGroupVariable m_option_variable;
Johnny Chen58dba3c2011-09-09 23:25:26 +0000660 OptionGroupWatchpoint m_option_watchpoint;
Jim Ingham10de7d12011-05-04 03:43:18 +0000661 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham537926c2010-09-02 00:18:39 +0000662};
663
Jim Ingham10de7d12011-05-04 03:43:18 +0000664
Chris Lattner24943d22010-06-08 16:52:24 +0000665#pragma mark CommandObjectMultiwordFrame
666
667//-------------------------------------------------------------------------
668// CommandObjectMultiwordFrame
669//-------------------------------------------------------------------------
670
Greg Clayton63094e02010-06-23 01:19:29 +0000671CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000672 CommandObjectMultiword (interpreter,
673 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000674 "A set of commands for operating on the current thread's frames.",
675 "frame <subcommand> [<subcommand-options>]")
676{
Greg Clayton238c0a12010-09-18 01:14:36 +0000677 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
678 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
679 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000680}
681
682CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
683{
684}
685