blob: ed27b384f898f2201d962e948d14d75005ec11c4 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObjectFrame.cpp ----------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CommandObjectFrame.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Enrico Granata0be2e9b2011-08-22 22:03:47 +000016#include "lldb/Core/DataVisualization.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Core/Debugger.h"
Jim Ingham537926c2010-09-02 00:18:39 +000018#include "lldb/Core/Module.h"
19#include "lldb/Core/StreamFile.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Core/Timer.h"
Jim Ingham537926c2010-09-02 00:18:39 +000021#include "lldb/Core/Value.h"
22#include "lldb/Core/ValueObject.h"
23#include "lldb/Core/ValueObjectVariable.h"
Greg Claytoncd548032011-02-01 01:31:41 +000024#include "lldb/Host/Host.h"
Jim Ingham537926c2010-09-02 00:18:39 +000025#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Interpreter/CommandInterpreter.h"
27#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham537926c2010-09-02 00:18:39 +000028#include "lldb/Interpreter/Options.h"
Jim Ingham10de7d12011-05-04 03:43:18 +000029#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton368f8222011-07-07 04:38:25 +000030#include "lldb/Interpreter/OptionGroupVariable.h"
Jim Ingham537926c2010-09-02 00:18:39 +000031#include "lldb/Symbol/ClangASTType.h"
32#include "lldb/Symbol/ClangASTContext.h"
33#include "lldb/Symbol/ObjectFile.h"
34#include "lldb/Symbol/SymbolContext.h"
35#include "lldb/Symbol/Type.h"
36#include "lldb/Symbol/Variable.h"
37#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038#include "lldb/Target/Process.h"
39#include "lldb/Target/StackFrame.h"
40#include "lldb/Target/Thread.h"
Jim Ingham537926c2010-09-02 00:18:39 +000041#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000042
Chris Lattner24943d22010-06-08 16:52:24 +000043using namespace lldb;
44using namespace lldb_private;
45
46#pragma mark CommandObjectFrameInfo
47
48//-------------------------------------------------------------------------
49// CommandObjectFrameInfo
50//-------------------------------------------------------------------------
51
52class CommandObjectFrameInfo : public CommandObject
53{
54public:
55
Greg Clayton238c0a12010-09-18 01:14:36 +000056 CommandObjectFrameInfo (CommandInterpreter &interpreter) :
57 CommandObject (interpreter,
58 "frame info",
59 "List information about the currently selected frame in the current thread.",
60 "frame info",
61 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +000062 {
63 }
64
65 ~CommandObjectFrameInfo ()
66 {
67 }
68
69 bool
Greg Clayton238c0a12010-09-18 01:14:36 +000070 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000071 CommandReturnObject &result)
72 {
Greg Claytonb72d0f02011-04-12 05:54:46 +000073 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +000074 if (exe_ctx.frame)
75 {
Greg Claytona830adb2010-10-04 01:05:56 +000076 exe_ctx.frame->DumpUsingSettingsFormat (&result.GetOutputStream());
Chris Lattner24943d22010-06-08 16:52:24 +000077 result.SetStatus (eReturnStatusSuccessFinishResult);
78 }
79 else
80 {
81 result.AppendError ("no current frame");
82 result.SetStatus (eReturnStatusFailed);
83 }
84 return result.Succeeded();
85 }
86};
87
88#pragma mark CommandObjectFrameSelect
89
90//-------------------------------------------------------------------------
91// CommandObjectFrameSelect
92//-------------------------------------------------------------------------
93
94class CommandObjectFrameSelect : public CommandObject
95{
96public:
97
Greg Claytonc12b6b42010-10-10 22:28:11 +000098 class CommandOptions : public Options
99 {
100 public:
101
Greg Claytonf15996e2011-04-07 22:46:35 +0000102 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000103 Options(interpreter)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000104 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000105 OptionParsingStarting ();
Greg Claytonc12b6b42010-10-10 22:28:11 +0000106 }
107
108 virtual
109 ~CommandOptions ()
110 {
111 }
112
113 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000114 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonc12b6b42010-10-10 22:28:11 +0000115 {
116 Error error;
117 bool success = false;
118 char short_option = (char) m_getopt_table[option_idx].val;
119 switch (short_option)
120 {
121 case 'r':
122 relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
123 if (!success)
124 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg);
125 break;
126
127 default:
Benjamin Kramerfddc25a2010-11-10 20:16:47 +0000128 error.SetErrorStringWithFormat ("Invalid short option character '%c'.\n", short_option);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000129 break;
130 }
131
132 return error;
133 }
134
135 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000136 OptionParsingStarting ()
Greg Claytonc12b6b42010-10-10 22:28:11 +0000137 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000138 relative_frame_offset = INT32_MIN;
139 }
140
Greg Claytonb3448432011-03-24 21:19:54 +0000141 const OptionDefinition*
Greg Claytonc12b6b42010-10-10 22:28:11 +0000142 GetDefinitions ()
143 {
144 return g_option_table;
145 }
146
147 // Options table: Required for subclasses of Options.
148
Greg Claytonb3448432011-03-24 21:19:54 +0000149 static OptionDefinition g_option_table[];
Greg Claytonc12b6b42010-10-10 22:28:11 +0000150 int32_t relative_frame_offset;
151 };
152
Greg Clayton238c0a12010-09-18 01:14:36 +0000153 CommandObjectFrameSelect (CommandInterpreter &interpreter) :
154 CommandObject (interpreter,
155 "frame select",
156 "Select a frame by index from within the current thread and make it the current frame.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000157 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000158 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
159 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000160 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000161 CommandArgumentEntry arg;
162 CommandArgumentData index_arg;
163
164 // Define the first (and only) variant of this arg.
165 index_arg.arg_type = eArgTypeFrameIndex;
Greg Claytonc12b6b42010-10-10 22:28:11 +0000166 index_arg.arg_repetition = eArgRepeatOptional;
Caroline Tice43b014a2010-10-04 22:28:36 +0000167
168 // There is only one variant this argument could be; put it into the argument entry.
169 arg.push_back (index_arg);
170
171 // Push the data for the first argument into the m_arguments vector.
172 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000173 }
174
175 ~CommandObjectFrameSelect ()
176 {
177 }
178
Greg Claytonc12b6b42010-10-10 22:28:11 +0000179 virtual
180 Options *
181 GetOptions ()
182 {
183 return &m_options;
184 }
185
186
Chris Lattner24943d22010-06-08 16:52:24 +0000187 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000188 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000189 CommandReturnObject &result)
190 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000191 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +0000192 if (exe_ctx.thread)
193 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000194 const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
195 uint32_t frame_idx = UINT32_MAX;
196 if (m_options.relative_frame_offset != INT32_MIN)
Chris Lattner24943d22010-06-08 16:52:24 +0000197 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000198 // The one and only argument is a signed relative frame index
199 frame_idx = exe_ctx.thread->GetSelectedFrameIndex ();
200 if (frame_idx == UINT32_MAX)
201 frame_idx = 0;
202
203 if (m_options.relative_frame_offset < 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000204 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000205 if (frame_idx >= -m_options.relative_frame_offset)
206 frame_idx += m_options.relative_frame_offset;
207 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000208 {
209 if (frame_idx == 0)
210 {
211 //If you are already at the bottom of the stack, then just warn and don't reset the frame.
212 result.AppendError("Already at the bottom of the stack");
213 result.SetStatus(eReturnStatusFailed);
214 return false;
215 }
216 else
217 frame_idx = 0;
218 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000219 }
220 else if (m_options.relative_frame_offset > 0)
221 {
222 if (num_frames - frame_idx > m_options.relative_frame_offset)
223 frame_idx += m_options.relative_frame_offset;
224 else
Jim Inghamd9fa9d72011-09-08 01:15:09 +0000225 {
226 if (frame_idx == num_frames - 1)
227 {
228 //If we are already at the top of the stack, just warn and don't reset the frame.
229 result.AppendError("Already at the top of the stack");
230 result.SetStatus(eReturnStatusFailed);
231 return false;
232 }
233 else
234 frame_idx = num_frames - 1;
235 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000236 }
237 }
238 else
239 {
240 if (command.GetArgumentCount() == 1)
241 {
242 const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
243 frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
244 }
245 else
246 {
247 result.AppendError ("invalid arguments.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000248 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Greg Claytonc12b6b42010-10-10 22:28:11 +0000249 }
250 }
251
252 if (frame_idx < num_frames)
253 {
254 exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
255 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000256
Greg Claytonc12b6b42010-10-10 22:28:11 +0000257 if (exe_ctx.frame)
258 {
259 bool already_shown = false;
260 SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
261 if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000262 {
Greg Claytonc12b6b42010-10-10 22:28:11 +0000263 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
264 }
Jim Ingham74989e82010-08-30 19:44:40 +0000265
Greg Claytonabe0fed2011-04-18 08:33:37 +0000266 bool show_frame_info = true;
267 bool show_source = !already_shown;
268 uint32_t source_lines_before = 3;
269 uint32_t source_lines_after = 3;
270 if (exe_ctx.frame->GetStatus(result.GetOutputStream(),
271 show_frame_info,
272 show_source,
273 source_lines_before,
274 source_lines_after))
Greg Claytonc12b6b42010-10-10 22:28:11 +0000275 {
276 result.SetStatus (eReturnStatusSuccessFinishResult);
277 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000278 }
279 }
Chris Lattner24943d22010-06-08 16:52:24 +0000280 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000281 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000282 }
283 else
284 {
285 result.AppendError ("no current thread");
286 }
287 result.SetStatus (eReturnStatusFailed);
288 return false;
289 }
Greg Claytonc12b6b42010-10-10 22:28:11 +0000290protected:
291
292 CommandOptions m_options;
293};
294
Greg Claytonb3448432011-03-24 21:19:54 +0000295OptionDefinition
Greg Claytonc12b6b42010-10-10 22:28:11 +0000296CommandObjectFrameSelect::CommandOptions::g_option_table[] =
297{
298{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
299{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000300};
301
Jim Ingham537926c2010-09-02 00:18:39 +0000302#pragma mark CommandObjectFrameVariable
303//----------------------------------------------------------------------
304// List images with associated information
305//----------------------------------------------------------------------
306class CommandObjectFrameVariable : public CommandObject
307{
308public:
309
Greg Clayton238c0a12010-09-18 01:14:36 +0000310 CommandObjectFrameVariable (CommandInterpreter &interpreter) :
311 CommandObject (interpreter,
312 "frame variable",
Greg Claytonfe424a92010-09-18 03:37:20 +0000313 "Show frame variables. All argument and local variables "
314 "that are in scope will be shown when no arguments are given. "
315 "If any arguments are specified, they can be names of "
Johnny Chen17a661c2010-10-25 23:57:26 +0000316 "argument, local, file static and file global variables. "
Greg Claytonfe424a92010-09-18 03:37:20 +0000317 "Children of aggregate variables can be specified such as "
318 "'var->child.x'.",
Jim Inghama7a9c892010-12-23 02:17:54 +0000319 NULL,
Greg Claytonf15996e2011-04-07 22:46:35 +0000320 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Jim Ingham10de7d12011-05-04 03:43:18 +0000321 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000322 m_option_variable(true), // Include the frame specific options by passing "true"
Jim Ingham10de7d12011-05-04 03:43:18 +0000323 m_varobj_options()
Jim Ingham537926c2010-09-02 00:18:39 +0000324 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000325 CommandArgumentEntry arg;
326 CommandArgumentData var_name_arg;
327
328 // Define the first (and only) variant of this arg.
329 var_name_arg.arg_type = eArgTypeVarName;
330 var_name_arg.arg_repetition = eArgRepeatStar;
331
332 // There is only one variant this argument could be; put it into the argument entry.
333 arg.push_back (var_name_arg);
334
335 // Push the data for the first argument into the m_arguments vector.
336 m_arguments.push_back (arg);
Jim Ingham10de7d12011-05-04 03:43:18 +0000337
Greg Clayton368f8222011-07-07 04:38:25 +0000338 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Jim Ingham10de7d12011-05-04 03:43:18 +0000339 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
340 m_option_group.Finalize();
Jim Ingham537926c2010-09-02 00:18:39 +0000341 }
342
343 virtual
344 ~CommandObjectFrameVariable ()
345 {
346 }
347
348 virtual
349 Options *
350 GetOptions ()
351 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000352 return &m_option_group;
Jim Ingham537926c2010-09-02 00:18:39 +0000353 }
354
Jim Ingham537926c2010-09-02 00:18:39 +0000355
356 virtual bool
357 Execute
358 (
Jim Ingham537926c2010-09-02 00:18:39 +0000359 Args& command,
360 CommandReturnObject &result
361 )
362 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000363 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Jim Ingham537926c2010-09-02 00:18:39 +0000364 if (exe_ctx.frame == NULL)
365 {
Greg Claytonaa448052010-09-18 04:06:15 +0000366 result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
Jim Ingham537926c2010-09-02 00:18:39 +0000367 result.SetStatus (eReturnStatusFailed);
368 return false;
369 }
370 else
371 {
Greg Claytonaed58812010-09-13 02:37:44 +0000372 Stream &s = result.GetOutputStream();
Jim Ingham537926c2010-09-02 00:18:39 +0000373
Greg Claytonaed58812010-09-13 02:37:44 +0000374 bool get_file_globals = true;
Jim Ingham994aba02011-08-27 01:22:52 +0000375
376 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
377 // for the thread. So hold onto a shared pointer to the frame so it stays alive.
378
379 StackFrameSP frame_sp = exe_ctx.frame->GetSP();
380
381 VariableList *variable_list = frame_sp->GetVariableList (get_file_globals);
Greg Claytonaed58812010-09-13 02:37:44 +0000382
Jim Ingham537926c2010-09-02 00:18:39 +0000383 VariableSP var_sp;
384 ValueObjectSP valobj_sp;
Jim Inghame41494a2011-04-16 00:01:13 +0000385
Jim Ingham537926c2010-09-02 00:18:39 +0000386 const char *name_cstr = NULL;
387 size_t idx;
Enrico Granata1a102082011-07-12 00:18:11 +0000388
389 SummaryFormatSP summary_format_sp;
390 if (!m_option_variable.summary.empty())
Enrico Granataf501c592011-08-17 22:13:59 +0000391 DataVisualization::NamedSummaryFormats::Get(ConstString(m_option_variable.summary.c_str()), summary_format_sp);
Enrico Granata19030d82011-08-15 18:01:31 +0000392
393 ValueObject::DumpValueObjectOptions options;
394
395 options.SetPointerDepth(m_varobj_options.ptr_depth)
396 .SetMaximumDepth(m_varobj_options.max_depth)
397 .SetShowTypes(m_varobj_options.show_types)
398 .SetShowLocation(m_varobj_options.show_location)
399 .SetUseObjectiveC(m_varobj_options.use_objc)
400 .SetUseDynamicType(m_varobj_options.use_dynamic)
401 .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth)
402 .SetFlatOutput(m_varobj_options.flat_output)
403 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
404 .SetIgnoreCap(m_varobj_options.ignore_cap);
Jim Ingham537926c2010-09-02 00:18:39 +0000405
Enrico Granata19030d82011-08-15 18:01:31 +0000406 if (m_varobj_options.be_raw)
407 options.SetRawDisplay(true);
408
Greg Clayton368f8222011-07-07 04:38:25 +0000409 if (variable_list)
Jim Ingham537926c2010-09-02 00:18:39 +0000410 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000411 if (command.GetArgumentCount() > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000412 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000413 VariableList regex_var_list;
414
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000415 // If we have any args to the variable command, we will make
416 // variable objects from them...
417 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000418 {
Greg Clayton368f8222011-07-07 04:38:25 +0000419 if (m_option_variable.use_regex)
Jim Ingham537926c2010-09-02 00:18:39 +0000420 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000421 const uint32_t regex_start_index = regex_var_list.GetSize();
422 RegularExpression regex (name_cstr);
423 if (regex.Compile(name_cstr))
Jim Ingham537926c2010-09-02 00:18:39 +0000424 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000425 size_t num_matches = 0;
Jim Inghame41494a2011-04-16 00:01:13 +0000426 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
427 regex_var_list,
428 num_matches);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000429 if (num_new_regex_vars > 0)
Jim Ingham537926c2010-09-02 00:18:39 +0000430 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000431 for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
432 regex_idx < end_index;
433 ++regex_idx)
Jim Ingham537926c2010-09-02 00:18:39 +0000434 {
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000435 var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
436 if (var_sp)
Jim Ingham537926c2010-09-02 00:18:39 +0000437 {
Jim Ingham994aba02011-08-27 01:22:52 +0000438 valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000439 if (valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000440 {
Greg Clayton368f8222011-07-07 04:38:25 +0000441 if (m_option_variable.format != eFormatDefault)
442 valobj_sp->SetFormat (m_option_variable.format);
Greg Claytonb1888f22011-03-19 01:12:21 +0000443
Greg Clayton368f8222011-07-07 04:38:25 +0000444 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000445 {
Greg Claytonfb816422011-07-10 19:21:23 +0000446 bool show_fullpaths = false;
447 bool show_module = true;
448 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
449 s.PutCString (": ");
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000450 }
Enrico Granata1a102082011-07-12 00:18:11 +0000451 if (summary_format_sp)
452 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000453 ValueObject::DumpValueObject (result.GetOutputStream(),
Enrico Granata19030d82011-08-15 18:01:31 +0000454 valobj_sp.get(),
455 options);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000456 }
457 }
458 }
459 }
460 else if (num_matches == 0)
461 {
462 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
463 }
464 }
465 else
466 {
467 char regex_error[1024];
468 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
469 result.GetErrorStream().Printf ("error: %s\n", regex_error);
470 else
471 result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
472 }
473 }
474 else
475 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000476 Error error;
Jim Inghame41494a2011-04-16 00:01:13 +0000477 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
Jim Ingham10de7d12011-05-04 03:43:18 +0000478 lldb::VariableSP var_sp;
Jim Ingham994aba02011-08-27 01:22:52 +0000479 valobj_sp = frame_sp->GetValueForVariableExpressionPath (name_cstr,
Jim Ingham10de7d12011-05-04 03:43:18 +0000480 m_varobj_options.use_dynamic,
481 expr_path_options,
482 var_sp,
483 error);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000484 if (valobj_sp)
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000485 {
Greg Clayton368f8222011-07-07 04:38:25 +0000486 if (m_option_variable.format != eFormatDefault)
487 valobj_sp->SetFormat (m_option_variable.format);
488 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000489 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000490 var_sp->GetDeclaration ().DumpStopContext (&s, false);
491 s.PutCString (": ");
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000492 }
Enrico Granata1a102082011-07-12 00:18:11 +0000493 if (summary_format_sp)
494 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000495 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Claytonc3b61d22010-12-15 05:08:08 +0000496 valobj_sp.get(),
Enrico Granata19030d82011-08-15 18:01:31 +0000497 valobj_sp->GetParent() ? name_cstr : NULL,
498 options);
Greg Claytonaed58812010-09-13 02:37:44 +0000499 }
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000500 else
501 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000502 const char *error_cstr = error.AsCString(NULL);
503 if (error_cstr)
504 result.GetErrorStream().Printf("error: %s\n", error_cstr);
505 else
506 result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000507 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000508 }
Jim Ingham537926c2010-09-02 00:18:39 +0000509 }
510 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000511 else
512 {
513 const uint32_t num_variables = variable_list->GetSize();
514
515 if (num_variables > 0)
516 {
517 for (uint32_t i=0; i<num_variables; i++)
518 {
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000519 var_sp = variable_list->GetVariableAtIndex(i);
Jim Inghame41494a2011-04-16 00:01:13 +0000520
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000521 bool dump_variable = true;
522
523 switch (var_sp->GetScope())
524 {
525 case eValueTypeVariableGlobal:
Greg Clayton368f8222011-07-07 04:38:25 +0000526 dump_variable = m_option_variable.show_globals;
527 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000528 s.PutCString("GLOBAL: ");
529 break;
530
531 case eValueTypeVariableStatic:
Greg Clayton368f8222011-07-07 04:38:25 +0000532 dump_variable = m_option_variable.show_globals;
533 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000534 s.PutCString("STATIC: ");
535 break;
536
537 case eValueTypeVariableArgument:
Greg Clayton368f8222011-07-07 04:38:25 +0000538 dump_variable = m_option_variable.show_args;
539 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000540 s.PutCString(" ARG: ");
541 break;
542
543 case eValueTypeVariableLocal:
Greg Clayton368f8222011-07-07 04:38:25 +0000544 dump_variable = m_option_variable.show_locals;
545 if (dump_variable && m_option_variable.show_scope)
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000546 s.PutCString(" LOCAL: ");
547 break;
548
549 default:
550 break;
551 }
552
553 if (dump_variable)
554 {
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000555
556 // Use the variable object code to make sure we are
557 // using the same APIs as the the public API will be
558 // using...
Jim Ingham994aba02011-08-27 01:22:52 +0000559 valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp,
Johnny Chen677aabd2011-09-08 23:52:06 +0000560 m_varobj_options.use_dynamic);
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000561 if (valobj_sp)
562 {
Greg Clayton368f8222011-07-07 04:38:25 +0000563 if (m_option_variable.format != eFormatDefault)
564 valobj_sp->SetFormat (m_option_variable.format);
Greg Claytonb1888f22011-03-19 01:12:21 +0000565
Greg Claytona357ecf2010-09-14 03:16:58 +0000566 // When dumping all variables, don't print any variables
567 // that are not in scope to avoid extra unneeded output
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000568 if (valobj_sp->IsInScope ())
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000569 {
Greg Clayton368f8222011-07-07 04:38:25 +0000570 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
Greg Claytona357ecf2010-09-14 03:16:58 +0000571 {
572 var_sp->GetDeclaration ().DumpStopContext (&s, false);
573 s.PutCString (": ");
574 }
Enrico Granata1a102082011-07-12 00:18:11 +0000575 if (summary_format_sp)
576 valobj_sp->SetCustomSummaryFormat(summary_format_sp);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000577 ValueObject::DumpValueObject (result.GetOutputStream(),
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000578 valobj_sp.get(),
Enrico Granata19030d82011-08-15 18:01:31 +0000579 name_cstr,
580 options);
Greg Claytona357ecf2010-09-14 03:16:58 +0000581 }
Greg Claytonc0cf52d2010-09-13 03:44:33 +0000582 }
583 }
584 }
585 }
586 }
587 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham537926c2010-09-02 00:18:39 +0000588 }
Jim Ingham537926c2010-09-02 00:18:39 +0000589 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000590
591 if (m_interpreter.TruncationWarningNecessary())
592 {
593 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
594 m_cmd_name.c_str());
595 m_interpreter.TruncationWarningGiven();
596 }
597
Jim Ingham537926c2010-09-02 00:18:39 +0000598 return result.Succeeded();
599 }
600protected:
601
Jim Ingham10de7d12011-05-04 03:43:18 +0000602 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000603 OptionGroupVariable m_option_variable;
Jim Ingham10de7d12011-05-04 03:43:18 +0000604 OptionGroupValueObjectDisplay m_varobj_options;
Jim Ingham537926c2010-09-02 00:18:39 +0000605};
606
Jim Ingham10de7d12011-05-04 03:43:18 +0000607
Chris Lattner24943d22010-06-08 16:52:24 +0000608#pragma mark CommandObjectMultiwordFrame
609
610//-------------------------------------------------------------------------
611// CommandObjectMultiwordFrame
612//-------------------------------------------------------------------------
613
Greg Clayton63094e02010-06-23 01:19:29 +0000614CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000615 CommandObjectMultiword (interpreter,
616 "frame",
Chris Lattner24943d22010-06-08 16:52:24 +0000617 "A set of commands for operating on the current thread's frames.",
618 "frame <subcommand> [<subcommand-options>]")
619{
Greg Clayton238c0a12010-09-18 01:14:36 +0000620 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
621 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
622 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000623}
624
625CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
626{
627}
628