blob: 24dd4a47ee16cc127973b241460b9f40406898ad [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
Johnny Chenecd4feb2011-10-14 00:42:25 +000017#include "lldb/Breakpoint/Watchpoint.h"
Enrico Granata0be2e9b2011-08-22 22:03:47 +000018#include "lldb/Core/DataVisualization.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/Debugger.h"
Jim Ingham537926c2010-09-02 00:18:39 +000020#include "lldb/Core/Module.h"
21#include "lldb/Core/StreamFile.h"
Johnny Chen10b12b32011-09-16 21:41:42 +000022#include "lldb/Core/StreamString.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/Timer.h"
Jim Ingham537926c2010-09-02 00:18:39 +000024#include "lldb/Core/Value.h"
25#include "lldb/Core/ValueObject.h"
26#include "lldb/Core/ValueObjectVariable.h"
Greg Claytoncd548032011-02-01 01:31:41 +000027#include "lldb/Host/Host.h"
Jim Ingham537926c2010-09-02 00:18:39 +000028#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Interpreter/CommandInterpreter.h"
30#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham537926c2010-09-02 00:18:39 +000031#include "lldb/Interpreter/Options.h"
Greg Claytona42880a2011-10-25 06:44:01 +000032#include "lldb/Interpreter/OptionGroupFormat.h"
Jim Ingham10de7d12011-05-04 03:43:18 +000033#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton368f8222011-07-07 04:38:25 +000034#include "lldb/Interpreter/OptionGroupVariable.h"
Johnny Chen58dba3c2011-09-09 23:25:26 +000035#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Jim Ingham537926c2010-09-02 00:18:39 +000036#include "lldb/Symbol/ClangASTType.h"
37#include "lldb/Symbol/ClangASTContext.h"
38#include "lldb/Symbol/ObjectFile.h"
39#include "lldb/Symbol/SymbolContext.h"
40#include "lldb/Symbol/Type.h"
41#include "lldb/Symbol/Variable.h"
42#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000043#include "lldb/Target/Process.h"
44#include "lldb/Target/StackFrame.h"
45#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000046#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000047
Chris Lattner24943d22010-06-08 16:52:24 +000048using namespace lldb;
49using namespace lldb_private;
50
51#pragma mark CommandObjectFrameInfo
52
53//-------------------------------------------------------------------------
54// CommandObjectFrameInfo
55//-------------------------------------------------------------------------
56
57class CommandObjectFrameInfo : public CommandObject
58{
59public:
60
Greg Clayton238c0a12010-09-18 01:14:36 +000061 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
62 CommandObject (interpreter,
63 "frame info",
64 "List information about the currently selected frame in the current thread.",
65 "frame info",
66 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000067 {
68 }
69
70 ~CommandObjectFrameInfo ()
71 {
72 }
73
74 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000075 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000076 CommandReturnObject &result)
77 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000078 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +000079 StackFrame *frame = exe_ctx.GetFramePtr();
80 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +000081 {
Greg Clayton567e7f32011-09-22 04:58:26 +000082 frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000083 result.SetStatus (eReturnStatusSuccessFinishResult);
84 }
85 else
86 {
87 result.AppendError ("no current frame");
88 result.SetStatus (eReturnStatusFailed);
89 }
90 return result.Succeeded();
91 }
92};
93
94#pragma mark CommandObjectFrameSelect
95
96//-------------------------------------------------------------------------
97// CommandObjectFrameSelect
98//-------------------------------------------------------------------------
99
100class CommandObjectFrameSelect : public CommandObject
101{
102public:
103
Greg Claytonc12b6b42010-10-10 22:28:11 +0000104 class CommandOptions : public Options
105 {
106 public:
107
Greg Claytonf15996e2011-04-07 22:46:35 +0000108 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000109 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000110 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000111 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000112 }
113
114 virtual
115 ~CommandOptions ()
116 {
117 }
118
119 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000120 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000121 {
122 Error error;
123 bool success = false;
124 char short_option = (char) m_getopt_table[option_idx].val;
125 switch (short_option)
126 {
127 case 'r':
128 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
129 if (!success)
Greg Clayton9c236732011-10-26 00:56:27 +0000130 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'", option_arg);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000131 break;
132
133 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000134 error.SetErrorStringWithFormat ("invalid short option character '%c'", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000135 break;
136 }
137
138 return error;
139 }
140
141 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000142 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000143 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000144 relative_frame_offset = INT32_MIN;
145 }
146
Greg Claytonb3448432011-03-24 21:19:54 +0000147 const OptionDefinition*
Greg Claytonc12b6b42010-10-10 22:28:11 +0000148 GetDefinitions ()
149 {
150 return g_option_table;
151 }
152
153 // Options table: Required for subclasses of Options.
154
Greg Claytonb3448432011-03-24 21:19:54 +0000155 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000156 int32_t relative_frame_offset;
157 };
158
Greg Clayton238c0a12010-09-18 01:14:36 +0000159 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
160 CommandObject (interpreter,
161 "frame select",
162 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000163 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000164 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
165 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000166 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000167 CommandArgumentEntry arg;
168 CommandArgumentData index_arg;
169
170 // Define the first (and only) variant of this arg.
171 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000172 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000173
174 // There is only one variant this argument could be; put it into the argument entry.
175 arg.push_back (index_arg);
176
177 // Push the data for the first argument into the m_arguments vector.
178 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000179 }
180
181 ~CommandObjectFrameSelect ()
182 {
183 }
184
Greg Claytonc12b6b42010-10-10 22:28:11 +0000185 virtual
186 Options *
187 GetOptions ()
188 {
189 return &m_options;
190 }
191
192
Chris Lattner24943d22010-06-08 16:52:24 +0000193 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000194 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000195 CommandReturnObject &result)
196 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000197 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000198 Thread *thread = exe_ctx.GetThreadPtr();
199 if (thread)
Chris Lattner24943d22010-06-08 16:52:24 +0000200 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000201 const uint32_t num_frames = thread->GetStackFrameCount();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000202 uint32_t frame_idx = UINT32_MAX;
203 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000204 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000205 // The one and only argument is a signed relative frame index
Greg Clayton567e7f32011-09-22 04:58:26 +0000206 frame_idx = thread->GetSelectedFrameIndex ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000207 if (frame_idx == UINT32_MAX)
208 frame_idx = 0;
209
210 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000211 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000212 if (frame_idx >= -m_options.relative_frame_offset)
213 frame_idx += m_options.relative_frame_offset;
214 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000215 {
216 if (frame_idx == 0)
217 {
218 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
219 result.AppendError("Already at the bottom of the stack");
220 result.SetStatus(eReturnStatusFailed);
221 return false;
222 }
223 else
224 frame_idx = 0;
225 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000226 }
227 else if (m_options.relative_frame_offset > 0)
228 {
229 if (num_frames - frame_idx > m_options.relative_frame_offset)
230 frame_idx += m_options.relative_frame_offset;
231 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000232 {
233 if (frame_idx == num_frames - 1)
234 {
235 //If we are already at the top of the stack, just warn and don't reset the frame.
236 result.AppendError("Already at the top of the stack");
237 result.SetStatus(eReturnStatusFailed);
238 return false;
239 }
240 else
241 frame_idx = num_frames - 1;
242 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000243 }
244 }
245 else
246 {
247 if (command.GetArgumentCount() == 1)
248 {
249 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
250 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
251 }
Jason Molenda7685ccc2011-09-30 23:12:14 +0000252 else if (command.GetArgumentCount() == 0)
Jason Molenda811ded52011-09-29 23:02:41 +0000253 {
254 frame_idx = thread->GetSelectedFrameIndex ();
255 if (frame_idx == UINT32_MAX)
Jason Molenda7685ccc2011-09-30 23:12:14 +0000256 {
Jason Molenda811ded52011-09-29 23:02:41 +0000257 frame_idx = 0;
Jason Molenda7685ccc2011-09-30 23:12:14 +0000258 }
Jason Molenda811ded52011-09-29 23:02:41 +0000259 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000260 else
261 {
262 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000263 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000264 }
265 }
266
267 if (frame_idx < num_frames)
268 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000269 thread->SetSelectedFrameByIndex (frame_idx);
270 exe_ctx.SetFrameSP(thread->GetSelectedFrame ());
271 StackFrame *frame = exe_ctx.GetFramePtr();
272 if (frame)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000273 {
274 bool already_shown = false;
Greg Clayton567e7f32011-09-22 04:58:26 +0000275 SymbolContext frame_sc(frame->GetSymbolContext(eSymbolContextLineEntry));
Greg Claytonc12b6b42010-10-10 22:28:11 +0000276 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000277 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000278 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
279 }
Jim Ingham74989e82010-08-30 19:44:40 +0000280
Greg Claytonabe0fed2011-04-18 08:33:37 +0000281 bool show_frame_info = true;
282 bool show_source = !already_shown;
283 uint32_t source_lines_before = 3;
284 uint32_t source_lines_after = 3;
Greg Clayton567e7f32011-09-22 04:58:26 +0000285 if (frame->GetStatus (result.GetOutputStream(),
286 show_frame_info,
287 show_source,
288 source_lines_before,
289 source_lines_after))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000290 {
291 result.SetStatus (eReturnStatusSuccessFinishResult);
292 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000293 }
294 }
Chris Lattner24943d22010-06-08 16:52:24 +0000295 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000296 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000297 }
298 else
299 {
300 result.AppendError ("no current thread");
301 }
302 result.SetStatus (eReturnStatusFailed);
303 return false;
304 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000305protected:
306
307 CommandOptions m_options;
308};
309
Greg Claytonb3448432011-03-24 21:19:54 +0000310OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000311CommandObjectFrameSelect::CommandOptions::g_option_table[] =
312{
313{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
314{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000315};
316
Jim Ingham537926c2010-09-02 00:18:39 +0000317#pragma mark CommandObjectFrameVariable
318//----------------------------------------------------------------------
319// List images with associated information
320//----------------------------------------------------------------------
321class CommandObjectFrameVariable : public CommandObject
322{
323public:
324
Greg Clayton238c0a12010-09-18 01:14:36 +0000325 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
326 CommandObject (interpreter,
327 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000328 "Show frame variables. All argument and local variables "
329 "that are in scope will be shown when no arguments are given. "
330 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000331 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000332 "Children of aggregate variables can be specified such as "
Johnny Chen58dba3c2011-09-09 23:25:26 +0000333 "'var->child.x'. "
Johnny Chenf86c60f2012-02-08 01:50:38 +0000334 "You can choose to watch a variable with the '-w' option; "
335 "with the additional '-x' option to specify the region size, "
336 "the variable's value will be used as the starting address of "
337 "the region to watch for, instead. "
Johnny Chencb1a0d92012-02-06 22:17:23 +0000338 "Note that hardware resources for watching are often limited. "
339 "See alo 'watchpoint set' where you can use an expression to "
340 "specify the address to watch for.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000341 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000342 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Jim Ingham10de7d12011-05-04 03:43:18 +0000343 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000344 m_option_variable(true), // Include the frame specific options by passing "true"
Greg Claytona42880a2011-10-25 06:44:01 +0000345 m_option_format (eFormatDefault),
Johnny Chen58dba3c2011-09-09 23:25:26 +0000346 m_option_watchpoint(),
Jim Ingham10de7d12011-05-04 03:43:18 +0000347 m_varobj_options()
Jim Ingham537926c2010-09-02 00:18:39 +0000348 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000349 CommandArgumentEntry arg;
350 CommandArgumentData var_name_arg;
351
352 // Define the first (and only) variant of this arg.
353 var_name_arg.arg_type = eArgTypeVarName;
354 var_name_arg.arg_repetition = eArgRepeatStar;
355
356 // There is only one variant this argument could be; put it into the argument entry.
357 arg.push_back (var_name_arg);
358
359 // Push the data for the first argument into the m_arguments vector.
360 m_arguments.push_back (arg);
Jim Ingham10de7d12011-05-04 03:43:18 +0000361
Greg Clayton368f8222011-07-07 04:38:25 +0000362 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton24a6bd92011-10-27 17:55:14 +0000363 m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1);
Johnny Chen58dba3c2011-09-09 23:25:26 +0000364 m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Jim Ingham10de7d12011-05-04 03:43:18 +0000365 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
366 m_option_group.Finalize();
Jim Ingham537926c2010-09-02 00:18:39 +0000367 }
368
369 virtual
370 ~CommandObjectFrameVariable ()
371 {
372 }
373
374 virtual
375 Options *
376 GetOptions ()
377 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000378 return &m_option_group;
Jim Ingham537926c2010-09-02 00:18:39 +0000379 }
380
Jim Ingham537926c2010-09-02 00:18:39 +0000381
382 virtual bool
383 Execute
384 (
Jim Ingham537926c2010-09-02 00:18:39 +0000385 Args& command,
386 CommandReturnObject &result
387 )
388 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000389 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000390 StackFrame *frame = exe_ctx.GetFramePtr();
391 if (frame == NULL)
Jim Ingham537926c2010-09-02 00:18:39 +0000392 {
Greg Claytonaa448052010-09-18 04:06:15 +0000393 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000394 result.SetStatus (eReturnStatusFailed);
395 return false;
396 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000397
398 Stream &s = result.GetOutputStream();
399
400 bool get_file_globals = true;
401
402 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
403 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
404
Greg Clayton567e7f32011-09-22 04:58:26 +0000405 VariableList *variable_list = frame->GetVariableList (get_file_globals);
Johnny Chen649d3f12011-09-12 23:58:53 +0000406
407 VariableSP var_sp;
408 ValueObjectSP valobj_sp;
409
410 const char *name_cstr = NULL;
411 size_t idx;
412
413 SummaryFormatSP summary_format_sp;
414 if (!m_option_variable.summary.empty())
415 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.c_str()), summary_format_sp);
416
417 ValueObject::DumpValueObjectOptions options;
418
419 options.SetPointerDepth(m_varobj_options.ptr_depth)
420 .SetMaximumDepth(m_varobj_options.max_depth)
421 .SetShowTypes(m_varobj_options.show_types)
422 .SetShowLocation(m_varobj_options.show_location)
423 .SetUseObjectiveC(m_varobj_options.use_objc)
424 .SetUseDynamicType(m_varobj_options.use_dynamic)
425 .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth)
426 .SetFlatOutput(m_varobj_options.flat_output)
427 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
428 .SetIgnoreCap(m_varobj_options.ignore_cap);
429
430 if (m_varobj_options.be_raw)
431 options.SetRawDisplay(true);
432
433 if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000434 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000435 // If watching a variable, there are certain restrictions to be followed.
Johnny Chen42404d22012-02-08 22:37:48 +0000436 if (m_option_watchpoint.watch_type_specified)
Jim Ingham537926c2010-09-02 00:18:39 +0000437 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000438 if (command.GetArgumentCount() != 1) {
439 result.GetErrorStream().Printf("error: specify exactly one variable when using the '-w' option\n");
440 result.SetStatus(eReturnStatusFailed);
441 return false;
442 } else if (m_option_variable.use_regex) {
443 result.GetErrorStream().Printf("error: specify your variable name exactly (no regex) when using the '-w' option\n");
444 result.SetStatus(eReturnStatusFailed);
445 return false;
Johnny Chen3066b252011-09-12 19:12:06 +0000446 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000447
Johnny Chen649d3f12011-09-12 23:58:53 +0000448 // Things have checked out ok...
Johnny Chen1b452522011-09-30 01:08:48 +0000449 // m_option_watchpoint.watch_type specifies the type of watching.
Johnny Chen649d3f12011-09-12 23:58:53 +0000450 }
Greg Claytona42880a2011-10-25 06:44:01 +0000451
452 const Format format = m_option_format.GetFormat();
453
Johnny Chen649d3f12011-09-12 23:58:53 +0000454 if (command.GetArgumentCount() > 0)
455 {
456 VariableList regex_var_list;
457
458 // If we have any args to the variable command, we will make
459 // variable objects from them...
460 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
461 {
462 if (m_option_variable.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000463 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000464 const uint32_t regex_start_index = regex_var_list.GetSize();
465 RegularExpression regex (name_cstr);
466 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000467 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000468 size_t num_matches = 0;
469 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
470 regex_var_list,
471 num_matches);
472 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000473 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000474 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
475 regex_idx < end_index;
476 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000477 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000478 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
479 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000480 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000481 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
Johnny Chen649d3f12011-09-12 23:58:53 +0000482 if (valobj_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000483 {
Greg Claytonccf44502012-01-26 21:08:30 +0000484// if (format != eFormatDefault)
485// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000486
487 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
488 {
489 bool show_fullpaths = false;
490 bool show_module = true;
491 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
492 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000493 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000494 if (summary_format_sp)
495 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
496 ValueObject::DumpValueObject (result.GetOutputStream(),
497 valobj_sp.get(),
Greg Claytonccf44502012-01-26 21:08:30 +0000498 options,
499 format);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000500 }
501 }
502 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000503 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000504 else if (num_matches == 0)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000505 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000506 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000507 }
508 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000509 else
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000510 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000511 char regex_error[1024];
512 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
513 result.GetErrorStream().Printf ("error: %s\n", regex_error);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000514 else
Johnny Chen649d3f12011-09-12 23:58:53 +0000515 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
516 }
517 }
518 else // No regex, either exact variable names or variable expressions.
519 {
520 Error error;
521 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
522 lldb::VariableSP var_sp;
Greg Clayton567e7f32011-09-22 04:58:26 +0000523 valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr,
524 m_varobj_options.use_dynamic,
525 expr_path_options,
526 var_sp,
527 error);
Johnny Chen649d3f12011-09-12 23:58:53 +0000528 if (valobj_sp)
529 {
Greg Claytonccf44502012-01-26 21:08:30 +0000530// if (format != eFormatDefault)
531// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000532 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000533 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000534 var_sp->GetDeclaration ().DumpStopContext (&s, false);
535 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000536 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000537 if (summary_format_sp)
538 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
539
540 Stream &output_stream = result.GetOutputStream();
541 ValueObject::DumpValueObject (output_stream,
542 valobj_sp.get(),
543 valobj_sp->GetParent() ? name_cstr : NULL,
Greg Claytonccf44502012-01-26 21:08:30 +0000544 options,
545 format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000546 // Process watchpoint if necessary.
Johnny Chen42404d22012-02-08 22:37:48 +0000547 if (m_option_watchpoint.watch_type_specified)
Johnny Chen649d3f12011-09-12 23:58:53 +0000548 {
Johnny Chen61286a52011-09-13 18:30:59 +0000549 AddressType addr_type;
Johnny Chen1b452522011-09-30 01:08:48 +0000550 lldb::addr_t addr = 0;
Johnny Chen649d3f12011-09-12 23:58:53 +0000551 size_t size = 0;
Johnny Chen1b452522011-09-30 01:08:48 +0000552 if (m_option_watchpoint.watch_size == 0) {
553 addr = valobj_sp->GetAddressOf(false, &addr_type);
554 if (addr_type == eAddressTypeLoad) {
555 // We're in business.
556 // Find out the size of this variable.
557 size = valobj_sp->GetByteSize();
558 }
559 } else {
560 // The '-xsize'/'-x' option means to treat the value object as
561 // a pointer and to watch the pointee with the specified size.
562 addr = valobj_sp->GetValueAsUnsigned(0);
563 size = m_option_watchpoint.watch_size;
Johnny Chen61286a52011-09-13 18:30:59 +0000564 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000565 uint32_t watch_type = m_option_watchpoint.watch_type;
Johnny Chenecd4feb2011-10-14 00:42:25 +0000566 Watchpoint *wp = exe_ctx.GetTargetRef().CreateWatchpoint(addr, size, watch_type).get();
567 if (wp)
Johnny Chen649d3f12011-09-12 23:58:53 +0000568 {
Johnny Chen10b12b32011-09-16 21:41:42 +0000569 if (var_sp && var_sp->GetDeclaration().GetFile())
570 {
571 StreamString ss;
Johnny Chen26ec8742011-09-16 21:46:38 +0000572 // True to show fullpath for declaration file.
Johnny Chen10b12b32011-09-16 21:41:42 +0000573 var_sp->GetDeclaration().DumpStopContext(&ss, true);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000574 wp->SetDeclInfo(ss.GetString());
Johnny Chen10b12b32011-09-16 21:41:42 +0000575 }
576 StreamString ss;
Johnny Chen649d3f12011-09-12 23:58:53 +0000577 output_stream.Printf("Watchpoint created: ");
Johnny Chenecd4feb2011-10-14 00:42:25 +0000578 wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull);
Johnny Chen649d3f12011-09-12 23:58:53 +0000579 output_stream.EOL();
580 result.SetStatus(eReturnStatusSuccessFinishResult);
581 }
582 else
583 {
584 result.AppendErrorWithFormat("Watchpoint creation failed.\n");
585 result.SetStatus(eReturnStatusFailed);
586 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000587 return (wp != NULL);
Johnny Chen649d3f12011-09-12 23:58:53 +0000588 }
589 }
590 else
591 {
592 const char *error_cstr = error.AsCString(NULL);
593 if (error_cstr)
594 result.GetErrorStream().Printf("error: %s\n", error_cstr);
595 else
596 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000597 }
Jim Ingham537926c2010-09-02 00:18:39 +0000598 }
599 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000600 }
601 else // No command arg specified. Use variable_list, instead.
602 {
603 const uint32_t num_variables = variable_list->GetSize();
604 if (num_variables > 0)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000605 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000606 for (uint32_t i=0; i<num_variables; i++)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000607 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000608 var_sp = variable_list->GetVariableAtIndex(i);
609 bool dump_variable = true;
610 switch (var_sp->GetScope())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000611 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000612 case eValueTypeVariableGlobal:
Greg Clayton368f8222011-07-07 04:38:25 +0000613 dump_variable = m_option_variable.show_globals;
614 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000615 s.PutCString("GLOBAL: ");
616 break;
617
618 case eValueTypeVariableStatic:
Greg Clayton368f8222011-07-07 04:38:25 +0000619 dump_variable = m_option_variable.show_globals;
620 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000621 s.PutCString("STATIC: ");
622 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000623
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000624 case eValueTypeVariableArgument:
Greg Clayton368f8222011-07-07 04:38:25 +0000625 dump_variable = m_option_variable.show_args;
626 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000627 s.PutCString(" ARG: ");
628 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000629
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000630 case eValueTypeVariableLocal:
Greg Clayton368f8222011-07-07 04:38:25 +0000631 dump_variable = m_option_variable.show_locals;
632 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000633 s.PutCString(" LOCAL: ");
634 break;
635
636 default:
637 break;
Johnny Chen649d3f12011-09-12 23:58:53 +0000638 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000639
Johnny Chen649d3f12011-09-12 23:58:53 +0000640 if (dump_variable)
641 {
642 // Use the variable object code to make sure we are
643 // using the same APIs as the the public API will be
644 // using...
Greg Clayton567e7f32011-09-22 04:58:26 +0000645 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp,
646 m_varobj_options.use_dynamic);
Johnny Chen649d3f12011-09-12 23:58:53 +0000647 if (valobj_sp)
648 {
Greg Claytonccf44502012-01-26 21:08:30 +0000649// if (format != eFormatDefault)
650// valobj_sp->SetFormat (format);
Johnny Chen649d3f12011-09-12 23:58:53 +0000651
652 // When dumping all variables, don't print any variables
653 // that are not in scope to avoid extra unneeded output
654 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000655 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000656 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000657 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000658 var_sp->GetDeclaration ().DumpStopContext (&s, false);
659 s.PutCString (": ");
Greg Claytona357ecf2010-09-14 03:16:58 +0000660 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000661 if (summary_format_sp)
662 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
663 ValueObject::DumpValueObject (result.GetOutputStream(),
664 valobj_sp.get(),
665 name_cstr,
Greg Claytonccf44502012-01-26 21:08:30 +0000666 options,
667 format);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000668 }
669 }
670 }
671 }
672 }
Jim Ingham537926c2010-09-02 00:18:39 +0000673 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000674 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000675 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000676
677 if (m_interpreter.TruncationWarningNecessary())
678 {
679 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
680 m_cmd_name.c_str());
681 m_interpreter.TruncationWarningGiven();
682 }
683
Jim Ingham537926c2010-09-02 00:18:39 +0000684 return result.Succeeded();
685 }
686protected:
687
Jim Ingham10de7d12011-05-04 03:43:18 +0000688 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000689 OptionGroupVariable m_option_variable;
Greg Claytona42880a2011-10-25 06:44:01 +0000690 OptionGroupFormat m_option_format;
Johnny Chen58dba3c2011-09-09 23:25:26 +0000691 OptionGroupWatchpoint m_option_watchpoint;
Jim Ingham10de7d12011-05-04 03:43:18 +0000692 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham537926c2010-09-02 00:18:39 +0000693};
694
Jim Ingham10de7d12011-05-04 03:43:18 +0000695
Chris Lattner24943d22010-06-08 16:52:24 +0000696#pragma mark CommandObjectMultiwordFrame
697
698//-------------------------------------------------------------------------
699// CommandObjectMultiwordFrame
700//-------------------------------------------------------------------------
701
Greg Clayton63094e02010-06-23 01:19:29 +0000702CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000703 CommandObjectMultiword (interpreter,
704 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000705 "A set of commands for operating on the current thread's frames.",
706 "frame <subcommand> [<subcommand-options>]")
707{
Greg Clayton238c0a12010-09-18 01:14:36 +0000708 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
709 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
710 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000711}
712
713CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
714{
715}
716