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 // C Includes 11 // C++ Includes 12 #include <string> 13 14 // Other libraries and framework includes 15 // Project includes 16 #include "CommandObjectFrame.h" 17 #include "lldb/Core/Debugger.h" 18 #include "lldb/Core/Module.h" 19 #include "lldb/Core/StreamFile.h" 20 #include "lldb/Core/StreamString.h" 21 #include "lldb/Core/Timer.h" 22 #include "lldb/Core/Value.h" 23 #include "lldb/Core/ValueObject.h" 24 #include "lldb/Core/ValueObjectVariable.h" 25 #include "lldb/DataFormatters/DataVisualization.h" 26 #include "lldb/DataFormatters/ValueObjectPrinter.h" 27 #include "lldb/Host/Host.h" 28 #include "lldb/Host/StringConvert.h" 29 #include "lldb/Interpreter/Args.h" 30 #include "lldb/Interpreter/CommandInterpreter.h" 31 #include "lldb/Interpreter/CommandReturnObject.h" 32 #include "lldb/Interpreter/Options.h" 33 #include "lldb/Interpreter/OptionGroupFormat.h" 34 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" 35 #include "lldb/Interpreter/OptionGroupVariable.h" 36 #include "lldb/Symbol/CompilerType.h" 37 #include "lldb/Symbol/ClangASTContext.h" 38 #include "lldb/Symbol/Function.h" 39 #include "lldb/Symbol/ObjectFile.h" 40 #include "lldb/Symbol/SymbolContext.h" 41 #include "lldb/Symbol/Type.h" 42 #include "lldb/Symbol/Variable.h" 43 #include "lldb/Symbol/VariableList.h" 44 #include "lldb/Target/Process.h" 45 #include "lldb/Target/StackFrame.h" 46 #include "lldb/Target/StopInfo.h" 47 #include "lldb/Target/Thread.h" 48 #include "lldb/Target/Target.h" 49 #include "lldb/Utility/LLDBAssert.h" 50 51 using namespace lldb; 52 using namespace lldb_private; 53 54 #pragma mark CommandObjectFrameDiagnose 55 56 //------------------------------------------------------------------------- 57 // CommandObjectFrameInfo 58 //------------------------------------------------------------------------- 59 60 //------------------------------------------------------------------------- 61 // CommandObjectFrameDiagnose 62 //------------------------------------------------------------------------- 63 64 class CommandObjectFrameDiagnose : public CommandObjectParsed 65 { 66 public: 67 class CommandOptions : public Options 68 { 69 public: 70 CommandOptions() : 71 Options() 72 { 73 OptionParsingStarting(nullptr); 74 } 75 76 ~CommandOptions() override = default; 77 78 Error 79 SetOptionValue(uint32_t option_idx, const char *option_arg, 80 ExecutionContext *execution_context) override 81 { 82 Error error; 83 const int short_option = m_getopt_table[option_idx].val; 84 switch (short_option) 85 { 86 case 'r': 87 reg = ConstString(option_arg); 88 break; 89 90 case 'a': 91 { 92 bool success = false; 93 94 address = StringConvert::ToUInt64 (option_arg, 0, 0, &success); 95 if (!success) 96 { 97 address.reset(); 98 error.SetErrorStringWithFormat ("invalid address argument '%s'", option_arg); 99 } 100 } 101 break; 102 103 case 'o': 104 { 105 bool success = false; 106 107 offset = StringConvert::ToSInt64 (option_arg, 0, 0, &success); 108 if (!success) 109 { 110 offset.reset(); 111 error.SetErrorStringWithFormat ("invalid offset argument '%s'", option_arg); 112 } 113 } 114 break; 115 116 default: 117 error.SetErrorStringWithFormat ("invalid short option character '%c'", short_option); 118 break; 119 } 120 121 return error; 122 } 123 124 void 125 OptionParsingStarting(ExecutionContext *execution_context) override 126 { 127 address.reset(); 128 reg.reset(); 129 offset.reset(); 130 } 131 132 const OptionDefinition* 133 GetDefinitions () override 134 { 135 return g_option_table; 136 } 137 138 // Options table: Required for subclasses of Options. 139 static OptionDefinition g_option_table[]; 140 141 // Options. 142 llvm::Optional<lldb::addr_t> address; 143 llvm::Optional<ConstString> reg; 144 llvm::Optional<int64_t> offset; 145 }; 146 147 CommandObjectFrameDiagnose(CommandInterpreter &interpreter) 148 : CommandObjectParsed(interpreter, "frame diagnose", 149 "Try to determine what path path the current stop location used to get to a register or address", 150 nullptr, eCommandRequiresThread | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched | 151 eCommandProcessMustBePaused), 152 m_options() 153 { 154 CommandArgumentEntry arg; 155 CommandArgumentData index_arg; 156 157 // Define the first (and only) variant of this arg. 158 index_arg.arg_type = eArgTypeFrameIndex; 159 index_arg.arg_repetition = eArgRepeatOptional; 160 161 // There is only one variant this argument could be; put it into the argument entry. 162 arg.push_back (index_arg); 163 164 // Push the data for the first argument into the m_arguments vector. 165 m_arguments.push_back (arg); 166 } 167 168 ~CommandObjectFrameDiagnose() override = default; 169 170 Options * 171 GetOptions () override 172 { 173 return &m_options; 174 } 175 176 protected: 177 bool 178 DoExecute (Args& command, CommandReturnObject &result) override 179 { 180 Thread *thread = m_exe_ctx.GetThreadPtr(); 181 StackFrameSP frame_sp = thread->GetSelectedFrame(); 182 183 ValueObjectSP valobj_sp; 184 185 if (m_options.address.hasValue()) 186 { 187 if (m_options.reg.hasValue() || m_options.offset.hasValue()) 188 { 189 result.AppendError("`frame diagnose --address` is incompatible with other arguments."); 190 result.SetStatus(eReturnStatusFailed); 191 return false; 192 } 193 valobj_sp = frame_sp->GuessValueForAddress(m_options.address.getValue()); 194 } 195 else if (m_options.reg.hasValue()) 196 { 197 valobj_sp = frame_sp->GuessValueForRegisterAndOffset(m_options.reg.getValue(), m_options.offset.getValueOr(0)); 198 } 199 else 200 { 201 StopInfoSP stop_info_sp = thread->GetStopInfo(); 202 if (!stop_info_sp) 203 { 204 result.AppendError("No arguments provided, and no stop info."); 205 result.SetStatus(eReturnStatusFailed); 206 return false; 207 } 208 209 valobj_sp = StopInfo::GetCrashingDereference(stop_info_sp); 210 } 211 212 if (!valobj_sp) 213 { 214 result.AppendError("No diagnosis available."); 215 result.SetStatus(eReturnStatusFailed); 216 return false; 217 } 218 219 const bool qualify_cxx_base_classes = false; 220 221 DumpValueObjectOptions::DeclPrintingHelper helper = [&valobj_sp, qualify_cxx_base_classes](ConstString type, 222 ConstString var, 223 const DumpValueObjectOptions &opts, 224 Stream &stream) -> bool { 225 const ValueObject::GetExpressionPathFormat format = ValueObject::GetExpressionPathFormat::eGetExpressionPathFormatHonorPointers; 226 valobj_sp->GetExpressionPath(stream, qualify_cxx_base_classes, format); 227 stream.PutCString(" ="); 228 return true; 229 }; 230 231 DumpValueObjectOptions options; 232 options.SetDeclPrintingHelper(helper); 233 ValueObjectPrinter printer(valobj_sp.get(), &result.GetOutputStream(), options); 234 printer.PrintValueObject(); 235 236 return true; 237 } 238 239 protected: 240 CommandOptions m_options; 241 }; 242 243 OptionDefinition 244 CommandObjectFrameDiagnose::CommandOptions::g_option_table[] = 245 { 246 // clang-format off 247 {LLDB_OPT_SET_1, false, "register", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegisterName, "A register to diagnose."}, 248 {LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress, "An address to diagnose."}, 249 {LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "An optional offset. Requires --register."}, 250 {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} 251 // clang-format on 252 }; 253 254 #pragma mark CommandObjectFrameInfo 255 256 //------------------------------------------------------------------------- 257 // CommandObjectFrameInfo 258 //------------------------------------------------------------------------- 259 260 class CommandObjectFrameInfo : public CommandObjectParsed 261 { 262 public: 263 CommandObjectFrameInfo(CommandInterpreter &interpreter) 264 : CommandObjectParsed(interpreter, "frame info", 265 "List information about the current stack frame in the current thread.", "frame info", 266 eCommandRequiresFrame | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched | 267 eCommandProcessMustBePaused) 268 { 269 } 270 271 ~CommandObjectFrameInfo() override = default; 272 273 protected: 274 bool 275 DoExecute (Args& command, CommandReturnObject &result) override 276 { 277 m_exe_ctx.GetFrameRef().DumpUsingSettingsFormat (&result.GetOutputStream()); 278 result.SetStatus (eReturnStatusSuccessFinishResult); 279 return result.Succeeded(); 280 } 281 }; 282 283 #pragma mark CommandObjectFrameSelect 284 285 //------------------------------------------------------------------------- 286 // CommandObjectFrameSelect 287 //------------------------------------------------------------------------- 288 289 class CommandObjectFrameSelect : public CommandObjectParsed 290 { 291 public: 292 class CommandOptions : public Options 293 { 294 public: 295 CommandOptions() : 296 Options() 297 { 298 OptionParsingStarting(nullptr); 299 } 300 301 ~CommandOptions() override = default; 302 303 Error 304 SetOptionValue(uint32_t option_idx, const char *option_arg, 305 ExecutionContext *execution_context) override 306 { 307 Error error; 308 bool success = false; 309 const int short_option = m_getopt_table[option_idx].val; 310 switch (short_option) 311 { 312 case 'r': 313 relative_frame_offset = StringConvert::ToSInt32 (option_arg, INT32_MIN, 0, &success); 314 if (!success) 315 error.SetErrorStringWithFormat ("invalid frame offset argument '%s'", option_arg); 316 break; 317 318 default: 319 error.SetErrorStringWithFormat ("invalid short option character '%c'", short_option); 320 break; 321 } 322 323 return error; 324 } 325 326 void 327 OptionParsingStarting(ExecutionContext *execution_context) override 328 { 329 relative_frame_offset = INT32_MIN; 330 } 331 332 const OptionDefinition* 333 GetDefinitions () override 334 { 335 return g_option_table; 336 } 337 338 // Options table: Required for subclasses of Options. 339 340 static OptionDefinition g_option_table[]; 341 int32_t relative_frame_offset; 342 }; 343 344 CommandObjectFrameSelect(CommandInterpreter &interpreter) 345 : CommandObjectParsed( 346 interpreter, "frame select", 347 "Select the current stack frame by index from within the current thread (see 'thread backtrace'.)", 348 nullptr, eCommandRequiresThread | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched | 349 eCommandProcessMustBePaused), 350 m_options() 351 { 352 CommandArgumentEntry arg; 353 CommandArgumentData index_arg; 354 355 // Define the first (and only) variant of this arg. 356 index_arg.arg_type = eArgTypeFrameIndex; 357 index_arg.arg_repetition = eArgRepeatOptional; 358 359 // There is only one variant this argument could be; put it into the argument entry. 360 arg.push_back (index_arg); 361 362 // Push the data for the first argument into the m_arguments vector. 363 m_arguments.push_back (arg); 364 } 365 366 ~CommandObjectFrameSelect() override = default; 367 368 Options * 369 GetOptions () override 370 { 371 return &m_options; 372 } 373 374 protected: 375 bool 376 DoExecute (Args& command, CommandReturnObject &result) override 377 { 378 // No need to check "thread" for validity as eCommandRequiresThread ensures it is valid 379 Thread *thread = m_exe_ctx.GetThreadPtr(); 380 381 uint32_t frame_idx = UINT32_MAX; 382 if (m_options.relative_frame_offset != INT32_MIN) 383 { 384 // The one and only argument is a signed relative frame index 385 frame_idx = thread->GetSelectedFrameIndex (); 386 if (frame_idx == UINT32_MAX) 387 frame_idx = 0; 388 389 if (m_options.relative_frame_offset < 0) 390 { 391 if (static_cast<int32_t>(frame_idx) >= -m_options.relative_frame_offset) 392 frame_idx += m_options.relative_frame_offset; 393 else 394 { 395 if (frame_idx == 0) 396 { 397 //If you are already at the bottom of the stack, then just warn and don't reset the frame. 398 result.AppendError("Already at the bottom of the stack."); 399 result.SetStatus(eReturnStatusFailed); 400 return false; 401 } 402 else 403 frame_idx = 0; 404 } 405 } 406 else if (m_options.relative_frame_offset > 0) 407 { 408 // I don't want "up 20" where "20" takes you past the top of the stack to produce 409 // an error, but rather to just go to the top. So I have to count the stack here... 410 const uint32_t num_frames = thread->GetStackFrameCount(); 411 if (static_cast<int32_t>(num_frames - frame_idx) > m_options.relative_frame_offset) 412 frame_idx += m_options.relative_frame_offset; 413 else 414 { 415 if (frame_idx == num_frames - 1) 416 { 417 //If we are already at the top of the stack, just warn and don't reset the frame. 418 result.AppendError("Already at the top of the stack."); 419 result.SetStatus(eReturnStatusFailed); 420 return false; 421 } 422 else 423 frame_idx = num_frames - 1; 424 } 425 } 426 } 427 else 428 { 429 if (command.GetArgumentCount() == 1) 430 { 431 const char *frame_idx_cstr = command.GetArgumentAtIndex(0); 432 bool success = false; 433 frame_idx = StringConvert::ToUInt32 (frame_idx_cstr, UINT32_MAX, 0, &success); 434 if (!success) 435 { 436 result.AppendErrorWithFormat("invalid frame index argument '%s'.", frame_idx_cstr); 437 result.SetStatus (eReturnStatusFailed); 438 return false; 439 } 440 } 441 else if (command.GetArgumentCount() == 0) 442 { 443 frame_idx = thread->GetSelectedFrameIndex (); 444 if (frame_idx == UINT32_MAX) 445 { 446 frame_idx = 0; 447 } 448 } 449 else 450 { 451 result.AppendErrorWithFormat ("too many arguments; expected frame-index, saw '%s'.\n", 452 command.GetArgumentAtIndex(0)); 453 m_options.GenerateOptionUsage(result.GetErrorStream(), this, 454 GetCommandInterpreter() 455 .GetDebugger() 456 .GetTerminalWidth()); 457 return false; 458 } 459 } 460 461 bool success = thread->SetSelectedFrameByIndexNoisily (frame_idx, result.GetOutputStream()); 462 if (success) 463 { 464 m_exe_ctx.SetFrameSP(thread->GetSelectedFrame ()); 465 result.SetStatus (eReturnStatusSuccessFinishResult); 466 } 467 else 468 { 469 result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx); 470 result.SetStatus (eReturnStatusFailed); 471 } 472 473 return result.Succeeded(); 474 } 475 476 protected: 477 CommandOptions m_options; 478 }; 479 480 OptionDefinition 481 CommandObjectFrameSelect::CommandOptions::g_option_table[] = 482 { 483 // clang-format off 484 {LLDB_OPT_SET_1, false, "relative", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."}, 485 {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} 486 // clang-format on 487 }; 488 489 #pragma mark CommandObjectFrameVariable 490 //---------------------------------------------------------------------- 491 // List images with associated information 492 //---------------------------------------------------------------------- 493 class CommandObjectFrameVariable : public CommandObjectParsed 494 { 495 public: 496 CommandObjectFrameVariable(CommandInterpreter &interpreter) 497 : CommandObjectParsed( 498 interpreter, "frame variable", "Show variables for the current stack frame. Defaults to all " 499 "arguments and local variables in scope. Names of argument, " 500 "local, file static and file global variables can be specified. " 501 "Children of aggregate variables can be specified such as " 502 "'var->child.x'.", 503 nullptr, eCommandRequiresFrame | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched | 504 eCommandProcessMustBePaused | eCommandRequiresProcess), 505 m_option_group(), 506 m_option_variable(true), // Include the frame specific options by passing "true" 507 m_option_format(eFormatDefault), 508 m_varobj_options() 509 { 510 CommandArgumentEntry arg; 511 CommandArgumentData var_name_arg; 512 513 // Define the first (and only) variant of this arg. 514 var_name_arg.arg_type = eArgTypeVarName; 515 var_name_arg.arg_repetition = eArgRepeatStar; 516 517 // There is only one variant this argument could be; put it into the argument entry. 518 arg.push_back (var_name_arg); 519 520 // Push the data for the first argument into the m_arguments vector. 521 m_arguments.push_back (arg); 522 523 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); 524 m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1); 525 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); 526 m_option_group.Finalize(); 527 } 528 529 ~CommandObjectFrameVariable() override = default; 530 531 Options * 532 GetOptions () override 533 { 534 return &m_option_group; 535 } 536 537 int 538 HandleArgumentCompletion (Args &input, 539 int &cursor_index, 540 int &cursor_char_position, 541 OptionElementVector &opt_element_vector, 542 int match_start_point, 543 int max_return_elements, 544 bool &word_complete, 545 StringList &matches) override 546 { 547 // Arguments are the standard source file completer. 548 std::string completion_str (input.GetArgumentAtIndex(cursor_index)); 549 completion_str.erase (cursor_char_position); 550 551 CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(), 552 CommandCompletions::eVariablePathCompletion, 553 completion_str.c_str(), 554 match_start_point, 555 max_return_elements, 556 nullptr, 557 word_complete, 558 matches); 559 return matches.GetSize(); 560 } 561 562 protected: 563 bool 564 DoExecute (Args& command, CommandReturnObject &result) override 565 { 566 // No need to check "frame" for validity as eCommandRequiresFrame ensures it is valid 567 StackFrame *frame = m_exe_ctx.GetFramePtr(); 568 569 Stream &s = result.GetOutputStream(); 570 571 // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList 572 // for the thread. So hold onto a shared pointer to the frame so it stays alive. 573 574 VariableList *variable_list = frame->GetVariableList (m_option_variable.show_globals); 575 576 VariableSP var_sp; 577 ValueObjectSP valobj_sp; 578 579 const char *name_cstr = nullptr; 580 size_t idx; 581 582 TypeSummaryImplSP summary_format_sp; 583 if (!m_option_variable.summary.IsCurrentValueEmpty()) 584 DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.GetCurrentValue()), summary_format_sp); 585 else if (!m_option_variable.summary_string.IsCurrentValueEmpty()) 586 summary_format_sp.reset(new StringSummaryFormat(TypeSummaryImpl::Flags(),m_option_variable.summary_string.GetCurrentValue())); 587 588 DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(eLanguageRuntimeDescriptionDisplayVerbosityFull,eFormatDefault,summary_format_sp)); 589 590 const SymbolContext& sym_ctx = frame->GetSymbolContext(eSymbolContextFunction); 591 if (sym_ctx.function && sym_ctx.function->IsTopLevelFunction()) 592 m_option_variable.show_globals = true; 593 594 if (variable_list) 595 { 596 const Format format = m_option_format.GetFormat(); 597 options.SetFormat(format); 598 599 if (command.GetArgumentCount() > 0) 600 { 601 VariableList regex_var_list; 602 603 // If we have any args to the variable command, we will make 604 // variable objects from them... 605 for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != nullptr; ++idx) 606 { 607 if (m_option_variable.use_regex) 608 { 609 const size_t regex_start_index = regex_var_list.GetSize(); 610 RegularExpression regex (name_cstr); 611 if (regex.Compile(name_cstr)) 612 { 613 size_t num_matches = 0; 614 const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex, 615 regex_var_list, 616 num_matches); 617 if (num_new_regex_vars > 0) 618 { 619 for (size_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize(); 620 regex_idx < end_index; 621 ++regex_idx) 622 { 623 var_sp = regex_var_list.GetVariableAtIndex (regex_idx); 624 if (var_sp) 625 { 626 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic); 627 if (valobj_sp) 628 { 629 // if (format != eFormatDefault) 630 // valobj_sp->SetFormat (format); 631 632 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) 633 { 634 bool show_fullpaths = false; 635 bool show_module = true; 636 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module)) 637 s.PutCString (": "); 638 } 639 valobj_sp->Dump(result.GetOutputStream(),options); 640 } 641 } 642 } 643 } 644 else if (num_matches == 0) 645 { 646 result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr); 647 } 648 } 649 else 650 { 651 char regex_error[1024]; 652 if (regex.GetErrorAsCString(regex_error, sizeof(regex_error))) 653 result.GetErrorStream().Printf ("error: %s\n", regex_error); 654 else 655 result.GetErrorStream().Printf ("error: unknown regex error when compiling '%s'\n", name_cstr); 656 } 657 } 658 else // No regex, either exact variable names or variable expressions. 659 { 660 Error error; 661 uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember | 662 StackFrame::eExpressionPathOptionsAllowDirectIVarAccess | 663 StackFrame::eExpressionPathOptionsInspectAnonymousUnions; 664 lldb::VariableSP var_sp; 665 valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr, 666 m_varobj_options.use_dynamic, 667 expr_path_options, 668 var_sp, 669 error); 670 if (valobj_sp) 671 { 672 // if (format != eFormatDefault) 673 // valobj_sp->SetFormat (format); 674 if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile()) 675 { 676 var_sp->GetDeclaration ().DumpStopContext (&s, false); 677 s.PutCString (": "); 678 } 679 680 options.SetFormat(format); 681 options.SetVariableFormatDisplayLanguage(valobj_sp->GetPreferredDisplayLanguage()); 682 683 Stream &output_stream = result.GetOutputStream(); 684 options.SetRootValueObjectName(valobj_sp->GetParent() ? name_cstr : nullptr); 685 valobj_sp->Dump(output_stream,options); 686 } 687 else 688 { 689 const char *error_cstr = error.AsCString(nullptr); 690 if (error_cstr) 691 result.GetErrorStream().Printf("error: %s\n", error_cstr); 692 else 693 result.GetErrorStream().Printf( 694 "error: unable to find any variable expression path that matches '%s'.\n", 695 name_cstr); 696 } 697 } 698 } 699 } 700 else // No command arg specified. Use variable_list, instead. 701 { 702 const size_t num_variables = variable_list->GetSize(); 703 if (num_variables > 0) 704 { 705 for (size_t i=0; i<num_variables; i++) 706 { 707 var_sp = variable_list->GetVariableAtIndex(i); 708 bool dump_variable = true; 709 std::string scope_string; 710 switch (var_sp->GetScope()) 711 { 712 case eValueTypeVariableGlobal: 713 // Always dump globals since we only fetched them if 714 // m_option_variable.show_scope was true 715 if (dump_variable && m_option_variable.show_scope) 716 scope_string = "GLOBAL: "; 717 break; 718 719 case eValueTypeVariableStatic: 720 // Always dump globals since we only fetched them if 721 // m_option_variable.show_scope was true, or this is 722 // a static variable from a block in the current scope 723 if (dump_variable && m_option_variable.show_scope) 724 scope_string = "STATIC: "; 725 break; 726 727 case eValueTypeVariableArgument: 728 dump_variable = m_option_variable.show_args; 729 if (dump_variable && m_option_variable.show_scope) 730 scope_string = " ARG: "; 731 break; 732 733 case eValueTypeVariableLocal: 734 dump_variable = m_option_variable.show_locals; 735 if (dump_variable && m_option_variable.show_scope) 736 scope_string = " LOCAL: "; 737 break; 738 739 case eValueTypeVariableThreadLocal: 740 if (dump_variable && m_option_variable.show_scope) 741 scope_string = "THREAD: "; 742 break; 743 default: 744 break; 745 } 746 747 if (dump_variable) 748 { 749 // Use the variable object code to make sure we are 750 // using the same APIs as the public API will be 751 // using... 752 valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, 753 m_varobj_options.use_dynamic); 754 if (valobj_sp) 755 { 756 // if (format != eFormatDefault) 757 // valobj_sp->SetFormat (format); 758 759 // When dumping all variables, don't print any variables 760 // that are not in scope to avoid extra unneeded output 761 if (valobj_sp->IsInScope ()) 762 { 763 if (!valobj_sp->GetTargetSP()->GetDisplayRuntimeSupportValues() && 764 valobj_sp->IsRuntimeSupportValue()) 765 continue; 766 767 if (!scope_string.empty()) 768 s.PutCString(scope_string.c_str()); 769 770 if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) 771 { 772 var_sp->GetDeclaration ().DumpStopContext (&s, false); 773 s.PutCString (": "); 774 } 775 776 options.SetFormat(format); 777 options.SetVariableFormatDisplayLanguage(valobj_sp->GetPreferredDisplayLanguage()); 778 options.SetRootValueObjectName(name_cstr); 779 valobj_sp->Dump(result.GetOutputStream(),options); 780 } 781 } 782 } 783 } 784 } 785 } 786 result.SetStatus (eReturnStatusSuccessFinishResult); 787 } 788 789 if (m_interpreter.TruncationWarningNecessary()) 790 { 791 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(), 792 m_cmd_name.c_str()); 793 m_interpreter.TruncationWarningGiven(); 794 } 795 796 return result.Succeeded(); 797 } 798 799 protected: 800 OptionGroupOptions m_option_group; 801 OptionGroupVariable m_option_variable; 802 OptionGroupFormat m_option_format; 803 OptionGroupValueObjectDisplay m_varobj_options; 804 }; 805 806 #pragma mark CommandObjectMultiwordFrame 807 808 //------------------------------------------------------------------------- 809 // CommandObjectMultiwordFrame 810 //------------------------------------------------------------------------- 811 812 CommandObjectMultiwordFrame::CommandObjectMultiwordFrame(CommandInterpreter &interpreter) 813 : CommandObjectMultiword(interpreter, "frame", 814 "Commands for selecting and examing the current thread's stack frames.", 815 "frame <subcommand> [<subcommand-options>]") 816 { 817 LoadSubCommand ("diagnose", CommandObjectSP (new CommandObjectFrameDiagnose (interpreter))); 818 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter))); 819 LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter))); 820 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter))); 821 } 822 823 CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame() = default; 824