blob: 28ac8419d57f5ced4617c851395f1420a43aa484 [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 Chen096c2932011-09-26 22:40:50 +000017#include "lldb/Breakpoint/WatchpointLocation.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"
Jim Ingham10de7d12011-05-04 03:43:18 +000032#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton368f8222011-07-07 04:38:25 +000033#include "lldb/Interpreter/OptionGroupVariable.h"
Johnny Chen58dba3c2011-09-09 23:25:26 +000034#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Jim Ingham537926c2010-09-02 00:18:39 +000035#include "lldb/Symbol/ClangASTType.h"
36#include "lldb/Symbol/ClangASTContext.h"
37#include "lldb/Symbol/ObjectFile.h"
38#include "lldb/Symbol/SymbolContext.h"
39#include "lldb/Symbol/Type.h"
40#include "lldb/Symbol/Variable.h"
41#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000042#include "lldb/Target/Process.h"
43#include "lldb/Target/StackFrame.h"
44#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000045#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000046
Chris Lattner24943d22010-06-08 16:52:24 +000047using namespace lldb;
48using namespace lldb_private;
49
50#pragma mark CommandObjectFrameInfo
51
52//-------------------------------------------------------------------------
53// CommandObjectFrameInfo
54//-------------------------------------------------------------------------
55
56class CommandObjectFrameInfo : public CommandObject
57{
58public:
59
Greg Clayton238c0a12010-09-18 01:14:36 +000060 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
61 CommandObject (interpreter,
62 "frame info",
63 "List information about the currently selected frame in the current thread.",
64 "frame info",
65 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000066 {
67 }
68
69 ~CommandObjectFrameInfo ()
70 {
71 }
72
73 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000074 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000075 CommandReturnObject &result)
76 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000077 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +000078 StackFrame *frame = exe_ctx.GetFramePtr();
79 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +000080 {
Greg Clayton567e7f32011-09-22 04:58:26 +000081 frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000082 result.SetStatus (eReturnStatusSuccessFinishResult);
83 }
84 else
85 {
86 result.AppendError ("no current frame");
87 result.SetStatus (eReturnStatusFailed);
88 }
89 return result.Succeeded();
90 }
91};
92
93#pragma mark CommandObjectFrameSelect
94
95//-------------------------------------------------------------------------
96// CommandObjectFrameSelect
97//-------------------------------------------------------------------------
98
99class CommandObjectFrameSelect : public CommandObject
100{
101public:
102
Greg Claytonc12b6b42010-10-10 22:28:11 +0000103 class CommandOptions : public Options
104 {
105 public:
106
Greg Claytonf15996e2011-04-07 22:46:35 +0000107 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000108 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000109 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000110 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000111 }
112
113 virtual
114 ~CommandOptions ()
115 {
116 }
117
118 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000119 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000120 {
121 Error error;
122 bool success = false;
123 char short_option = (char) m_getopt_table[option_idx].val;
124 switch (short_option)
125 {
126 case 'r':
127 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
128 if (!success)
129 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg);
130 break;
131
132 default:
Benjamin Kramerfddc25a2010-11-10 20:16:47 +0000133 error.SetErrorStringWithFormat ("Invalid short option character '%c'.\n", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000134 break;
135 }
136
137 return error;
138 }
139
140 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000141 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000142 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000143 relative_frame_offset = INT32_MIN;
144 }
145
Greg Claytonb3448432011-03-24 21:19:54 +0000146 const OptionDefinition*
Greg Claytonc12b6b42010-10-10 22:28:11 +0000147 GetDefinitions ()
148 {
149 return g_option_table;
150 }
151
152 // Options table: Required for subclasses of Options.
153
Greg Claytonb3448432011-03-24 21:19:54 +0000154 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000155 int32_t relative_frame_offset;
156 };
157
Greg Clayton238c0a12010-09-18 01:14:36 +0000158 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
159 CommandObject (interpreter,
160 "frame select",
161 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000162 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000163 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
164 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000165 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000166 CommandArgumentEntry arg;
167 CommandArgumentData index_arg;
168
169 // Define the first (and only) variant of this arg.
170 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000171 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000172
173 // There is only one variant this argument could be; put it into the argument entry.
174 arg.push_back (index_arg);
175
176 // Push the data for the first argument into the m_arguments vector.
177 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000178 }
179
180 ~CommandObjectFrameSelect ()
181 {
182 }
183
Greg Claytonc12b6b42010-10-10 22:28:11 +0000184 virtual
185 Options *
186 GetOptions ()
187 {
188 return &m_options;
189 }
190
191
Chris Lattner24943d22010-06-08 16:52:24 +0000192 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000193 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000194 CommandReturnObject &result)
195 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000196 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000197 Thread *thread = exe_ctx.GetThreadPtr();
198 if (thread)
Chris Lattner24943d22010-06-08 16:52:24 +0000199 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000200 const uint32_t num_frames = thread->GetStackFrameCount();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000201 uint32_t frame_idx = UINT32_MAX;
202 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000203 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000204 // The one and only argument is a signed relative frame index
Greg Clayton567e7f32011-09-22 04:58:26 +0000205 frame_idx = thread->GetSelectedFrameIndex ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000206 if (frame_idx == UINT32_MAX)
207 frame_idx = 0;
208
209 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000210 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000211 if (frame_idx >= -m_options.relative_frame_offset)
212 frame_idx += m_options.relative_frame_offset;
213 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000214 {
215 if (frame_idx == 0)
216 {
217 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
218 result.AppendError("Already at the bottom of the stack");
219 result.SetStatus(eReturnStatusFailed);
220 return false;
221 }
222 else
223 frame_idx = 0;
224 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000225 }
226 else if (m_options.relative_frame_offset > 0)
227 {
228 if (num_frames - frame_idx > m_options.relative_frame_offset)
229 frame_idx += m_options.relative_frame_offset;
230 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000231 {
232 if (frame_idx == num_frames - 1)
233 {
234 //If we are already at the top of the stack, just warn and don't reset the frame.
235 result.AppendError("Already at the top of the stack");
236 result.SetStatus(eReturnStatusFailed);
237 return false;
238 }
239 else
240 frame_idx = num_frames - 1;
241 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000242 }
243 }
244 else
245 {
246 if (command.GetArgumentCount() == 1)
247 {
248 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
249 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
250 }
251 else
252 {
253 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000254 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000255 }
256 }
257
258 if (frame_idx < num_frames)
259 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000260 thread->SetSelectedFrameByIndex (frame_idx);
261 exe_ctx.SetFrameSP(thread->GetSelectedFrame ());
262 StackFrame *frame = exe_ctx.GetFramePtr();
263 if (frame)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000264 {
265 bool already_shown = false;
Greg Clayton567e7f32011-09-22 04:58:26 +0000266 SymbolContext frame_sc(frame->GetSymbolContext(eSymbolContextLineEntry));
Greg Claytonc12b6b42010-10-10 22:28:11 +0000267 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000268 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000269 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
270 }
Jim Ingham74989e82010-08-30 19:44:40 +0000271
Greg Claytonabe0fed2011-04-18 08:33:37 +0000272 bool show_frame_info = true;
273 bool show_source = !already_shown;
274 uint32_t source_lines_before = 3;
275 uint32_t source_lines_after = 3;
Greg Clayton567e7f32011-09-22 04:58:26 +0000276 if (frame->GetStatus (result.GetOutputStream(),
277 show_frame_info,
278 show_source,
279 source_lines_before,
280 source_lines_after))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000281 {
282 result.SetStatus (eReturnStatusSuccessFinishResult);
283 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000284 }
285 }
Chris Lattner24943d22010-06-08 16:52:24 +0000286 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000287 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000288 }
289 else
290 {
291 result.AppendError ("no current thread");
292 }
293 result.SetStatus (eReturnStatusFailed);
294 return false;
295 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000296protected:
297
298 CommandOptions m_options;
299};
300
Greg Claytonb3448432011-03-24 21:19:54 +0000301OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000302CommandObjectFrameSelect::CommandOptions::g_option_table[] =
303{
304{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
305{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000306};
307
Jim Ingham537926c2010-09-02 00:18:39 +0000308#pragma mark CommandObjectFrameVariable
309//----------------------------------------------------------------------
310// List images with associated information
311//----------------------------------------------------------------------
312class CommandObjectFrameVariable : public CommandObject
313{
314public:
315
Greg Clayton238c0a12010-09-18 01:14:36 +0000316 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
317 CommandObject (interpreter,
318 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000319 "Show frame variables. All argument and local variables "
320 "that are in scope will be shown when no arguments are given. "
321 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000322 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000323 "Children of aggregate variables can be specified such as "
Johnny Chen58dba3c2011-09-09 23:25:26 +0000324 "'var->child.x'. "
Johnny Chen58dba3c2011-09-09 23:25:26 +0000325 "You can choose to watch a variable with the '-w' option. "
326 "Note that hardware resources for watching are often limited.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000327 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000328 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Jim Ingham10de7d12011-05-04 03:43:18 +0000329 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000330 m_option_variable(true), // Include the frame specific options by passing "true"
Johnny Chen58dba3c2011-09-09 23:25:26 +0000331 m_option_watchpoint(),
Jim Ingham10de7d12011-05-04 03:43:18 +0000332 m_varobj_options()
Jim Ingham537926c2010-09-02 00:18:39 +0000333 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000334 CommandArgumentEntry arg;
335 CommandArgumentData var_name_arg;
336
337 // Define the first (and only) variant of this arg.
338 var_name_arg.arg_type = eArgTypeVarName;
339 var_name_arg.arg_repetition = eArgRepeatStar;
340
341 // There is only one variant this argument could be; put it into the argument entry.
342 arg.push_back (var_name_arg);
343
344 // Push the data for the first argument into the m_arguments vector.
345 m_arguments.push_back (arg);
Jim Ingham10de7d12011-05-04 03:43:18 +0000346
Greg Clayton368f8222011-07-07 04:38:25 +0000347 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Johnny Chen58dba3c2011-09-09 23:25:26 +0000348 m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Jim Ingham10de7d12011-05-04 03:43:18 +0000349 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
350 m_option_group.Finalize();
Jim Ingham537926c2010-09-02 00:18:39 +0000351 }
352
353 virtual
354 ~CommandObjectFrameVariable ()
355 {
356 }
357
358 virtual
359 Options *
360 GetOptions ()
361 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000362 return &m_option_group;
Jim Ingham537926c2010-09-02 00:18:39 +0000363 }
364
Jim Ingham537926c2010-09-02 00:18:39 +0000365
366 virtual bool
367 Execute
368 (
Jim Ingham537926c2010-09-02 00:18:39 +0000369 Args& command,
370 CommandReturnObject &result
371 )
372 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000373 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000374 StackFrame *frame = exe_ctx.GetFramePtr();
375 if (frame == NULL)
Jim Ingham537926c2010-09-02 00:18:39 +0000376 {
Greg Claytonaa448052010-09-18 04:06:15 +0000377 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000378 result.SetStatus (eReturnStatusFailed);
379 return false;
380 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000381
382 Stream &s = result.GetOutputStream();
383
384 bool get_file_globals = true;
385
386 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
387 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
388
Greg Clayton567e7f32011-09-22 04:58:26 +0000389 VariableList *variable_list = frame->GetVariableList (get_file_globals);
Johnny Chen649d3f12011-09-12 23:58:53 +0000390
391 VariableSP var_sp;
392 ValueObjectSP valobj_sp;
393
394 const char *name_cstr = NULL;
395 size_t idx;
396
397 SummaryFormatSP summary_format_sp;
398 if (!m_option_variable.summary.empty())
399 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.c_str()), summary_format_sp);
400
401 ValueObject::DumpValueObjectOptions options;
402
403 options.SetPointerDepth(m_varobj_options.ptr_depth)
404 .SetMaximumDepth(m_varobj_options.max_depth)
405 .SetShowTypes(m_varobj_options.show_types)
406 .SetShowLocation(m_varobj_options.show_location)
407 .SetUseObjectiveC(m_varobj_options.use_objc)
408 .SetUseDynamicType(m_varobj_options.use_dynamic)
409 .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth)
410 .SetFlatOutput(m_varobj_options.flat_output)
411 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
412 .SetIgnoreCap(m_varobj_options.ignore_cap);
413
414 if (m_varobj_options.be_raw)
415 options.SetRawDisplay(true);
416
417 if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000418 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000419 // If watching a variable, there are certain restrictions to be followed.
420 if (m_option_watchpoint.watch_variable)
Jim Ingham537926c2010-09-02 00:18:39 +0000421 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000422 if (command.GetArgumentCount() != 1) {
423 result.GetErrorStream().Printf("error: specify exactly one variable when using the '-w' option\n");
424 result.SetStatus(eReturnStatusFailed);
425 return false;
426 } else if (m_option_variable.use_regex) {
427 result.GetErrorStream().Printf("error: specify your variable name exactly (no regex) when using the '-w' option\n");
428 result.SetStatus(eReturnStatusFailed);
429 return false;
Johnny Chen3066b252011-09-12 19:12:06 +0000430 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000431
Johnny Chen649d3f12011-09-12 23:58:53 +0000432 // Things have checked out ok...
433 // m_option_watchpoint.watch_mode specifies the mode for watching.
434 }
435 if (command.GetArgumentCount() > 0)
436 {
437 VariableList regex_var_list;
438
439 // If we have any args to the variable command, we will make
440 // variable objects from them...
441 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
442 {
443 if (m_option_variable.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000444 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000445 const uint32_t regex_start_index = regex_var_list.GetSize();
446 RegularExpression regex (name_cstr);
447 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000448 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000449 size_t num_matches = 0;
450 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
451 regex_var_list,
452 num_matches);
453 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000454 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000455 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
456 regex_idx < end_index;
457 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000458 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000459 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
460 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000461 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000462 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
Johnny Chen649d3f12011-09-12 23:58:53 +0000463 if (valobj_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000464 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000465 if (m_option_variable.format != eFormatDefault)
466 valobj_sp->SetFormat (m_option_variable.format);
467
468 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
469 {
470 bool show_fullpaths = false;
471 bool show_module = true;
472 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
473 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000474 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000475 if (summary_format_sp)
476 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
477 ValueObject::DumpValueObject (result.GetOutputStream(),
478 valobj_sp.get(),
479 options);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000480 }
481 }
482 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000483 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000484 else if (num_matches == 0)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000485 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000486 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000487 }
488 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000489 else
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000490 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000491 char regex_error[1024];
492 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
493 result.GetErrorStream().Printf ("error: %s\n", regex_error);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000494 else
Johnny Chen649d3f12011-09-12 23:58:53 +0000495 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
496 }
497 }
498 else // No regex, either exact variable names or variable expressions.
499 {
500 Error error;
501 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
502 lldb::VariableSP var_sp;
Greg Clayton567e7f32011-09-22 04:58:26 +0000503 valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr,
504 m_varobj_options.use_dynamic,
505 expr_path_options,
506 var_sp,
507 error);
Johnny Chen649d3f12011-09-12 23:58:53 +0000508 if (valobj_sp)
509 {
510 if (m_option_variable.format != eFormatDefault)
511 valobj_sp->SetFormat (m_option_variable.format);
512 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000513 {
Johnny Chen649d3f12011-09-12 23:58:53 +0000514 var_sp->GetDeclaration ().DumpStopContext (&s, false);
515 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000516 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000517 if (summary_format_sp)
518 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
519
520 Stream &output_stream = result.GetOutputStream();
521 ValueObject::DumpValueObject (output_stream,
522 valobj_sp.get(),
523 valobj_sp->GetParent() ? name_cstr : NULL,
524 options);
525 // Process watchpoint if necessary.
526 if (m_option_watchpoint.watch_variable)
527 {
Johnny Chen61286a52011-09-13 18:30:59 +0000528 AddressType addr_type;
529 lldb::addr_t addr = valobj_sp->GetAddressOf(false, &addr_type);
Johnny Chen649d3f12011-09-12 23:58:53 +0000530 size_t size = 0;
Johnny Chen61286a52011-09-13 18:30:59 +0000531 if (addr_type == eAddressTypeLoad) {
532 // We're in business.
533 // Find out the size of this variable.
534 size = valobj_sp->GetByteSize();
535 }
Johnny Chen649d3f12011-09-12 23:58:53 +0000536 uint32_t watch_type = m_option_watchpoint.watch_type;
Greg Clayton567e7f32011-09-22 04:58:26 +0000537 WatchpointLocation *wp_loc = exe_ctx.GetTargetRef().CreateWatchpointLocation(addr, size, watch_type).get();
Johnny Chen649d3f12011-09-12 23:58:53 +0000538 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...
Greg Clayton567e7f32011-09-22 04:58:26 +0000616 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp,
617 m_varobj_options.use_dynamic);
Johnny Chen649d3f12011-09-12 23:58:53 +0000618 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