Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Debugger.h" |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Module.h" |
| 18 | #include "lldb/Core/StreamFile.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Timer.h" |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Value.h" |
| 21 | #include "lldb/Core/ValueObject.h" |
| 22 | #include "lldb/Core/ValueObjectVariable.h" |
| 23 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 25 | #include "lldb/Interpreter/CommandReturnObject.h" |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 26 | #include "lldb/Interpreter/Options.h" |
| 27 | #include "lldb/Symbol/ClangASTType.h" |
| 28 | #include "lldb/Symbol/ClangASTContext.h" |
| 29 | #include "lldb/Symbol/ObjectFile.h" |
| 30 | #include "lldb/Symbol/SymbolContext.h" |
| 31 | #include "lldb/Symbol/Type.h" |
| 32 | #include "lldb/Symbol/Variable.h" |
| 33 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Target/Process.h" |
| 35 | #include "lldb/Target/StackFrame.h" |
| 36 | #include "lldb/Target/Thread.h" |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 37 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | |
| 39 | #include "CommandObjectThread.h" |
| 40 | |
| 41 | using namespace lldb; |
| 42 | using namespace lldb_private; |
| 43 | |
| 44 | #pragma mark CommandObjectFrameInfo |
| 45 | |
| 46 | //------------------------------------------------------------------------- |
| 47 | // CommandObjectFrameInfo |
| 48 | //------------------------------------------------------------------------- |
| 49 | |
| 50 | class CommandObjectFrameInfo : public CommandObject |
| 51 | { |
| 52 | public: |
| 53 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 54 | CommandObjectFrameInfo (CommandInterpreter &interpreter) : |
| 55 | CommandObject (interpreter, |
| 56 | "frame info", |
| 57 | "List information about the currently selected frame in the current thread.", |
| 58 | "frame info", |
| 59 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | { |
| 61 | } |
| 62 | |
| 63 | ~CommandObjectFrameInfo () |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 68 | Execute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | CommandReturnObject &result) |
| 70 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 71 | ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | if (exe_ctx.frame) |
| 73 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 74 | exe_ctx.frame->Dump (&result.GetOutputStream(), true, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | result.GetOutputStream().EOL(); |
| 76 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | result.AppendError ("no current frame"); |
| 81 | result.SetStatus (eReturnStatusFailed); |
| 82 | } |
| 83 | return result.Succeeded(); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | #pragma mark CommandObjectFrameSelect |
| 88 | |
| 89 | //------------------------------------------------------------------------- |
| 90 | // CommandObjectFrameSelect |
| 91 | //------------------------------------------------------------------------- |
| 92 | |
| 93 | class CommandObjectFrameSelect : public CommandObject |
| 94 | { |
| 95 | public: |
| 96 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 97 | CommandObjectFrameSelect (CommandInterpreter &interpreter) : |
| 98 | CommandObject (interpreter, |
| 99 | "frame select", |
| 100 | "Select a frame by index from within the current thread and make it the current frame.", |
| 101 | "frame select <frame-index>", |
| 102 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | { |
| 104 | } |
| 105 | |
| 106 | ~CommandObjectFrameSelect () |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 111 | Execute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 112 | CommandReturnObject &result) |
| 113 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 114 | ExecutionContext exe_ctx (m_interpreter.GetDebugger().GetExecutionContext()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | if (exe_ctx.thread) |
| 116 | { |
| 117 | if (command.GetArgumentCount() == 1) |
| 118 | { |
| 119 | const char *frame_idx_cstr = command.GetArgumentAtIndex(0); |
| 120 | |
| 121 | const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount(); |
| 122 | const uint32_t frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0); |
| 123 | if (frame_idx < num_frames) |
| 124 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 125 | exe_ctx.thread->SetSelectedFrameByIndex (frame_idx); |
| 126 | exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 127 | |
| 128 | if (exe_ctx.frame) |
| 129 | { |
Jim Ingham | 74989e8 | 2010-08-30 19:44:40 +0000 | [diff] [blame] | 130 | bool already_shown = false; |
| 131 | SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry)); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 132 | if (m_interpreter.GetDebugger().UseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) |
Jim Ingham | 74989e8 | 2010-08-30 19:44:40 +0000 | [diff] [blame] | 133 | { |
| 134 | already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 135 | } |
| 136 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 137 | if (DisplayFrameForExecutionContext (exe_ctx.thread, |
| 138 | exe_ctx.frame, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 139 | m_interpreter, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | result.GetOutputStream(), |
| 141 | true, |
Jim Ingham | 74989e8 | 2010-08-30 19:44:40 +0000 | [diff] [blame] | 142 | !already_shown, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | 3, |
| 144 | 3)) |
| 145 | { |
| 146 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 147 | return result.Succeeded(); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | if (frame_idx == UINT32_MAX) |
| 152 | result.AppendErrorWithFormat ("Invalid frame index: %s.\n", frame_idx_cstr); |
| 153 | else |
| 154 | result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx); |
| 155 | } |
| 156 | else |
| 157 | { |
| 158 | result.AppendError ("invalid arguments"); |
| 159 | result.AppendErrorWithFormat ("Usage: %s\n", m_cmd_syntax.c_str()); |
| 160 | } |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | result.AppendError ("no current thread"); |
| 165 | } |
| 166 | result.SetStatus (eReturnStatusFailed); |
| 167 | return false; |
| 168 | } |
| 169 | }; |
| 170 | |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 171 | #pragma mark CommandObjectFrameVariable |
| 172 | //---------------------------------------------------------------------- |
| 173 | // List images with associated information |
| 174 | //---------------------------------------------------------------------- |
| 175 | class CommandObjectFrameVariable : public CommandObject |
| 176 | { |
| 177 | public: |
| 178 | |
| 179 | class CommandOptions : public Options |
| 180 | { |
| 181 | public: |
| 182 | |
| 183 | CommandOptions () : |
| 184 | Options() |
| 185 | { |
| 186 | ResetOptionValues (); |
| 187 | } |
| 188 | |
| 189 | virtual |
| 190 | ~CommandOptions () |
| 191 | { |
| 192 | } |
| 193 | |
| 194 | virtual Error |
| 195 | SetOptionValue (int option_idx, const char *option_arg) |
| 196 | { |
| 197 | Error error; |
| 198 | bool success; |
| 199 | char short_option = (char) m_getopt_table[option_idx].val; |
| 200 | switch (short_option) |
| 201 | { |
| 202 | case 'o': use_objc = true; break; |
| 203 | case 'n': name = option_arg; break; |
| 204 | case 'r': use_regex = true; break; |
| 205 | case 'a': show_args = false; break; |
| 206 | case 'l': show_locals = false; break; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 207 | case 'g': show_globals = true; break; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 208 | case 't': show_types = false; break; |
| 209 | case 'y': show_summary = false; break; |
| 210 | case 'L': show_location= true; break; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 211 | case 'c': show_decl = true; break; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 212 | case 'D': debug = true; break; |
| 213 | case 'd': |
| 214 | max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success); |
| 215 | if (!success) |
| 216 | error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg); |
| 217 | break; |
| 218 | |
| 219 | case 'p': |
| 220 | ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success); |
| 221 | if (!success) |
| 222 | error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg); |
| 223 | break; |
| 224 | |
| 225 | case 'G': |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 226 | globals.push_back(ConstString (option_arg)); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 227 | break; |
| 228 | |
| 229 | case 's': |
| 230 | show_scope = true; |
| 231 | break; |
| 232 | |
| 233 | default: |
| 234 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | return error; |
| 239 | } |
| 240 | |
| 241 | void |
| 242 | ResetOptionValues () |
| 243 | { |
| 244 | Options::ResetOptionValues(); |
| 245 | |
| 246 | name.clear(); |
| 247 | use_objc = false; |
| 248 | use_regex = false; |
| 249 | show_args = true; |
| 250 | show_locals = true; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 251 | show_globals = false; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 252 | show_types = true; |
| 253 | show_scope = false; |
| 254 | show_summary = true; |
| 255 | show_location = false; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 256 | show_decl = false; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 257 | debug = false; |
| 258 | max_depth = UINT32_MAX; |
| 259 | ptr_depth = 0; |
| 260 | globals.clear(); |
| 261 | } |
| 262 | |
| 263 | const lldb::OptionDefinition* |
| 264 | GetDefinitions () |
| 265 | { |
| 266 | return g_option_table; |
| 267 | } |
| 268 | |
| 269 | // Options table: Required for subclasses of Options. |
| 270 | |
| 271 | static lldb::OptionDefinition g_option_table[]; |
| 272 | std::string name; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 273 | bool use_objc:1, |
| 274 | use_regex:1, |
| 275 | show_args:1, |
| 276 | show_locals:1, |
| 277 | show_globals:1, |
| 278 | show_types:1, |
| 279 | show_scope:1, |
| 280 | show_summary:1, |
| 281 | show_location:1, |
| 282 | show_decl:1, |
| 283 | debug:1; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 284 | uint32_t max_depth; // The depth to print when dumping concrete (not pointers) aggreate values |
| 285 | uint32_t ptr_depth; // The default depth that is dumped when we find pointers |
| 286 | std::vector<ConstString> globals; |
| 287 | // Instance variables to hold the values for command options. |
| 288 | }; |
| 289 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 290 | CommandObjectFrameVariable (CommandInterpreter &interpreter) : |
| 291 | CommandObject (interpreter, |
| 292 | "frame variable", |
| 293 | "Show specified argument, local variable, static variable or global variable for the current frame. If none specified, list them all.", |
| 294 | "frame variable [<cmd-options>] [<var-name1> [<var-name2>...]]") |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 295 | { |
| 296 | } |
| 297 | |
| 298 | virtual |
| 299 | ~CommandObjectFrameVariable () |
| 300 | { |
| 301 | } |
| 302 | |
| 303 | virtual |
| 304 | Options * |
| 305 | GetOptions () |
| 306 | { |
| 307 | return &m_options; |
| 308 | } |
| 309 | |
| 310 | void |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 311 | DumpValueObject (CommandReturnObject &result, |
| 312 | ExecutionContextScope *exe_scope, |
| 313 | ValueObject *valobj, |
| 314 | const char *root_valobj_name, |
| 315 | uint32_t ptr_depth, |
| 316 | uint32_t curr_depth, |
| 317 | uint32_t max_depth, |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 318 | bool use_objc, |
| 319 | bool scope_already_checked) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 320 | { |
| 321 | if (valobj) |
| 322 | { |
| 323 | Stream &s = result.GetOutputStream(); |
| 324 | |
| 325 | //const char *loc_cstr = valobj->GetLocationAsCString(); |
| 326 | if (m_options.show_location) |
| 327 | { |
| 328 | s.Printf("@ %s: ", valobj->GetLocationAsCString(exe_scope)); |
| 329 | } |
| 330 | if (m_options.debug) |
| 331 | s.Printf ("%p ValueObject{%u} ", valobj, valobj->GetID()); |
| 332 | |
| 333 | s.Indent(); |
| 334 | |
| 335 | if (m_options.show_types) |
| 336 | s.Printf("(%s) ", valobj->GetTypeName().AsCString()); |
| 337 | |
| 338 | const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString(""); |
| 339 | s.Printf ("%s = ", name_cstr); |
| 340 | |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 341 | if (!scope_already_checked && !valobj->IsInScope(exe_scope->CalculateStackFrame())) |
| 342 | { |
| 343 | s.PutCString("error: out of scope"); |
| 344 | return; |
| 345 | } |
| 346 | |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 347 | const char *val_cstr = valobj->GetValueAsCString(exe_scope); |
| 348 | const char *err_cstr = valobj->GetError().AsCString(); |
| 349 | |
| 350 | if (err_cstr) |
| 351 | { |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 352 | s.Printf ("error: %s", err_cstr); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 353 | } |
| 354 | else |
| 355 | { |
| 356 | const char *sum_cstr = valobj->GetSummaryAsCString(exe_scope); |
| 357 | |
| 358 | const bool is_aggregate = ClangASTContext::IsAggregateType (valobj->GetOpaqueClangQualType()); |
| 359 | |
| 360 | if (val_cstr) |
| 361 | s.PutCString(val_cstr); |
| 362 | |
| 363 | if (sum_cstr) |
| 364 | s.Printf(" %s", sum_cstr); |
| 365 | |
| 366 | if (use_objc) |
| 367 | { |
Jim Ingham | 4ae5196 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 368 | const char *object_desc = valobj->GetObjectDescription(exe_scope); |
| 369 | if (object_desc) |
| 370 | s.Printf("\n%s\n", object_desc); |
| 371 | else |
| 372 | s.Printf ("No description available.\n"); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 373 | return; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | if (curr_depth < max_depth) |
| 378 | { |
| 379 | if (is_aggregate) |
| 380 | s.PutChar('{'); |
| 381 | |
| 382 | bool is_ptr_or_ref = ClangASTContext::IsPointerOrReferenceType (valobj->GetOpaqueClangQualType()); |
| 383 | |
| 384 | if (is_ptr_or_ref && ptr_depth == 0) |
| 385 | return; |
| 386 | |
| 387 | const uint32_t num_children = valobj->GetNumChildren(); |
| 388 | if (num_children) |
| 389 | { |
| 390 | s.IndentMore(); |
| 391 | for (uint32_t idx=0; idx<num_children; ++idx) |
| 392 | { |
| 393 | ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true)); |
| 394 | if (child_sp.get()) |
| 395 | { |
| 396 | s.EOL(); |
| 397 | DumpValueObject (result, |
| 398 | exe_scope, |
| 399 | child_sp.get(), |
| 400 | NULL, |
| 401 | is_ptr_or_ref ? ptr_depth - 1 : ptr_depth, |
| 402 | curr_depth + 1, |
| 403 | max_depth, |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 404 | false, |
| 405 | true); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 406 | if (idx + 1 < num_children) |
| 407 | s.PutChar(','); |
| 408 | } |
| 409 | } |
| 410 | s.IndentLess(); |
| 411 | } |
| 412 | if (is_aggregate) |
| 413 | { |
| 414 | s.EOL(); |
| 415 | s.Indent("}"); |
| 416 | } |
| 417 | } |
| 418 | else |
| 419 | { |
| 420 | if (is_aggregate) |
| 421 | { |
| 422 | s.PutCString("{...}"); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | virtual bool |
| 431 | Execute |
| 432 | ( |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 433 | Args& command, |
| 434 | CommandReturnObject &result |
| 435 | ) |
| 436 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 437 | ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 438 | if (exe_ctx.frame == NULL) |
| 439 | { |
| 440 | result.AppendError ("invalid frame"); |
| 441 | result.SetStatus (eReturnStatusFailed); |
| 442 | return false; |
| 443 | } |
| 444 | else |
| 445 | { |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 446 | Stream &s = result.GetOutputStream(); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 447 | |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 448 | bool get_file_globals = true; |
| 449 | VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals); |
| 450 | |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 451 | VariableSP var_sp; |
| 452 | ValueObjectSP valobj_sp; |
| 453 | //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList(); |
| 454 | const char *name_cstr = NULL; |
| 455 | size_t idx; |
| 456 | if (!m_options.globals.empty()) |
| 457 | { |
| 458 | uint32_t fail_count = 0; |
| 459 | if (exe_ctx.target) |
| 460 | { |
| 461 | const size_t num_globals = m_options.globals.size(); |
| 462 | for (idx = 0; idx < num_globals; ++idx) |
| 463 | { |
| 464 | VariableList global_var_list; |
| 465 | const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list); |
| 466 | |
| 467 | if (num_matching_globals == 0) |
| 468 | { |
| 469 | ++fail_count; |
| 470 | result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString()); |
| 471 | } |
| 472 | else |
| 473 | { |
| 474 | for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx) |
| 475 | { |
| 476 | var_sp = global_var_list.GetVariableAtIndex(global_idx); |
| 477 | if (var_sp) |
| 478 | { |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 479 | valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 480 | if (!valobj_sp) |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 481 | valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 482 | |
| 483 | if (valobj_sp) |
| 484 | { |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 485 | if (m_options.show_decl && var_sp->GetDeclaration ().GetFile()) |
| 486 | { |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 487 | var_sp->GetDeclaration ().DumpStopContext (&s, false); |
| 488 | s.PutCString (": "); |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 491 | DumpValueObject (result, |
| 492 | exe_ctx.frame, |
| 493 | valobj_sp.get(), |
| 494 | name_cstr, |
| 495 | m_options.ptr_depth, |
| 496 | 0, |
| 497 | m_options.max_depth, |
| 498 | m_options.use_objc, |
| 499 | false); |
| 500 | |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 501 | s.EOL(); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | if (fail_count) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 509 | result.SetStatus (eReturnStatusFailed); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 510 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 511 | else if (variable_list) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 512 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 513 | if (command.GetArgumentCount() > 0) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 514 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 515 | // If we have any args to the variable command, we will make |
| 516 | // variable objects from them... |
| 517 | for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 518 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 519 | uint32_t ptr_depth = m_options.ptr_depth; |
| 520 | // If first character is a '*', then show pointer contents |
| 521 | if (name_cstr[0] == '*') |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 522 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 523 | ++ptr_depth; |
| 524 | name_cstr++; // Skip the '*' |
| 525 | } |
| 526 | |
| 527 | std::string var_path (name_cstr); |
| 528 | size_t separator_idx = var_path.find_first_of(".-["); |
| 529 | |
| 530 | ConstString name_const_string; |
| 531 | if (separator_idx == std::string::npos) |
| 532 | name_const_string.SetCString (var_path.c_str()); |
| 533 | else |
| 534 | name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); |
| 535 | |
| 536 | var_sp = variable_list->FindVariable(name_const_string); |
| 537 | if (var_sp) |
| 538 | { |
| 539 | valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp); |
| 540 | |
| 541 | var_path.erase (0, name_const_string.GetLength ()); |
| 542 | // We are dumping at least one child |
| 543 | while (separator_idx != std::string::npos) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 544 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 545 | // Calculate the next separator index ahead of time |
| 546 | ValueObjectSP child_valobj_sp; |
| 547 | const char separator_type = var_path[0]; |
| 548 | switch (separator_type) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 549 | { |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 550 | |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 551 | case '-': |
| 552 | if (var_path.size() >= 2 && var_path[1] != '>') |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 553 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 554 | result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n", |
| 555 | var_path.c_str()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 556 | var_path.clear(); |
| 557 | valobj_sp.reset(); |
| 558 | break; |
| 559 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 560 | var_path.erase (0, 1); // Remove the '-' |
| 561 | // Fall through |
| 562 | case '.': |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 563 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 564 | var_path.erase (0, 1); // Remove the '.' or '>' |
| 565 | separator_idx = var_path.find_first_of(".-["); |
| 566 | ConstString child_name; |
| 567 | if (separator_idx == std::string::npos) |
| 568 | child_name.SetCString (var_path.c_str()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 569 | else |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 570 | child_name.SetCStringWithLength(var_path.c_str(), separator_idx); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 571 | |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 572 | child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 573 | if (!child_valobj_sp) |
| 574 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 575 | result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n", |
| 576 | valobj_sp->GetName().AsCString(), |
| 577 | child_name.GetCString()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 578 | var_path.clear(); |
| 579 | valobj_sp.reset(); |
| 580 | break; |
| 581 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 582 | // Remove the child name from the path |
| 583 | var_path.erase(0, child_name.GetLength()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 584 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 585 | break; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 586 | |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 587 | case '[': |
| 588 | // Array member access, or treating pointer as an array |
| 589 | if (var_path.size() > 2) // Need at least two brackets and a number |
| 590 | { |
| 591 | char *end = NULL; |
| 592 | int32_t child_index = ::strtol (&var_path[1], &end, 0); |
| 593 | if (end && *end == ']') |
| 594 | { |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 595 | |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 596 | if (valobj_sp->IsPointerType ()) |
| 597 | { |
| 598 | child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true); |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); |
| 603 | } |
| 604 | |
| 605 | if (!child_valobj_sp) |
| 606 | { |
| 607 | result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n", |
| 608 | child_index, |
| 609 | valobj_sp->GetName().AsCString()); |
| 610 | var_path.clear(); |
| 611 | valobj_sp.reset(); |
| 612 | break; |
| 613 | } |
| 614 | |
| 615 | // Erase the array member specification '[%i]' where %i is the array index |
| 616 | var_path.erase(0, (end - var_path.c_str()) + 1); |
| 617 | separator_idx = var_path.find_first_of(".-["); |
| 618 | |
| 619 | // Break out early from the switch since we were able to find the child member |
| 620 | break; |
| 621 | } |
| 622 | } |
| 623 | result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n", |
| 624 | valobj_sp->GetName().AsCString(), |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 625 | var_path.c_str()); |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 626 | var_path.clear(); |
| 627 | valobj_sp.reset(); |
| 628 | break; |
| 629 | |
| 630 | break; |
| 631 | |
| 632 | default: |
| 633 | result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n", |
| 634 | var_path.c_str()); |
| 635 | var_path.clear(); |
| 636 | valobj_sp.reset(); |
| 637 | separator_idx = std::string::npos; |
| 638 | break; |
| 639 | } |
| 640 | |
| 641 | if (child_valobj_sp) |
| 642 | valobj_sp = child_valobj_sp; |
| 643 | |
| 644 | if (var_path.empty()) |
| 645 | break; |
| 646 | |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 649 | if (valobj_sp) |
| 650 | { |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 651 | if (m_options.show_decl && var_sp->GetDeclaration ().GetFile()) |
| 652 | { |
| 653 | var_sp->GetDeclaration ().DumpStopContext (&s, false); |
| 654 | s.PutCString (": "); |
| 655 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 656 | |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 657 | DumpValueObject (result, |
| 658 | exe_ctx.frame, |
| 659 | valobj_sp.get(), |
| 660 | name_cstr, |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 661 | ptr_depth, |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 662 | 0, |
| 663 | m_options.max_depth, |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 664 | m_options.use_objc, |
| 665 | false); |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 666 | |
| 667 | s.EOL(); |
| 668 | } |
| 669 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 670 | else |
| 671 | { |
| 672 | result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr); |
| 673 | var_path.clear(); |
| 674 | } |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 675 | } |
| 676 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 677 | else |
| 678 | { |
| 679 | const uint32_t num_variables = variable_list->GetSize(); |
| 680 | |
| 681 | if (num_variables > 0) |
| 682 | { |
| 683 | for (uint32_t i=0; i<num_variables; i++) |
| 684 | { |
| 685 | VariableSP var_sp (variable_list->GetVariableAtIndex(i)); |
| 686 | bool dump_variable = true; |
| 687 | |
| 688 | switch (var_sp->GetScope()) |
| 689 | { |
| 690 | case eValueTypeVariableGlobal: |
| 691 | dump_variable = m_options.show_globals; |
| 692 | if (dump_variable && m_options.show_scope) |
| 693 | s.PutCString("GLOBAL: "); |
| 694 | break; |
| 695 | |
| 696 | case eValueTypeVariableStatic: |
| 697 | dump_variable = m_options.show_globals; |
| 698 | if (dump_variable && m_options.show_scope) |
| 699 | s.PutCString("STATIC: "); |
| 700 | break; |
| 701 | |
| 702 | case eValueTypeVariableArgument: |
| 703 | dump_variable = m_options.show_args; |
| 704 | if (dump_variable && m_options.show_scope) |
| 705 | s.PutCString(" ARG: "); |
| 706 | break; |
| 707 | |
| 708 | case eValueTypeVariableLocal: |
| 709 | dump_variable = m_options.show_locals; |
| 710 | if (dump_variable && m_options.show_scope) |
| 711 | s.PutCString(" LOCAL: "); |
| 712 | break; |
| 713 | |
| 714 | default: |
| 715 | break; |
| 716 | } |
| 717 | |
| 718 | if (dump_variable) |
| 719 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 720 | |
| 721 | // Use the variable object code to make sure we are |
| 722 | // using the same APIs as the the public API will be |
| 723 | // using... |
| 724 | valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp); |
| 725 | if (valobj_sp) |
| 726 | { |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 727 | // When dumping all variables, don't print any variables |
| 728 | // that are not in scope to avoid extra unneeded output |
| 729 | if (valobj_sp->IsInScope (exe_ctx.frame)) |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 730 | { |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 731 | if (m_options.show_decl && var_sp->GetDeclaration ().GetFile()) |
| 732 | { |
| 733 | var_sp->GetDeclaration ().DumpStopContext (&s, false); |
| 734 | s.PutCString (": "); |
| 735 | } |
| 736 | DumpValueObject (result, |
| 737 | exe_ctx.frame, |
| 738 | valobj_sp.get(), |
| 739 | name_cstr, |
| 740 | m_options.ptr_depth, |
| 741 | 0, |
| 742 | m_options.max_depth, |
| 743 | m_options.use_objc, |
| 744 | true); |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 745 | |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 746 | s.EOL(); |
| 747 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 754 | } |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 755 | } |
| 756 | return result.Succeeded(); |
| 757 | } |
| 758 | protected: |
| 759 | |
| 760 | CommandOptions m_options; |
| 761 | }; |
| 762 | |
| 763 | lldb::OptionDefinition |
| 764 | CommandObjectFrameVariable::CommandOptions::g_option_table[] = |
| 765 | { |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 766 | { LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, NULL, "Enable verbose debug information."}, |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 767 | { LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, "<count>", "Set the max recurse depth when dumping aggregate types (default is infinity)."}, |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 768 | { LLDB_OPT_SET_1, false, "show-globals",'g', no_argument, NULL, 0, NULL, "Show the current frame source file global and static variables."}, |
| 769 | { LLDB_OPT_SET_1, false, "find-global",'G', required_argument, NULL, 0, NULL, "Find a global variable by name (which might not be in the current stack frame source file)."}, |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 770 | { LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, NULL, "Show variable location information."}, |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 771 | { LLDB_OPT_SET_1, false, "show-declaration", 'c', no_argument, NULL, 0, NULL, "Show variable declaration information (source file and line where the variable was declared)."}, |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 772 | { LLDB_OPT_SET_1, false, "name", 'n', required_argument, NULL, 0, "<name>", "Lookup a variable by name or regex (--regex) for the current execution context."}, |
| 773 | { LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, NULL, "Omit function arguments."}, |
| 774 | { LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, NULL, "Omit local variables."}, |
| 775 | { LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, NULL, "Omit variable type names."}, |
| 776 | { LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, NULL, "Omit summary information."}, |
| 777 | { LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, NULL, "Show variable scope (argument, local, global, static)."}, |
| 778 | { LLDB_OPT_SET_1, false, "objc", 'o', no_argument, NULL, 0, NULL, "When looking up a variable by name (--name), print as an Objective-C object."}, |
| 779 | { LLDB_OPT_SET_1, false, "ptr-depth", 'p', required_argument, NULL, 0, "<count>", "The number of pointers to be traversed when dumping values (default is zero)."}, |
| 780 | { LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."}, |
| 781 | { 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL } |
| 782 | }; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 783 | #pragma mark CommandObjectMultiwordFrame |
| 784 | |
| 785 | //------------------------------------------------------------------------- |
| 786 | // CommandObjectMultiwordFrame |
| 787 | //------------------------------------------------------------------------- |
| 788 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 789 | CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 790 | CommandObjectMultiword (interpreter, |
| 791 | "frame", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 792 | "A set of commands for operating on the current thread's frames.", |
| 793 | "frame <subcommand> [<subcommand-options>]") |
| 794 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 795 | LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter))); |
| 796 | LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter))); |
| 797 | LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter))); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame () |
| 801 | { |
| 802 | } |
| 803 | |