1 //===-- ValueObject.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 "lldb/Core/ValueObject.h" 11 12 // C Includes 13 #include <stdlib.h> 14 15 // C++ Includes 16 // Other libraries and framework includes 17 #include "llvm/Support/raw_ostream.h" 18 19 // Project includes 20 #include "lldb/Core/DataBufferHeap.h" 21 #include "lldb/Core/Debugger.h" 22 #include "lldb/Core/Log.h" 23 #include "lldb/Core/Module.h" 24 #include "lldb/Core/StreamString.h" 25 #include "lldb/Core/ValueObjectCast.h" 26 #include "lldb/Core/ValueObjectChild.h" 27 #include "lldb/Core/ValueObjectConstResult.h" 28 #include "lldb/Core/ValueObjectDynamicValue.h" 29 #include "lldb/Core/ValueObjectList.h" 30 #include "lldb/Core/ValueObjectMemory.h" 31 #include "lldb/Core/ValueObjectSyntheticFilter.h" 32 33 #include "lldb/DataFormatters/DataVisualization.h" 34 #include "lldb/DataFormatters/StringPrinter.h" 35 #include "lldb/DataFormatters/ValueObjectPrinter.h" 36 37 #include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h" 38 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" 39 40 #include "lldb/Host/Endian.h" 41 42 #include "lldb/Interpreter/CommandInterpreter.h" 43 44 #include "lldb/Symbol/CompilerType.h" 45 #include "lldb/Symbol/ClangASTContext.h" 46 #include "lldb/Symbol/CompileUnit.h" 47 #include "lldb/Symbol/Type.h" 48 49 #include "lldb/Target/ExecutionContext.h" 50 #include "lldb/Target/Language.h" 51 #include "lldb/Target/LanguageRuntime.h" 52 #include "lldb/Target/ObjCLanguageRuntime.h" 53 #include "lldb/Target/Process.h" 54 #include "lldb/Target/RegisterContext.h" 55 #include "lldb/Target/SectionLoadList.h" 56 #include "lldb/Target/Target.h" 57 #include "lldb/Target/Thread.h" 58 59 using namespace lldb; 60 using namespace lldb_private; 61 using namespace lldb_utility; 62 63 static user_id_t g_value_obj_uid = 0; 64 65 //---------------------------------------------------------------------- 66 // ValueObject constructor 67 //---------------------------------------------------------------------- 68 ValueObject::ValueObject (ValueObject &parent) : 69 UserID (++g_value_obj_uid), // Unique identifier for every value object 70 m_parent (&parent), 71 m_root (NULL), 72 m_update_point (parent.GetUpdatePoint ()), 73 m_name (), 74 m_data (), 75 m_value (), 76 m_error (), 77 m_value_str (), 78 m_old_value_str (), 79 m_location_str (), 80 m_summary_str (), 81 m_object_desc_str (), 82 m_validation_result(), 83 m_manager(parent.GetManager()), 84 m_children (), 85 m_synthetic_children (), 86 m_dynamic_value (NULL), 87 m_synthetic_value(NULL), 88 m_deref_valobj(NULL), 89 m_format (eFormatDefault), 90 m_last_format (eFormatDefault), 91 m_last_format_mgr_revision(0), 92 m_type_summary_sp(), 93 m_type_format_sp(), 94 m_synthetic_children_sp(), 95 m_type_validator_sp(), 96 m_user_id_of_forced_summary(), 97 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid), 98 m_value_checksum(), 99 m_preferred_display_language(lldb::eLanguageTypeUnknown), 100 m_value_is_valid (false), 101 m_value_did_change (false), 102 m_children_count_valid (false), 103 m_old_value_valid (false), 104 m_is_deref_of_parent (false), 105 m_is_array_item_for_pointer(false), 106 m_is_bitfield_for_scalar(false), 107 m_is_child_at_offset(false), 108 m_is_getting_summary(false), 109 m_did_calculate_complete_objc_class_type(false), 110 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated) 111 { 112 m_manager->ManageObject(this); 113 } 114 115 //---------------------------------------------------------------------- 116 // ValueObject constructor 117 //---------------------------------------------------------------------- 118 ValueObject::ValueObject (ExecutionContextScope *exe_scope, 119 AddressType child_ptr_or_ref_addr_type) : 120 UserID (++g_value_obj_uid), // Unique identifier for every value object 121 m_parent (NULL), 122 m_root (NULL), 123 m_update_point (exe_scope), 124 m_name (), 125 m_data (), 126 m_value (), 127 m_error (), 128 m_value_str (), 129 m_old_value_str (), 130 m_location_str (), 131 m_summary_str (), 132 m_object_desc_str (), 133 m_validation_result(), 134 m_manager(), 135 m_children (), 136 m_synthetic_children (), 137 m_dynamic_value (NULL), 138 m_synthetic_value(NULL), 139 m_deref_valobj(NULL), 140 m_format (eFormatDefault), 141 m_last_format (eFormatDefault), 142 m_last_format_mgr_revision(0), 143 m_type_summary_sp(), 144 m_type_format_sp(), 145 m_synthetic_children_sp(), 146 m_type_validator_sp(), 147 m_user_id_of_forced_summary(), 148 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type), 149 m_value_checksum(), 150 m_preferred_display_language(lldb::eLanguageTypeUnknown), 151 m_value_is_valid (false), 152 m_value_did_change (false), 153 m_children_count_valid (false), 154 m_old_value_valid (false), 155 m_is_deref_of_parent (false), 156 m_is_array_item_for_pointer(false), 157 m_is_bitfield_for_scalar(false), 158 m_is_child_at_offset(false), 159 m_is_getting_summary(false), 160 m_did_calculate_complete_objc_class_type(false), 161 m_is_synthetic_children_generated(false) 162 { 163 m_manager = new ValueObjectManager(); 164 m_manager->ManageObject (this); 165 } 166 167 //---------------------------------------------------------------------- 168 // Destructor 169 //---------------------------------------------------------------------- 170 ValueObject::~ValueObject () 171 { 172 } 173 174 bool 175 ValueObject::UpdateValueIfNeeded (bool update_format) 176 { 177 178 bool did_change_formats = false; 179 180 if (update_format) 181 did_change_formats = UpdateFormatsIfNeeded(); 182 183 // If this is a constant value, then our success is predicated on whether 184 // we have an error or not 185 if (GetIsConstant()) 186 { 187 // if you are constant, things might still have changed behind your back 188 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself) 189 // in this case, your value has not changed, but "computed" entries might have, so you might now have 190 // a different summary, or a different object description. clear these so we will recompute them 191 if (update_format && !did_change_formats) 192 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription); 193 return m_error.Success(); 194 } 195 196 bool first_update = IsChecksumEmpty(); 197 198 if (NeedsUpdating()) 199 { 200 m_update_point.SetUpdated(); 201 202 // Save the old value using swap to avoid a string copy which 203 // also will clear our m_value_str 204 if (m_value_str.empty()) 205 { 206 m_old_value_valid = false; 207 } 208 else 209 { 210 m_old_value_valid = true; 211 m_old_value_str.swap (m_value_str); 212 ClearUserVisibleData(eClearUserVisibleDataItemsValue); 213 } 214 215 ClearUserVisibleData(); 216 217 if (IsInScope()) 218 { 219 const bool value_was_valid = GetValueIsValid(); 220 SetValueDidChange (false); 221 222 m_error.Clear(); 223 224 // Call the pure virtual function to update the value 225 226 bool need_compare_checksums = false; 227 llvm::SmallVector<uint8_t, 16> old_checksum; 228 229 if (!first_update && CanProvideValue()) 230 { 231 need_compare_checksums = true; 232 old_checksum.resize(m_value_checksum.size()); 233 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin()); 234 } 235 236 bool success = UpdateValue (); 237 238 SetValueIsValid (success); 239 240 if (success) 241 { 242 const uint64_t max_checksum_size = 128; 243 m_data.Checksum(m_value_checksum, 244 max_checksum_size); 245 } 246 else 247 { 248 need_compare_checksums = false; 249 m_value_checksum.clear(); 250 } 251 252 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty())); 253 254 if (first_update) 255 SetValueDidChange (false); 256 else if (!m_value_did_change && success == false) 257 { 258 // The value wasn't gotten successfully, so we mark this 259 // as changed if the value used to be valid and now isn't 260 SetValueDidChange (value_was_valid); 261 } 262 else if (need_compare_checksums) 263 { 264 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size())); 265 } 266 267 } 268 else 269 { 270 m_error.SetErrorString("out of scope"); 271 } 272 } 273 return m_error.Success(); 274 } 275 276 bool 277 ValueObject::UpdateFormatsIfNeeded() 278 { 279 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); 280 if (log) 281 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d", 282 GetName().GetCString(), static_cast<void*>(this), 283 m_last_format_mgr_revision, 284 DataVisualization::GetCurrentRevision()); 285 286 bool any_change = false; 287 288 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision())) 289 { 290 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision(); 291 any_change = true; 292 293 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues)); 294 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType())); 295 #ifndef LLDB_DISABLE_PYTHON 296 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType())); 297 #endif 298 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType())); 299 } 300 301 return any_change; 302 } 303 304 void 305 ValueObject::SetNeedsUpdate () 306 { 307 m_update_point.SetNeedsUpdate(); 308 // We have to clear the value string here so ConstResult children will notice if their values are 309 // changed by hand (i.e. with SetValueAsCString). 310 ClearUserVisibleData(eClearUserVisibleDataItemsValue); 311 } 312 313 void 314 ValueObject::ClearDynamicTypeInformation () 315 { 316 m_children_count_valid = false; 317 m_did_calculate_complete_objc_class_type = false; 318 m_last_format_mgr_revision = 0; 319 m_override_type = CompilerType(); 320 SetValueFormat(lldb::TypeFormatImplSP()); 321 SetSummaryFormat(lldb::TypeSummaryImplSP()); 322 SetSyntheticChildren(lldb::SyntheticChildrenSP()); 323 } 324 325 CompilerType 326 ValueObject::MaybeCalculateCompleteType () 327 { 328 CompilerType compiler_type(GetCompilerTypeImpl()); 329 330 if (m_did_calculate_complete_objc_class_type) 331 { 332 if (m_override_type.IsValid()) 333 return m_override_type; 334 else 335 return compiler_type; 336 } 337 338 CompilerType class_type; 339 bool is_pointer_type = false; 340 341 if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type)) 342 { 343 is_pointer_type = true; 344 } 345 else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type)) 346 { 347 class_type = compiler_type; 348 } 349 else 350 { 351 return compiler_type; 352 } 353 354 m_did_calculate_complete_objc_class_type = true; 355 356 if (class_type) 357 { 358 ConstString class_name (class_type.GetConstTypeName()); 359 360 if (class_name) 361 { 362 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP()); 363 364 if (process_sp) 365 { 366 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime()); 367 368 if (objc_language_runtime) 369 { 370 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name); 371 372 if (complete_objc_class_type_sp) 373 { 374 CompilerType complete_class(complete_objc_class_type_sp->GetFullCompilerType ()); 375 376 if (complete_class.GetCompleteType()) 377 { 378 if (is_pointer_type) 379 { 380 m_override_type = complete_class.GetPointerType(); 381 } 382 else 383 { 384 m_override_type = complete_class; 385 } 386 387 if (m_override_type.IsValid()) 388 return m_override_type; 389 } 390 } 391 } 392 } 393 } 394 } 395 return compiler_type; 396 } 397 398 CompilerType 399 ValueObject::GetCompilerType () 400 { 401 return MaybeCalculateCompleteType(); 402 } 403 404 TypeImpl 405 ValueObject::GetTypeImpl () 406 { 407 return TypeImpl(GetCompilerType()); 408 } 409 410 DataExtractor & 411 ValueObject::GetDataExtractor () 412 { 413 UpdateValueIfNeeded(false); 414 return m_data; 415 } 416 417 const Error & 418 ValueObject::GetError() 419 { 420 UpdateValueIfNeeded(false); 421 return m_error; 422 } 423 424 const ConstString & 425 ValueObject::GetName() const 426 { 427 return m_name; 428 } 429 430 const char * 431 ValueObject::GetLocationAsCString () 432 { 433 return GetLocationAsCStringImpl(m_value, 434 m_data); 435 } 436 437 const char * 438 ValueObject::GetLocationAsCStringImpl (const Value& value, 439 const DataExtractor& data) 440 { 441 if (UpdateValueIfNeeded(false)) 442 { 443 if (m_location_str.empty()) 444 { 445 StreamString sstr; 446 447 Value::ValueType value_type = value.GetValueType(); 448 449 switch (value_type) 450 { 451 case Value::eValueTypeScalar: 452 case Value::eValueTypeVector: 453 if (value.GetContextType() == Value::eContextTypeRegisterInfo) 454 { 455 RegisterInfo *reg_info = value.GetRegisterInfo(); 456 if (reg_info) 457 { 458 if (reg_info->name) 459 m_location_str = reg_info->name; 460 else if (reg_info->alt_name) 461 m_location_str = reg_info->alt_name; 462 if (m_location_str.empty()) 463 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar"; 464 } 465 } 466 if (m_location_str.empty()) 467 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar"; 468 break; 469 470 case Value::eValueTypeLoadAddress: 471 case Value::eValueTypeFileAddress: 472 case Value::eValueTypeHostAddress: 473 { 474 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2; 475 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS)); 476 m_location_str.swap(sstr.GetString()); 477 } 478 break; 479 } 480 } 481 } 482 return m_location_str.c_str(); 483 } 484 485 Value & 486 ValueObject::GetValue() 487 { 488 return m_value; 489 } 490 491 const Value & 492 ValueObject::GetValue() const 493 { 494 return m_value; 495 } 496 497 bool 498 ValueObject::ResolveValue (Scalar &scalar) 499 { 500 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything 501 { 502 ExecutionContext exe_ctx (GetExecutionContextRef()); 503 Value tmp_value(m_value); 504 scalar = tmp_value.ResolveValue(&exe_ctx); 505 if (scalar.IsValid()) 506 { 507 const uint32_t bitfield_bit_size = GetBitfieldBitSize(); 508 if (bitfield_bit_size) 509 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset()); 510 return true; 511 } 512 } 513 return false; 514 } 515 516 bool 517 ValueObject::IsLogicalTrue (Error& error) 518 { 519 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) 520 { 521 LazyBool is_logical_true = language->IsLogicalTrue(*this, error); 522 switch (is_logical_true) 523 { 524 case eLazyBoolYes: 525 case eLazyBoolNo: 526 return (is_logical_true == true); 527 case eLazyBoolCalculate: 528 default: 529 break; 530 } 531 } 532 533 Scalar scalar_value; 534 535 if (!ResolveValue (scalar_value)) 536 { 537 error.SetErrorString("failed to get a scalar result"); 538 return false; 539 } 540 541 bool ret; 542 if (scalar_value.ULongLong(1) == 0) 543 ret = false; 544 else 545 ret = true; 546 error.Clear(); 547 return ret; 548 } 549 550 bool 551 ValueObject::GetValueIsValid () const 552 { 553 return m_value_is_valid; 554 } 555 556 557 void 558 ValueObject::SetValueIsValid (bool b) 559 { 560 m_value_is_valid = b; 561 } 562 563 bool 564 ValueObject::GetValueDidChange () 565 { 566 return m_value_did_change; 567 } 568 569 void 570 ValueObject::SetValueDidChange (bool value_changed) 571 { 572 m_value_did_change = value_changed; 573 } 574 575 ValueObjectSP 576 ValueObject::GetChildAtIndex (size_t idx, bool can_create) 577 { 578 ValueObjectSP child_sp; 579 // We may need to update our value if we are dynamic 580 if (IsPossibleDynamicType ()) 581 UpdateValueIfNeeded(false); 582 if (idx < GetNumChildren()) 583 { 584 // Check if we have already made the child value object? 585 if (can_create && !m_children.HasChildAtIndex(idx)) 586 { 587 // No we haven't created the child at this index, so lets have our 588 // subclass do it and cache the result for quick future access. 589 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0)); 590 } 591 592 ValueObject* child = m_children.GetChildAtIndex(idx); 593 if (child != NULL) 594 return child->GetSP(); 595 } 596 return child_sp; 597 } 598 599 ValueObjectSP 600 ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs, 601 size_t* index_of_error) 602 { 603 if (idxs.size() == 0) 604 return GetSP(); 605 ValueObjectSP root(GetSP()); 606 for (size_t idx : idxs) 607 { 608 root = root->GetChildAtIndex(idx, true); 609 if (!root) 610 { 611 if (index_of_error) 612 *index_of_error = idx; 613 return root; 614 } 615 } 616 return root; 617 } 618 619 ValueObjectSP 620 ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs, 621 size_t* index_of_error) 622 { 623 if (idxs.size() == 0) 624 return GetSP(); 625 ValueObjectSP root(GetSP()); 626 for (std::pair<size_t, bool> idx : idxs) 627 { 628 root = root->GetChildAtIndex(idx.first, idx.second); 629 if (!root) 630 { 631 if (index_of_error) 632 *index_of_error = idx.first; 633 return root; 634 } 635 } 636 return root; 637 } 638 639 lldb::ValueObjectSP 640 ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs, 641 size_t* index_of_error) 642 { 643 if (idxs.size() == 0) 644 return GetSP(); 645 ValueObjectSP root(GetSP()); 646 for (size_t idx : idxs) 647 { 648 root = root->GetChildAtIndex(idx, true); 649 if (!root) 650 { 651 if (index_of_error) 652 *index_of_error = idx; 653 return root; 654 } 655 } 656 return root; 657 } 658 659 lldb::ValueObjectSP 660 ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs, 661 size_t* index_of_error) 662 { 663 if (idxs.size() == 0) 664 return GetSP(); 665 ValueObjectSP root(GetSP()); 666 for (std::pair<size_t, bool> idx : idxs) 667 { 668 root = root->GetChildAtIndex(idx.first, idx.second); 669 if (!root) 670 { 671 if (index_of_error) 672 *index_of_error = idx.first; 673 return root; 674 } 675 } 676 return root; 677 } 678 679 lldb::ValueObjectSP 680 ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names, 681 ConstString* name_of_error) 682 { 683 if (names.size() == 0) 684 return GetSP(); 685 ValueObjectSP root(GetSP()); 686 for (ConstString name : names) 687 { 688 root = root->GetChildMemberWithName(name, true); 689 if (!root) 690 { 691 if (name_of_error) 692 *name_of_error = name; 693 return root; 694 } 695 } 696 return root; 697 } 698 699 lldb::ValueObjectSP 700 ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names, 701 ConstString* name_of_error) 702 { 703 if (names.size() == 0) 704 return GetSP(); 705 ValueObjectSP root(GetSP()); 706 for (ConstString name : names) 707 { 708 root = root->GetChildMemberWithName(name, true); 709 if (!root) 710 { 711 if (name_of_error) 712 *name_of_error = name; 713 return root; 714 } 715 } 716 return root; 717 } 718 719 lldb::ValueObjectSP 720 ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names, 721 ConstString* name_of_error) 722 { 723 if (names.size() == 0) 724 return GetSP(); 725 ValueObjectSP root(GetSP()); 726 for (std::pair<ConstString, bool> name : names) 727 { 728 root = root->GetChildMemberWithName(name.first, name.second); 729 if (!root) 730 { 731 if (name_of_error) 732 *name_of_error = name.first; 733 return root; 734 } 735 } 736 return root; 737 } 738 739 lldb::ValueObjectSP 740 ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names, 741 ConstString* name_of_error) 742 { 743 if (names.size() == 0) 744 return GetSP(); 745 ValueObjectSP root(GetSP()); 746 for (std::pair<ConstString, bool> name : names) 747 { 748 root = root->GetChildMemberWithName(name.first, name.second); 749 if (!root) 750 { 751 if (name_of_error) 752 *name_of_error = name.first; 753 return root; 754 } 755 } 756 return root; 757 } 758 759 size_t 760 ValueObject::GetIndexOfChildWithName (const ConstString &name) 761 { 762 bool omit_empty_base_classes = true; 763 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes); 764 } 765 766 ValueObjectSP 767 ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create) 768 { 769 // when getting a child by name, it could be buried inside some base 770 // classes (which really aren't part of the expression path), so we 771 // need a vector of indexes that can get us down to the correct child 772 ValueObjectSP child_sp; 773 774 // We may need to update our value if we are dynamic 775 if (IsPossibleDynamicType ()) 776 UpdateValueIfNeeded(false); 777 778 std::vector<uint32_t> child_indexes; 779 bool omit_empty_base_classes = true; 780 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(), 781 omit_empty_base_classes, 782 child_indexes); 783 if (num_child_indexes > 0) 784 { 785 std::vector<uint32_t>::const_iterator pos = child_indexes.begin (); 786 std::vector<uint32_t>::const_iterator end = child_indexes.end (); 787 788 child_sp = GetChildAtIndex(*pos, can_create); 789 for (++pos; pos != end; ++pos) 790 { 791 if (child_sp) 792 { 793 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create)); 794 child_sp = new_child_sp; 795 } 796 else 797 { 798 child_sp.reset(); 799 } 800 801 } 802 } 803 return child_sp; 804 } 805 806 807 size_t 808 ValueObject::GetNumChildren (uint32_t max) 809 { 810 UpdateValueIfNeeded(); 811 812 if (max < UINT32_MAX) 813 { 814 if (m_children_count_valid) 815 { 816 size_t children_count = m_children.GetChildrenCount(); 817 return children_count <= max ? children_count : max; 818 } 819 else 820 return CalculateNumChildren(max); 821 } 822 823 if (!m_children_count_valid) 824 { 825 SetNumChildren (CalculateNumChildren()); 826 } 827 return m_children.GetChildrenCount(); 828 } 829 830 bool 831 ValueObject::MightHaveChildren() 832 { 833 bool has_children = false; 834 const uint32_t type_info = GetTypeInfo(); 835 if (type_info) 836 { 837 if (type_info & (eTypeHasChildren | 838 eTypeIsPointer | 839 eTypeIsReference)) 840 has_children = true; 841 } 842 else 843 { 844 has_children = GetNumChildren () > 0; 845 } 846 return has_children; 847 } 848 849 // Should only be called by ValueObject::GetNumChildren() 850 void 851 ValueObject::SetNumChildren (size_t num_children) 852 { 853 m_children_count_valid = true; 854 m_children.SetChildrenCount(num_children); 855 } 856 857 void 858 ValueObject::SetName (const ConstString &name) 859 { 860 m_name = name; 861 } 862 863 ValueObject * 864 ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index) 865 { 866 ValueObject *valobj = NULL; 867 868 bool omit_empty_base_classes = true; 869 bool ignore_array_bounds = synthetic_array_member; 870 std::string child_name_str; 871 uint32_t child_byte_size = 0; 872 int32_t child_byte_offset = 0; 873 uint32_t child_bitfield_bit_size = 0; 874 uint32_t child_bitfield_bit_offset = 0; 875 bool child_is_base_class = false; 876 bool child_is_deref_of_parent = false; 877 878 const bool transparent_pointers = synthetic_array_member == false; 879 CompilerType child_compiler_type; 880 881 ExecutionContext exe_ctx (GetExecutionContextRef()); 882 883 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx, 884 idx, 885 transparent_pointers, 886 omit_empty_base_classes, 887 ignore_array_bounds, 888 child_name_str, 889 child_byte_size, 890 child_byte_offset, 891 child_bitfield_bit_size, 892 child_bitfield_bit_offset, 893 child_is_base_class, 894 child_is_deref_of_parent, 895 this); 896 if (child_compiler_type) 897 { 898 if (synthetic_index) 899 child_byte_offset += child_byte_size * synthetic_index; 900 901 ConstString child_name; 902 if (!child_name_str.empty()) 903 child_name.SetCString (child_name_str.c_str()); 904 905 valobj = new ValueObjectChild (*this, 906 child_compiler_type, 907 child_name, 908 child_byte_size, 909 child_byte_offset, 910 child_bitfield_bit_size, 911 child_bitfield_bit_offset, 912 child_is_base_class, 913 child_is_deref_of_parent, 914 eAddressTypeInvalid); 915 //if (valobj) 916 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid); 917 } 918 919 return valobj; 920 } 921 922 bool 923 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr, 924 std::string& destination, 925 lldb::LanguageType lang) 926 { 927 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang)); 928 } 929 930 bool 931 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr, 932 std::string& destination, 933 const TypeSummaryOptions& options) 934 { 935 destination.clear(); 936 937 // ideally we would like to bail out if passing NULL, but if we do so 938 // we end up not providing the summary for function pointers anymore 939 if (/*summary_ptr == NULL ||*/ m_is_getting_summary) 940 return false; 941 942 m_is_getting_summary = true; 943 944 TypeSummaryOptions actual_options(options); 945 946 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown) 947 actual_options.SetLanguage(GetPreferredDisplayLanguage()); 948 949 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other 950 // information that we might care to see in a crash log. might be useful in very specific situations though. 951 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s", 952 GetTypeName().GetCString(), 953 GetName().GetCString(), 954 summary_ptr->GetDescription().c_str());*/ 955 956 if (UpdateValueIfNeeded (false) && summary_ptr) 957 { 958 if (HasSyntheticValue()) 959 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#}) 960 summary_ptr->FormatObject(this, destination, actual_options); 961 } 962 m_is_getting_summary = false; 963 return !destination.empty(); 964 } 965 966 const char * 967 ValueObject::GetSummaryAsCString (lldb::LanguageType lang) 968 { 969 if (UpdateValueIfNeeded(true) && m_summary_str.empty()) 970 { 971 TypeSummaryOptions summary_options; 972 summary_options.SetLanguage(lang); 973 GetSummaryAsCString(GetSummaryFormat().get(), 974 m_summary_str, 975 summary_options); 976 } 977 if (m_summary_str.empty()) 978 return NULL; 979 return m_summary_str.c_str(); 980 } 981 982 bool 983 ValueObject::GetSummaryAsCString (std::string& destination, 984 const TypeSummaryOptions& options) 985 { 986 return GetSummaryAsCString(GetSummaryFormat().get(), 987 destination, 988 options); 989 } 990 991 bool 992 ValueObject::IsCStringContainer(bool check_pointer) 993 { 994 CompilerType pointee_or_element_compiler_type; 995 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type)); 996 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) && 997 pointee_or_element_compiler_type.IsCharType ()); 998 if (!is_char_arr_ptr) 999 return false; 1000 if (!check_pointer) 1001 return true; 1002 if (type_flags.Test(eTypeIsArray)) 1003 return true; 1004 addr_t cstr_address = LLDB_INVALID_ADDRESS; 1005 AddressType cstr_address_type = eAddressTypeInvalid; 1006 cstr_address = GetAddressOf (true, &cstr_address_type); 1007 return (cstr_address != LLDB_INVALID_ADDRESS); 1008 } 1009 1010 size_t 1011 ValueObject::GetPointeeData (DataExtractor& data, 1012 uint32_t item_idx, 1013 uint32_t item_count) 1014 { 1015 CompilerType pointee_or_element_compiler_type; 1016 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type); 1017 const bool is_pointer_type = type_info & eTypeIsPointer; 1018 const bool is_array_type = type_info & eTypeIsArray; 1019 if (!(is_pointer_type || is_array_type)) 1020 return 0; 1021 1022 if (item_count == 0) 1023 return 0; 1024 1025 ExecutionContext exe_ctx (GetExecutionContextRef()); 1026 1027 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); 1028 const uint64_t bytes = item_count * item_type_size; 1029 const uint64_t offset = item_idx * item_type_size; 1030 1031 if (item_idx == 0 && item_count == 1) // simply a deref 1032 { 1033 if (is_pointer_type) 1034 { 1035 Error error; 1036 ValueObjectSP pointee_sp = Dereference(error); 1037 if (error.Fail() || pointee_sp.get() == NULL) 1038 return 0; 1039 return pointee_sp->GetData(data, error); 1040 } 1041 else 1042 { 1043 ValueObjectSP child_sp = GetChildAtIndex(0, true); 1044 if (child_sp.get() == NULL) 1045 return 0; 1046 Error error; 1047 return child_sp->GetData(data, error); 1048 } 1049 return true; 1050 } 1051 else /* (items > 1) */ 1052 { 1053 Error error; 1054 lldb_private::DataBufferHeap* heap_buf_ptr = NULL; 1055 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap()); 1056 1057 AddressType addr_type; 1058 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type); 1059 1060 switch (addr_type) 1061 { 1062 case eAddressTypeFile: 1063 { 1064 ModuleSP module_sp (GetModule()); 1065 if (module_sp) 1066 { 1067 addr = addr + offset; 1068 Address so_addr; 1069 module_sp->ResolveFileAddress(addr, so_addr); 1070 ExecutionContext exe_ctx (GetExecutionContextRef()); 1071 Target* target = exe_ctx.GetTargetPtr(); 1072 if (target) 1073 { 1074 heap_buf_ptr->SetByteSize(bytes); 1075 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error); 1076 if (error.Success()) 1077 { 1078 data.SetData(data_sp); 1079 return bytes_read; 1080 } 1081 } 1082 } 1083 } 1084 break; 1085 case eAddressTypeLoad: 1086 { 1087 ExecutionContext exe_ctx (GetExecutionContextRef()); 1088 Process *process = exe_ctx.GetProcessPtr(); 1089 if (process) 1090 { 1091 heap_buf_ptr->SetByteSize(bytes); 1092 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error); 1093 if (error.Success() || bytes_read > 0) 1094 { 1095 data.SetData(data_sp); 1096 return bytes_read; 1097 } 1098 } 1099 } 1100 break; 1101 case eAddressTypeHost: 1102 { 1103 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()); 1104 if (max_bytes > offset) 1105 { 1106 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes); 1107 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1108 if (addr == 0 || addr == LLDB_INVALID_ADDRESS) 1109 break; 1110 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read); 1111 data.SetData(data_sp); 1112 return bytes_read; 1113 } 1114 } 1115 break; 1116 case eAddressTypeInvalid: 1117 break; 1118 } 1119 } 1120 return 0; 1121 } 1122 1123 uint64_t 1124 ValueObject::GetData (DataExtractor& data, Error &error) 1125 { 1126 UpdateValueIfNeeded(false); 1127 ExecutionContext exe_ctx (GetExecutionContextRef()); 1128 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); 1129 if (error.Fail()) 1130 { 1131 if (m_data.GetByteSize()) 1132 { 1133 data = m_data; 1134 return data.GetByteSize(); 1135 } 1136 else 1137 { 1138 return 0; 1139 } 1140 } 1141 data.SetAddressByteSize(m_data.GetAddressByteSize()); 1142 data.SetByteOrder(m_data.GetByteOrder()); 1143 return data.GetByteSize(); 1144 } 1145 1146 bool 1147 ValueObject::SetData (DataExtractor &data, Error &error) 1148 { 1149 error.Clear(); 1150 // Make sure our value is up to date first so that our location and location 1151 // type is valid. 1152 if (!UpdateValueIfNeeded(false)) 1153 { 1154 error.SetErrorString("unable to read value"); 1155 return false; 1156 } 1157 1158 uint64_t count = 0; 1159 const Encoding encoding = GetCompilerType().GetEncoding(count); 1160 1161 const size_t byte_size = GetByteSize(); 1162 1163 Value::ValueType value_type = m_value.GetValueType(); 1164 1165 switch (value_type) 1166 { 1167 case Value::eValueTypeScalar: 1168 { 1169 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size); 1170 1171 if (!set_error.Success()) 1172 { 1173 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString()); 1174 return false; 1175 } 1176 } 1177 break; 1178 case Value::eValueTypeLoadAddress: 1179 { 1180 // If it is a load address, then the scalar value is the storage location 1181 // of the data, and we have to shove this value down to that load location. 1182 ExecutionContext exe_ctx (GetExecutionContextRef()); 1183 Process *process = exe_ctx.GetProcessPtr(); 1184 if (process) 1185 { 1186 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1187 size_t bytes_written = process->WriteMemory(target_addr, 1188 data.GetDataStart(), 1189 byte_size, 1190 error); 1191 if (!error.Success()) 1192 return false; 1193 if (bytes_written != byte_size) 1194 { 1195 error.SetErrorString("unable to write value to memory"); 1196 return false; 1197 } 1198 } 1199 } 1200 break; 1201 case Value::eValueTypeHostAddress: 1202 { 1203 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data. 1204 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0)); 1205 m_data.SetData(buffer_sp, 0); 1206 data.CopyByteOrderedData (0, 1207 byte_size, 1208 const_cast<uint8_t *>(m_data.GetDataStart()), 1209 byte_size, 1210 m_data.GetByteOrder()); 1211 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); 1212 } 1213 break; 1214 case Value::eValueTypeFileAddress: 1215 case Value::eValueTypeVector: 1216 break; 1217 } 1218 1219 // If we have reached this point, then we have successfully changed the value. 1220 SetNeedsUpdate(); 1221 return true; 1222 } 1223 1224 // will compute strlen(str), but without consuming more than 1225 // maxlen bytes out of str (this serves the purpose of reading 1226 // chunks of a string without having to worry about 1227 // missing NULL terminators in the chunk) 1228 // of course, if strlen(str) > maxlen, the function will return 1229 // maxlen_value (which should be != maxlen, because that allows you 1230 // to know whether strlen(str) == maxlen or strlen(str) > maxlen) 1231 static uint32_t 1232 strlen_or_inf (const char* str, 1233 uint32_t maxlen, 1234 uint32_t maxlen_value) 1235 { 1236 uint32_t len = 0; 1237 if (str) 1238 { 1239 while(*str) 1240 { 1241 len++;str++; 1242 if (len >= maxlen) 1243 return maxlen_value; 1244 } 1245 } 1246 return len; 1247 } 1248 1249 static bool 1250 CopyStringDataToBufferSP(const StreamString& source, 1251 lldb::DataBufferSP& destination) 1252 { 1253 destination.reset(new DataBufferHeap(source.GetSize()+1,0)); 1254 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize()); 1255 return true; 1256 } 1257 1258 std::pair<size_t,bool> 1259 ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp, 1260 Error& error, 1261 uint32_t max_length, 1262 bool honor_array, 1263 Format item_format) 1264 { 1265 bool was_capped = false; 1266 StreamString s; 1267 ExecutionContext exe_ctx (GetExecutionContextRef()); 1268 Target* target = exe_ctx.GetTargetPtr(); 1269 1270 if (!target) 1271 { 1272 s << "<no target to read from>"; 1273 error.SetErrorString("no target to read from"); 1274 CopyStringDataToBufferSP(s, buffer_sp); 1275 return {0,was_capped}; 1276 } 1277 1278 if (max_length == 0) 1279 max_length = target->GetMaximumSizeOfStringSummary(); 1280 1281 size_t bytes_read = 0; 1282 size_t total_bytes_read = 0; 1283 1284 CompilerType compiler_type = GetCompilerType(); 1285 CompilerType elem_or_pointee_compiler_type; 1286 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type)); 1287 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) && 1288 elem_or_pointee_compiler_type.IsCharType ()) 1289 { 1290 addr_t cstr_address = LLDB_INVALID_ADDRESS; 1291 AddressType cstr_address_type = eAddressTypeInvalid; 1292 1293 size_t cstr_len = 0; 1294 bool capped_data = false; 1295 if (type_flags.Test (eTypeIsArray)) 1296 { 1297 // We have an array 1298 uint64_t array_size = 0; 1299 if (compiler_type.IsArrayType(NULL, &array_size, NULL)) 1300 { 1301 cstr_len = array_size; 1302 if (cstr_len > max_length) 1303 { 1304 capped_data = true; 1305 cstr_len = max_length; 1306 } 1307 } 1308 cstr_address = GetAddressOf (true, &cstr_address_type); 1309 } 1310 else 1311 { 1312 // We have a pointer 1313 cstr_address = GetPointerValue (&cstr_address_type); 1314 } 1315 1316 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS) 1317 { 1318 s << "<invalid address>"; 1319 error.SetErrorString("invalid address"); 1320 CopyStringDataToBufferSP(s, buffer_sp); 1321 return {0,was_capped}; 1322 } 1323 1324 Address cstr_so_addr (cstr_address); 1325 DataExtractor data; 1326 if (cstr_len > 0 && honor_array) 1327 { 1328 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host 1329 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this 1330 GetPointeeData(data, 0, cstr_len); 1331 1332 if ((bytes_read = data.GetByteSize()) > 0) 1333 { 1334 total_bytes_read = bytes_read; 1335 for (size_t offset = 0; offset < bytes_read; offset++) 1336 s.Printf("%c", *data.PeekData(offset, 1)); 1337 if (capped_data) 1338 was_capped = true; 1339 } 1340 } 1341 else 1342 { 1343 cstr_len = max_length; 1344 const size_t k_max_buf_size = 64; 1345 1346 size_t offset = 0; 1347 1348 int cstr_len_displayed = -1; 1349 bool capped_cstr = false; 1350 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host 1351 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this 1352 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) 1353 { 1354 total_bytes_read += bytes_read; 1355 const char *cstr = data.PeekCStr(0); 1356 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1); 1357 if (len > k_max_buf_size) 1358 len = k_max_buf_size; 1359 1360 if (cstr_len_displayed < 0) 1361 cstr_len_displayed = len; 1362 1363 if (len == 0) 1364 break; 1365 cstr_len_displayed += len; 1366 if (len > bytes_read) 1367 len = bytes_read; 1368 if (len > cstr_len) 1369 len = cstr_len; 1370 1371 for (size_t offset = 0; offset < bytes_read; offset++) 1372 s.Printf("%c", *data.PeekData(offset, 1)); 1373 1374 if (len < k_max_buf_size) 1375 break; 1376 1377 if (len >= cstr_len) 1378 { 1379 capped_cstr = true; 1380 break; 1381 } 1382 1383 cstr_len -= len; 1384 offset += len; 1385 } 1386 1387 if (cstr_len_displayed >= 0) 1388 { 1389 if (capped_cstr) 1390 was_capped = true; 1391 } 1392 } 1393 } 1394 else 1395 { 1396 error.SetErrorString("not a string object"); 1397 s << "<not a string object>"; 1398 } 1399 CopyStringDataToBufferSP(s, buffer_sp); 1400 return {total_bytes_read,was_capped}; 1401 } 1402 1403 std::pair<TypeValidatorResult, std::string> 1404 ValueObject::GetValidationStatus () 1405 { 1406 if (!UpdateValueIfNeeded(true)) 1407 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems 1408 1409 if (m_validation_result.hasValue()) 1410 return m_validation_result.getValue(); 1411 1412 if (!m_type_validator_sp) 1413 return {TypeValidatorResult::Success,""}; // no validator no failure 1414 1415 auto outcome = m_type_validator_sp->FormatObject(this); 1416 1417 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue(); 1418 } 1419 1420 const char * 1421 ValueObject::GetObjectDescription () 1422 { 1423 1424 if (!UpdateValueIfNeeded (true)) 1425 return NULL; 1426 1427 if (!m_object_desc_str.empty()) 1428 return m_object_desc_str.c_str(); 1429 1430 ExecutionContext exe_ctx (GetExecutionContextRef()); 1431 Process *process = exe_ctx.GetProcessPtr(); 1432 if (process == NULL) 1433 return NULL; 1434 1435 StreamString s; 1436 1437 LanguageType language = GetObjectRuntimeLanguage(); 1438 LanguageRuntime *runtime = process->GetLanguageRuntime(language); 1439 1440 if (runtime == NULL) 1441 { 1442 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway... 1443 CompilerType compiler_type = GetCompilerType(); 1444 if (compiler_type) 1445 { 1446 bool is_signed; 1447 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ()) 1448 { 1449 runtime = process->GetLanguageRuntime(eLanguageTypeObjC); 1450 } 1451 } 1452 } 1453 1454 if (runtime && runtime->GetObjectDescription(s, *this)) 1455 { 1456 m_object_desc_str.append (s.GetData()); 1457 } 1458 1459 if (m_object_desc_str.empty()) 1460 return NULL; 1461 else 1462 return m_object_desc_str.c_str(); 1463 } 1464 1465 bool 1466 ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format, 1467 std::string& destination) 1468 { 1469 if (UpdateValueIfNeeded(false)) 1470 return format.FormatObject(this,destination); 1471 else 1472 return false; 1473 } 1474 1475 bool 1476 ValueObject::GetValueAsCString (lldb::Format format, 1477 std::string& destination) 1478 { 1479 return GetValueAsCString(TypeFormatImpl_Format(format),destination); 1480 } 1481 1482 const char * 1483 ValueObject::GetValueAsCString () 1484 { 1485 if (UpdateValueIfNeeded(true)) 1486 { 1487 lldb::TypeFormatImplSP format_sp; 1488 lldb::Format my_format = GetFormat(); 1489 if (my_format == lldb::eFormatDefault) 1490 { 1491 if (m_type_format_sp) 1492 format_sp = m_type_format_sp; 1493 else 1494 { 1495 if (m_is_bitfield_for_scalar) 1496 my_format = eFormatUnsigned; 1497 else 1498 { 1499 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo) 1500 { 1501 const RegisterInfo *reg_info = m_value.GetRegisterInfo(); 1502 if (reg_info) 1503 my_format = reg_info->format; 1504 } 1505 else 1506 { 1507 my_format = GetValue().GetCompilerType().GetFormat(); 1508 } 1509 } 1510 } 1511 } 1512 if (my_format != m_last_format || m_value_str.empty()) 1513 { 1514 m_last_format = my_format; 1515 if (!format_sp) 1516 format_sp.reset(new TypeFormatImpl_Format(my_format)); 1517 if (GetValueAsCString(*format_sp.get(), m_value_str)) 1518 { 1519 if (!m_value_did_change && m_old_value_valid) 1520 { 1521 // The value was gotten successfully, so we consider the 1522 // value as changed if the value string differs 1523 SetValueDidChange (m_old_value_str != m_value_str); 1524 } 1525 } 1526 } 1527 } 1528 if (m_value_str.empty()) 1529 return NULL; 1530 return m_value_str.c_str(); 1531 } 1532 1533 // if > 8bytes, 0 is returned. this method should mostly be used 1534 // to read address values out of pointers 1535 uint64_t 1536 ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success) 1537 { 1538 // If our byte size is zero this is an aggregate type that has children 1539 if (CanProvideValue()) 1540 { 1541 Scalar scalar; 1542 if (ResolveValue (scalar)) 1543 { 1544 if (success) 1545 *success = true; 1546 return scalar.ULongLong(fail_value); 1547 } 1548 // fallthrough, otherwise... 1549 } 1550 1551 if (success) 1552 *success = false; 1553 return fail_value; 1554 } 1555 1556 int64_t 1557 ValueObject::GetValueAsSigned (int64_t fail_value, bool *success) 1558 { 1559 // If our byte size is zero this is an aggregate type that has children 1560 if (CanProvideValue()) 1561 { 1562 Scalar scalar; 1563 if (ResolveValue (scalar)) 1564 { 1565 if (success) 1566 *success = true; 1567 return scalar.SLongLong(fail_value); 1568 } 1569 // fallthrough, otherwise... 1570 } 1571 1572 if (success) 1573 *success = false; 1574 return fail_value; 1575 } 1576 1577 // if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep 1578 // this call up to date by returning true for your new special cases. We will eventually move 1579 // to checking this call result before trying to display special cases 1580 bool 1581 ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, 1582 Format custom_format) 1583 { 1584 Flags flags(GetTypeInfo()); 1585 if (flags.AnySet(eTypeIsArray | eTypeIsPointer) 1586 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) 1587 { 1588 if (IsCStringContainer(true) && 1589 (custom_format == eFormatCString || 1590 custom_format == eFormatCharArray || 1591 custom_format == eFormatChar || 1592 custom_format == eFormatVectorOfChar)) 1593 return true; 1594 1595 if (flags.Test(eTypeIsArray)) 1596 { 1597 if ((custom_format == eFormatBytes) || 1598 (custom_format == eFormatBytesWithASCII)) 1599 return true; 1600 1601 if ((custom_format == eFormatVectorOfChar) || 1602 (custom_format == eFormatVectorOfFloat32) || 1603 (custom_format == eFormatVectorOfFloat64) || 1604 (custom_format == eFormatVectorOfSInt16) || 1605 (custom_format == eFormatVectorOfSInt32) || 1606 (custom_format == eFormatVectorOfSInt64) || 1607 (custom_format == eFormatVectorOfSInt8) || 1608 (custom_format == eFormatVectorOfUInt128) || 1609 (custom_format == eFormatVectorOfUInt16) || 1610 (custom_format == eFormatVectorOfUInt32) || 1611 (custom_format == eFormatVectorOfUInt64) || 1612 (custom_format == eFormatVectorOfUInt8)) 1613 return true; 1614 } 1615 } 1616 return false; 1617 } 1618 1619 bool 1620 ValueObject::DumpPrintableRepresentation(Stream& s, 1621 ValueObjectRepresentationStyle val_obj_display, 1622 Format custom_format, 1623 PrintableRepresentationSpecialCases special, 1624 bool do_dump_error) 1625 { 1626 1627 Flags flags(GetTypeInfo()); 1628 1629 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow); 1630 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly); 1631 1632 if (allow_special) 1633 { 1634 if (flags.AnySet(eTypeIsArray | eTypeIsPointer) 1635 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) 1636 { 1637 // when being asked to get a printable display an array or pointer type directly, 1638 // try to "do the right thing" 1639 1640 if (IsCStringContainer(true) && 1641 (custom_format == eFormatCString || 1642 custom_format == eFormatCharArray || 1643 custom_format == eFormatChar || 1644 custom_format == eFormatVectorOfChar)) // print char[] & char* directly 1645 { 1646 Error error; 1647 lldb::DataBufferSP buffer_sp; 1648 std::pair<size_t, bool> read_string = ReadPointedString(buffer_sp, 1649 error, 1650 0, 1651 (custom_format == eFormatVectorOfChar) || 1652 (custom_format == eFormatCharArray)); 1653 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this); 1654 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults 1655 options.SetStream(&s); 1656 options.SetPrefixToken(0); 1657 options.SetQuote('"'); 1658 options.SetSourceSize(buffer_sp->GetByteSize()); 1659 options.SetIsTruncated(read_string.second); 1660 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options); 1661 return !error.Fail(); 1662 } 1663 1664 if (custom_format == eFormatEnum) 1665 return false; 1666 1667 // this only works for arrays, because I have no way to know when 1668 // the pointed memory ends, and no special \0 end of data marker 1669 if (flags.Test(eTypeIsArray)) 1670 { 1671 if ((custom_format == eFormatBytes) || 1672 (custom_format == eFormatBytesWithASCII)) 1673 { 1674 const size_t count = GetNumChildren(); 1675 1676 s << '['; 1677 for (size_t low = 0; low < count; low++) 1678 { 1679 1680 if (low) 1681 s << ','; 1682 1683 ValueObjectSP child = GetChildAtIndex(low,true); 1684 if (!child.get()) 1685 { 1686 s << "<invalid child>"; 1687 continue; 1688 } 1689 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format); 1690 } 1691 1692 s << ']'; 1693 1694 return true; 1695 } 1696 1697 if ((custom_format == eFormatVectorOfChar) || 1698 (custom_format == eFormatVectorOfFloat32) || 1699 (custom_format == eFormatVectorOfFloat64) || 1700 (custom_format == eFormatVectorOfSInt16) || 1701 (custom_format == eFormatVectorOfSInt32) || 1702 (custom_format == eFormatVectorOfSInt64) || 1703 (custom_format == eFormatVectorOfSInt8) || 1704 (custom_format == eFormatVectorOfUInt128) || 1705 (custom_format == eFormatVectorOfUInt16) || 1706 (custom_format == eFormatVectorOfUInt32) || 1707 (custom_format == eFormatVectorOfUInt64) || 1708 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly 1709 { 1710 const size_t count = GetNumChildren(); 1711 1712 Format format = FormatManager::GetSingleItemFormat(custom_format); 1713 1714 s << '['; 1715 for (size_t low = 0; low < count; low++) 1716 { 1717 1718 if (low) 1719 s << ','; 1720 1721 ValueObjectSP child = GetChildAtIndex(low,true); 1722 if (!child.get()) 1723 { 1724 s << "<invalid child>"; 1725 continue; 1726 } 1727 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format); 1728 } 1729 1730 s << ']'; 1731 1732 return true; 1733 } 1734 } 1735 1736 if ((custom_format == eFormatBoolean) || 1737 (custom_format == eFormatBinary) || 1738 (custom_format == eFormatChar) || 1739 (custom_format == eFormatCharPrintable) || 1740 (custom_format == eFormatComplexFloat) || 1741 (custom_format == eFormatDecimal) || 1742 (custom_format == eFormatHex) || 1743 (custom_format == eFormatHexUppercase) || 1744 (custom_format == eFormatFloat) || 1745 (custom_format == eFormatOctal) || 1746 (custom_format == eFormatOSType) || 1747 (custom_format == eFormatUnicode16) || 1748 (custom_format == eFormatUnicode32) || 1749 (custom_format == eFormatUnsigned) || 1750 (custom_format == eFormatPointer) || 1751 (custom_format == eFormatComplexInteger) || 1752 (custom_format == eFormatComplex) || 1753 (custom_format == eFormatDefault)) // use the [] operator 1754 return false; 1755 } 1756 } 1757 1758 if (only_special) 1759 return false; 1760 1761 bool var_success = false; 1762 1763 { 1764 const char *cstr = NULL; 1765 1766 // this is a local stream that we are using to ensure that the data pointed to by cstr survives 1767 // long enough for us to copy it to its destination - it is necessary to have this temporary storage 1768 // area for cases where our desired output is not backed by some other longer-term storage 1769 StreamString strm; 1770 1771 if (custom_format != eFormatInvalid) 1772 SetFormat(custom_format); 1773 1774 switch(val_obj_display) 1775 { 1776 case eValueObjectRepresentationStyleValue: 1777 cstr = GetValueAsCString(); 1778 break; 1779 1780 case eValueObjectRepresentationStyleSummary: 1781 cstr = GetSummaryAsCString(); 1782 break; 1783 1784 case eValueObjectRepresentationStyleLanguageSpecific: 1785 cstr = GetObjectDescription(); 1786 break; 1787 1788 case eValueObjectRepresentationStyleLocation: 1789 cstr = GetLocationAsCString(); 1790 break; 1791 1792 case eValueObjectRepresentationStyleChildrenCount: 1793 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren()); 1794 cstr = strm.GetString().c_str(); 1795 break; 1796 1797 case eValueObjectRepresentationStyleType: 1798 cstr = GetTypeName().AsCString(); 1799 break; 1800 1801 case eValueObjectRepresentationStyleName: 1802 cstr = GetName().AsCString(); 1803 break; 1804 1805 case eValueObjectRepresentationStyleExpressionPath: 1806 GetExpressionPath(strm, false); 1807 cstr = strm.GetString().c_str(); 1808 break; 1809 } 1810 1811 if (!cstr) 1812 { 1813 if (val_obj_display == eValueObjectRepresentationStyleValue) 1814 cstr = GetSummaryAsCString(); 1815 else if (val_obj_display == eValueObjectRepresentationStyleSummary) 1816 { 1817 if (!CanProvideValue()) 1818 { 1819 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString()); 1820 cstr = strm.GetString().c_str(); 1821 } 1822 else 1823 cstr = GetValueAsCString(); 1824 } 1825 } 1826 1827 if (cstr) 1828 s.PutCString(cstr); 1829 else 1830 { 1831 if (m_error.Fail()) 1832 { 1833 if (do_dump_error) 1834 s.Printf("<%s>", m_error.AsCString()); 1835 else 1836 return false; 1837 } 1838 else if (val_obj_display == eValueObjectRepresentationStyleSummary) 1839 s.PutCString("<no summary available>"); 1840 else if (val_obj_display == eValueObjectRepresentationStyleValue) 1841 s.PutCString("<no value available>"); 1842 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific) 1843 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description 1844 else 1845 s.PutCString("<no printable representation>"); 1846 } 1847 1848 // we should only return false here if we could not do *anything* 1849 // even if we have an error message as output, that's a success 1850 // from our callers' perspective, so return true 1851 var_success = true; 1852 1853 if (custom_format != eFormatInvalid) 1854 SetFormat(eFormatDefault); 1855 } 1856 1857 return var_success; 1858 } 1859 1860 addr_t 1861 ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type) 1862 { 1863 if (!UpdateValueIfNeeded(false)) 1864 return LLDB_INVALID_ADDRESS; 1865 1866 switch (m_value.GetValueType()) 1867 { 1868 case Value::eValueTypeScalar: 1869 case Value::eValueTypeVector: 1870 if (scalar_is_load_address) 1871 { 1872 if(address_type) 1873 *address_type = eAddressTypeLoad; 1874 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1875 } 1876 break; 1877 1878 case Value::eValueTypeLoadAddress: 1879 case Value::eValueTypeFileAddress: 1880 { 1881 if(address_type) 1882 *address_type = m_value.GetValueAddressType (); 1883 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1884 } 1885 break; 1886 case Value::eValueTypeHostAddress: 1887 { 1888 if(address_type) 1889 *address_type = m_value.GetValueAddressType (); 1890 return LLDB_INVALID_ADDRESS; 1891 } 1892 break; 1893 } 1894 if (address_type) 1895 *address_type = eAddressTypeInvalid; 1896 return LLDB_INVALID_ADDRESS; 1897 } 1898 1899 addr_t 1900 ValueObject::GetPointerValue (AddressType *address_type) 1901 { 1902 addr_t address = LLDB_INVALID_ADDRESS; 1903 if(address_type) 1904 *address_type = eAddressTypeInvalid; 1905 1906 if (!UpdateValueIfNeeded(false)) 1907 return address; 1908 1909 switch (m_value.GetValueType()) 1910 { 1911 case Value::eValueTypeScalar: 1912 case Value::eValueTypeVector: 1913 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1914 break; 1915 1916 case Value::eValueTypeHostAddress: 1917 case Value::eValueTypeLoadAddress: 1918 case Value::eValueTypeFileAddress: 1919 { 1920 lldb::offset_t data_offset = 0; 1921 address = m_data.GetPointer(&data_offset); 1922 } 1923 break; 1924 } 1925 1926 if (address_type) 1927 *address_type = GetAddressTypeOfChildren(); 1928 1929 return address; 1930 } 1931 1932 bool 1933 ValueObject::SetValueFromCString (const char *value_str, Error& error) 1934 { 1935 error.Clear(); 1936 // Make sure our value is up to date first so that our location and location 1937 // type is valid. 1938 if (!UpdateValueIfNeeded(false)) 1939 { 1940 error.SetErrorString("unable to read value"); 1941 return false; 1942 } 1943 1944 uint64_t count = 0; 1945 const Encoding encoding = GetCompilerType().GetEncoding (count); 1946 1947 const size_t byte_size = GetByteSize(); 1948 1949 Value::ValueType value_type = m_value.GetValueType(); 1950 1951 if (value_type == Value::eValueTypeScalar) 1952 { 1953 // If the value is already a scalar, then let the scalar change itself: 1954 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size); 1955 } 1956 else if (byte_size <= 16) 1957 { 1958 // If the value fits in a scalar, then make a new scalar and again let the 1959 // scalar code do the conversion, then figure out where to put the new value. 1960 Scalar new_scalar; 1961 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size); 1962 if (error.Success()) 1963 { 1964 switch (value_type) 1965 { 1966 case Value::eValueTypeLoadAddress: 1967 { 1968 // If it is a load address, then the scalar value is the storage location 1969 // of the data, and we have to shove this value down to that load location. 1970 ExecutionContext exe_ctx (GetExecutionContextRef()); 1971 Process *process = exe_ctx.GetProcessPtr(); 1972 if (process) 1973 { 1974 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1975 size_t bytes_written = process->WriteScalarToMemory (target_addr, 1976 new_scalar, 1977 byte_size, 1978 error); 1979 if (!error.Success()) 1980 return false; 1981 if (bytes_written != byte_size) 1982 { 1983 error.SetErrorString("unable to write value to memory"); 1984 return false; 1985 } 1986 } 1987 } 1988 break; 1989 case Value::eValueTypeHostAddress: 1990 { 1991 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data. 1992 DataExtractor new_data; 1993 new_data.SetByteOrder (m_data.GetByteOrder()); 1994 1995 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0)); 1996 m_data.SetData(buffer_sp, 0); 1997 bool success = new_scalar.GetData(new_data); 1998 if (success) 1999 { 2000 new_data.CopyByteOrderedData (0, 2001 byte_size, 2002 const_cast<uint8_t *>(m_data.GetDataStart()), 2003 byte_size, 2004 m_data.GetByteOrder()); 2005 } 2006 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); 2007 2008 } 2009 break; 2010 case Value::eValueTypeFileAddress: 2011 case Value::eValueTypeScalar: 2012 case Value::eValueTypeVector: 2013 break; 2014 } 2015 } 2016 else 2017 { 2018 return false; 2019 } 2020 } 2021 else 2022 { 2023 // We don't support setting things bigger than a scalar at present. 2024 error.SetErrorString("unable to write aggregate data type"); 2025 return false; 2026 } 2027 2028 // If we have reached this point, then we have successfully changed the value. 2029 SetNeedsUpdate(); 2030 return true; 2031 } 2032 2033 bool 2034 ValueObject::GetDeclaration (Declaration &decl) 2035 { 2036 decl.Clear(); 2037 return false; 2038 } 2039 2040 ConstString 2041 ValueObject::GetTypeName() 2042 { 2043 return GetCompilerType().GetConstTypeName(); 2044 } 2045 2046 ConstString 2047 ValueObject::GetDisplayTypeName() 2048 { 2049 return GetTypeName(); 2050 } 2051 2052 ConstString 2053 ValueObject::GetQualifiedTypeName() 2054 { 2055 return GetCompilerType().GetConstQualifiedTypeName(); 2056 } 2057 2058 2059 LanguageType 2060 ValueObject::GetObjectRuntimeLanguage () 2061 { 2062 return GetCompilerType().GetMinimumLanguage (); 2063 } 2064 2065 void 2066 ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj) 2067 { 2068 m_synthetic_children[key] = valobj; 2069 } 2070 2071 ValueObjectSP 2072 ValueObject::GetSyntheticChild (const ConstString &key) const 2073 { 2074 ValueObjectSP synthetic_child_sp; 2075 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key); 2076 if (pos != m_synthetic_children.end()) 2077 synthetic_child_sp = pos->second->GetSP(); 2078 return synthetic_child_sp; 2079 } 2080 2081 uint32_t 2082 ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type) 2083 { 2084 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type); 2085 } 2086 2087 bool 2088 ValueObject::IsPointerType () 2089 { 2090 return GetCompilerType().IsPointerType(); 2091 } 2092 2093 bool 2094 ValueObject::IsArrayType () 2095 { 2096 return GetCompilerType().IsArrayType (NULL, NULL, NULL); 2097 } 2098 2099 bool 2100 ValueObject::IsScalarType () 2101 { 2102 return GetCompilerType().IsScalarType (); 2103 } 2104 2105 bool 2106 ValueObject::IsIntegerType (bool &is_signed) 2107 { 2108 return GetCompilerType().IsIntegerType (is_signed); 2109 } 2110 2111 bool 2112 ValueObject::IsPointerOrReferenceType () 2113 { 2114 return GetCompilerType().IsPointerOrReferenceType (); 2115 } 2116 2117 bool 2118 ValueObject::IsPossibleDynamicType () 2119 { 2120 ExecutionContext exe_ctx (GetExecutionContextRef()); 2121 Process *process = exe_ctx.GetProcessPtr(); 2122 if (process) 2123 return process->IsPossibleDynamicValue(*this); 2124 else 2125 return GetCompilerType().IsPossibleDynamicType (NULL, true, true); 2126 } 2127 2128 bool 2129 ValueObject::IsRuntimeSupportValue () 2130 { 2131 Process *process(GetProcessSP().get()); 2132 if (process) 2133 { 2134 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage()); 2135 if (!runtime) 2136 runtime = process->GetObjCLanguageRuntime(); 2137 if (runtime) 2138 return runtime->IsRuntimeSupportValue(*this); 2139 } 2140 return false; 2141 } 2142 2143 bool 2144 ValueObject::IsObjCNil () 2145 { 2146 const uint32_t mask = eTypeIsObjC | eTypeIsPointer; 2147 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask); 2148 if (!isObjCpointer) 2149 return false; 2150 bool canReadValue = true; 2151 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0; 2152 return canReadValue && isZero; 2153 } 2154 2155 // This allows you to create an array member using and index 2156 // that doesn't not fall in the normal bounds of the array. 2157 // Many times structure can be defined as: 2158 // struct Collection 2159 // { 2160 // uint32_t item_count; 2161 // Item item_array[0]; 2162 // }; 2163 // The size of the "item_array" is 1, but many times in practice 2164 // there are more items in "item_array". 2165 2166 ValueObjectSP 2167 ValueObject::GetSyntheticArrayMember (size_t index, bool can_create) 2168 { 2169 ValueObjectSP synthetic_child_sp; 2170 if (IsPointerType () || IsArrayType()) 2171 { 2172 char index_str[64]; 2173 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index); 2174 ConstString index_const_str(index_str); 2175 // Check if we have already created a synthetic array member in this 2176 // valid object. If we have we will re-use it. 2177 synthetic_child_sp = GetSyntheticChild (index_const_str); 2178 if (!synthetic_child_sp) 2179 { 2180 ValueObject *synthetic_child; 2181 // We haven't made a synthetic array member for INDEX yet, so 2182 // lets make one and cache it for any future reference. 2183 synthetic_child = CreateChildAtIndex(0, true, index); 2184 2185 // Cache the value if we got one back... 2186 if (synthetic_child) 2187 { 2188 AddSyntheticChild(index_const_str, synthetic_child); 2189 synthetic_child_sp = synthetic_child->GetSP(); 2190 synthetic_child_sp->SetName(ConstString(index_str)); 2191 synthetic_child_sp->m_is_array_item_for_pointer = true; 2192 } 2193 } 2194 } 2195 return synthetic_child_sp; 2196 } 2197 2198 ValueObjectSP 2199 ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create) 2200 { 2201 ValueObjectSP synthetic_child_sp; 2202 if (IsScalarType ()) 2203 { 2204 char index_str[64]; 2205 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); 2206 ConstString index_const_str(index_str); 2207 // Check if we have already created a synthetic array member in this 2208 // valid object. If we have we will re-use it. 2209 synthetic_child_sp = GetSyntheticChild (index_const_str); 2210 if (!synthetic_child_sp) 2211 { 2212 // We haven't made a synthetic array member for INDEX yet, so 2213 // lets make one and cache it for any future reference. 2214 ValueObjectChild *synthetic_child = new ValueObjectChild (*this, 2215 GetCompilerType(), 2216 index_const_str, 2217 GetByteSize(), 2218 0, 2219 to-from+1, 2220 from, 2221 false, 2222 false, 2223 eAddressTypeInvalid); 2224 2225 // Cache the value if we got one back... 2226 if (synthetic_child) 2227 { 2228 AddSyntheticChild(index_const_str, synthetic_child); 2229 synthetic_child_sp = synthetic_child->GetSP(); 2230 synthetic_child_sp->SetName(ConstString(index_str)); 2231 synthetic_child_sp->m_is_bitfield_for_scalar = true; 2232 } 2233 } 2234 } 2235 return synthetic_child_sp; 2236 } 2237 2238 ValueObjectSP 2239 ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create) 2240 { 2241 2242 ValueObjectSP synthetic_child_sp; 2243 2244 char name_str[64]; 2245 snprintf(name_str, sizeof(name_str), "@%i", offset); 2246 ConstString name_const_str(name_str); 2247 2248 // Check if we have already created a synthetic array member in this 2249 // valid object. If we have we will re-use it. 2250 synthetic_child_sp = GetSyntheticChild (name_const_str); 2251 2252 if (synthetic_child_sp.get()) 2253 return synthetic_child_sp; 2254 2255 if (!can_create) 2256 return ValueObjectSP(); 2257 2258 ExecutionContext exe_ctx (GetExecutionContextRef()); 2259 2260 ValueObjectChild *synthetic_child = new ValueObjectChild(*this, 2261 type, 2262 name_const_str, 2263 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), 2264 offset, 2265 0, 2266 0, 2267 false, 2268 false, 2269 eAddressTypeInvalid); 2270 if (synthetic_child) 2271 { 2272 AddSyntheticChild(name_const_str, synthetic_child); 2273 synthetic_child_sp = synthetic_child->GetSP(); 2274 synthetic_child_sp->SetName(name_const_str); 2275 synthetic_child_sp->m_is_child_at_offset = true; 2276 } 2277 return synthetic_child_sp; 2278 } 2279 2280 ValueObjectSP 2281 ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create) 2282 { 2283 ValueObjectSP synthetic_child_sp; 2284 2285 char name_str[64]; 2286 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>")); 2287 ConstString name_const_str(name_str); 2288 2289 // Check if we have already created a synthetic array member in this 2290 // valid object. If we have we will re-use it. 2291 synthetic_child_sp = GetSyntheticChild (name_const_str); 2292 2293 if (synthetic_child_sp.get()) 2294 return synthetic_child_sp; 2295 2296 if (!can_create) 2297 return ValueObjectSP(); 2298 2299 const bool is_base_class = true; 2300 2301 ExecutionContext exe_ctx (GetExecutionContextRef()); 2302 2303 ValueObjectChild *synthetic_child = new ValueObjectChild(*this, 2304 type, 2305 name_const_str, 2306 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), 2307 offset, 2308 0, 2309 0, 2310 is_base_class, 2311 false, 2312 eAddressTypeInvalid); 2313 if (synthetic_child) 2314 { 2315 AddSyntheticChild(name_const_str, synthetic_child); 2316 synthetic_child_sp = synthetic_child->GetSP(); 2317 synthetic_child_sp->SetName(name_const_str); 2318 } 2319 return synthetic_child_sp; 2320 } 2321 2322 2323 // your expression path needs to have a leading . or -> 2324 // (unless it somehow "looks like" an array, in which case it has 2325 // a leading [ symbol). while the [ is meaningful and should be shown 2326 // to the user, . and -> are just parser design, but by no means 2327 // added information for the user.. strip them off 2328 static const char* 2329 SkipLeadingExpressionPathSeparators(const char* expression) 2330 { 2331 if (!expression || !expression[0]) 2332 return expression; 2333 if (expression[0] == '.') 2334 return expression+1; 2335 if (expression[0] == '-' && expression[1] == '>') 2336 return expression+2; 2337 return expression; 2338 } 2339 2340 ValueObjectSP 2341 ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create) 2342 { 2343 ValueObjectSP synthetic_child_sp; 2344 ConstString name_const_string(expression); 2345 // Check if we have already created a synthetic array member in this 2346 // valid object. If we have we will re-use it. 2347 synthetic_child_sp = GetSyntheticChild (name_const_string); 2348 if (!synthetic_child_sp) 2349 { 2350 // We haven't made a synthetic array member for expression yet, so 2351 // lets make one and cache it for any future reference. 2352 synthetic_child_sp = GetValueForExpressionPath(expression, 2353 NULL, NULL, NULL, 2354 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None)); 2355 2356 // Cache the value if we got one back... 2357 if (synthetic_child_sp.get()) 2358 { 2359 // FIXME: this causes a "real" child to end up with its name changed to the contents of expression 2360 AddSyntheticChild(name_const_string, synthetic_child_sp.get()); 2361 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression))); 2362 } 2363 } 2364 return synthetic_child_sp; 2365 } 2366 2367 void 2368 ValueObject::CalculateSyntheticValue (bool use_synthetic) 2369 { 2370 if (use_synthetic == false) 2371 return; 2372 2373 TargetSP target_sp(GetTargetSP()); 2374 if (target_sp && target_sp->GetEnableSyntheticValue() == false) 2375 { 2376 m_synthetic_value = NULL; 2377 return; 2378 } 2379 2380 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp); 2381 2382 if (!UpdateFormatsIfNeeded() && m_synthetic_value) 2383 return; 2384 2385 if (m_synthetic_children_sp.get() == NULL) 2386 return; 2387 2388 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value) 2389 return; 2390 2391 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp); 2392 } 2393 2394 void 2395 ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic) 2396 { 2397 if (use_dynamic == eNoDynamicValues) 2398 return; 2399 2400 if (!m_dynamic_value && !IsDynamic()) 2401 { 2402 ExecutionContext exe_ctx (GetExecutionContextRef()); 2403 Process *process = exe_ctx.GetProcessPtr(); 2404 if (process && process->IsPossibleDynamicValue(*this)) 2405 { 2406 ClearDynamicTypeInformation (); 2407 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); 2408 } 2409 } 2410 } 2411 2412 ValueObjectSP 2413 ValueObject::GetDynamicValue (DynamicValueType use_dynamic) 2414 { 2415 if (use_dynamic == eNoDynamicValues) 2416 return ValueObjectSP(); 2417 2418 if (!IsDynamic() && m_dynamic_value == NULL) 2419 { 2420 CalculateDynamicValue(use_dynamic); 2421 } 2422 if (m_dynamic_value) 2423 return m_dynamic_value->GetSP(); 2424 else 2425 return ValueObjectSP(); 2426 } 2427 2428 ValueObjectSP 2429 ValueObject::GetStaticValue() 2430 { 2431 return GetSP(); 2432 } 2433 2434 lldb::ValueObjectSP 2435 ValueObject::GetNonSyntheticValue () 2436 { 2437 return GetSP(); 2438 } 2439 2440 ValueObjectSP 2441 ValueObject::GetSyntheticValue (bool use_synthetic) 2442 { 2443 if (use_synthetic == false) 2444 return ValueObjectSP(); 2445 2446 CalculateSyntheticValue(use_synthetic); 2447 2448 if (m_synthetic_value) 2449 return m_synthetic_value->GetSP(); 2450 else 2451 return ValueObjectSP(); 2452 } 2453 2454 bool 2455 ValueObject::HasSyntheticValue() 2456 { 2457 UpdateFormatsIfNeeded(); 2458 2459 if (m_synthetic_children_sp.get() == NULL) 2460 return false; 2461 2462 CalculateSyntheticValue(true); 2463 2464 if (m_synthetic_value) 2465 return true; 2466 else 2467 return false; 2468 } 2469 2470 bool 2471 ValueObject::GetBaseClassPath (Stream &s) 2472 { 2473 if (IsBaseClass()) 2474 { 2475 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s); 2476 CompilerType compiler_type = GetCompilerType(); 2477 std::string cxx_class_name; 2478 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name); 2479 if (this_had_base_class) 2480 { 2481 if (parent_had_base_class) 2482 s.PutCString("::"); 2483 s.PutCString(cxx_class_name.c_str()); 2484 } 2485 return parent_had_base_class || this_had_base_class; 2486 } 2487 return false; 2488 } 2489 2490 2491 ValueObject * 2492 ValueObject::GetNonBaseClassParent() 2493 { 2494 if (GetParent()) 2495 { 2496 if (GetParent()->IsBaseClass()) 2497 return GetParent()->GetNonBaseClassParent(); 2498 else 2499 return GetParent(); 2500 } 2501 return NULL; 2502 } 2503 2504 2505 bool 2506 ValueObject::IsBaseClass (uint32_t& depth) 2507 { 2508 if (!IsBaseClass()) 2509 { 2510 depth = 0; 2511 return false; 2512 } 2513 if (GetParent()) 2514 { 2515 GetParent()->IsBaseClass(depth); 2516 depth = depth + 1; 2517 return true; 2518 } 2519 // TODO: a base of no parent? weird.. 2520 depth = 1; 2521 return true; 2522 } 2523 2524 void 2525 ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat) 2526 { 2527 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways 2528 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return 2529 // something that can hopefully be used in expression 2530 if (m_is_synthetic_children_generated) 2531 { 2532 UpdateValueIfNeeded(); 2533 2534 if (m_value.GetValueType() == Value::eValueTypeLoadAddress) 2535 { 2536 if (IsPointerOrReferenceType()) 2537 { 2538 s.Printf("((%s)0x%" PRIx64 ")", 2539 GetTypeName().AsCString("void"), 2540 GetValueAsUnsigned(0)); 2541 return; 2542 } 2543 else 2544 { 2545 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 2546 if (load_addr != LLDB_INVALID_ADDRESS) 2547 { 2548 s.Printf("(*( (%s *)0x%" PRIx64 "))", 2549 GetTypeName().AsCString("void"), 2550 load_addr); 2551 return; 2552 } 2553 } 2554 } 2555 2556 if (CanProvideValue()) 2557 { 2558 s.Printf("((%s)%s)", 2559 GetTypeName().AsCString("void"), 2560 GetValueAsCString()); 2561 return; 2562 } 2563 2564 return; 2565 } 2566 2567 const bool is_deref_of_parent = IsDereferenceOfParent (); 2568 2569 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers) 2570 { 2571 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely 2572 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName. 2573 // the eHonorPointers mode is meant to produce strings in this latter format 2574 s.PutCString("*("); 2575 } 2576 2577 ValueObject* parent = GetParent(); 2578 2579 if (parent) 2580 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat); 2581 2582 // if we are a deref_of_parent just because we are synthetic array 2583 // members made up to allow ptr[%d] syntax to work in variable 2584 // printing, then add our name ([%d]) to the expression path 2585 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers) 2586 s.PutCString(m_name.AsCString()); 2587 2588 if (!IsBaseClass()) 2589 { 2590 if (!is_deref_of_parent) 2591 { 2592 ValueObject *non_base_class_parent = GetNonBaseClassParent(); 2593 if (non_base_class_parent) 2594 { 2595 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType(); 2596 if (non_base_class_parent_compiler_type) 2597 { 2598 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers) 2599 { 2600 s.PutCString("->"); 2601 } 2602 else 2603 { 2604 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo(); 2605 2606 if (non_base_class_parent_type_info & eTypeIsPointer) 2607 { 2608 s.PutCString("->"); 2609 } 2610 else if ((non_base_class_parent_type_info & eTypeHasChildren) && 2611 !(non_base_class_parent_type_info & eTypeIsArray)) 2612 { 2613 s.PutChar('.'); 2614 } 2615 } 2616 } 2617 } 2618 2619 const char *name = GetName().GetCString(); 2620 if (name) 2621 { 2622 if (qualify_cxx_base_classes) 2623 { 2624 if (GetBaseClassPath (s)) 2625 s.PutCString("::"); 2626 } 2627 s.PutCString(name); 2628 } 2629 } 2630 } 2631 2632 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers) 2633 { 2634 s.PutChar(')'); 2635 } 2636 } 2637 2638 ValueObjectSP 2639 ValueObject::GetValueForExpressionPath(const char* expression, 2640 const char** first_unparsed, 2641 ExpressionPathScanEndReason* reason_to_stop, 2642 ExpressionPathEndResultType* final_value_type, 2643 const GetValueForExpressionPathOptions& options, 2644 ExpressionPathAftermath* final_task_on_target) 2645 { 2646 2647 const char* dummy_first_unparsed; 2648 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown; 2649 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; 2650 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2651 2652 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, 2653 first_unparsed ? first_unparsed : &dummy_first_unparsed, 2654 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 2655 final_value_type ? final_value_type : &dummy_final_value_type, 2656 options, 2657 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); 2658 2659 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing) 2660 return ret_val; 2661 2662 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects 2663 { 2664 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference) 2665 { 2666 Error error; 2667 ValueObjectSP final_value = ret_val->Dereference(error); 2668 if (error.Fail() || !final_value.get()) 2669 { 2670 if (reason_to_stop) 2671 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2672 if (final_value_type) 2673 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; 2674 return ValueObjectSP(); 2675 } 2676 else 2677 { 2678 if (final_task_on_target) 2679 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2680 return final_value; 2681 } 2682 } 2683 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress) 2684 { 2685 Error error; 2686 ValueObjectSP final_value = ret_val->AddressOf(error); 2687 if (error.Fail() || !final_value.get()) 2688 { 2689 if (reason_to_stop) 2690 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed; 2691 if (final_value_type) 2692 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; 2693 return ValueObjectSP(); 2694 } 2695 else 2696 { 2697 if (final_task_on_target) 2698 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2699 return final_value; 2700 } 2701 } 2702 } 2703 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it 2704 } 2705 2706 int 2707 ValueObject::GetValuesForExpressionPath(const char* expression, 2708 ValueObjectListSP& list, 2709 const char** first_unparsed, 2710 ExpressionPathScanEndReason* reason_to_stop, 2711 ExpressionPathEndResultType* final_value_type, 2712 const GetValueForExpressionPathOptions& options, 2713 ExpressionPathAftermath* final_task_on_target) 2714 { 2715 const char* dummy_first_unparsed; 2716 ExpressionPathScanEndReason dummy_reason_to_stop; 2717 ExpressionPathEndResultType dummy_final_value_type; 2718 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2719 2720 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, 2721 first_unparsed ? first_unparsed : &dummy_first_unparsed, 2722 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 2723 final_value_type ? final_value_type : &dummy_final_value_type, 2724 options, 2725 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); 2726 2727 if (!ret_val.get()) // if there are errors, I add nothing to the list 2728 return 0; 2729 2730 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet) 2731 { 2732 // I need not expand a range, just post-process the final value and return 2733 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing) 2734 { 2735 list->Append(ret_val); 2736 return 1; 2737 } 2738 if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects 2739 { 2740 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference) 2741 { 2742 Error error; 2743 ValueObjectSP final_value = ret_val->Dereference(error); 2744 if (error.Fail() || !final_value.get()) 2745 { 2746 if (reason_to_stop) 2747 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2748 if (final_value_type) 2749 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; 2750 return 0; 2751 } 2752 else 2753 { 2754 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2755 list->Append(final_value); 2756 return 1; 2757 } 2758 } 2759 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress) 2760 { 2761 Error error; 2762 ValueObjectSP final_value = ret_val->AddressOf(error); 2763 if (error.Fail() || !final_value.get()) 2764 { 2765 if (reason_to_stop) 2766 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed; 2767 if (final_value_type) 2768 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; 2769 return 0; 2770 } 2771 else 2772 { 2773 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2774 list->Append(final_value); 2775 return 1; 2776 } 2777 } 2778 } 2779 } 2780 else 2781 { 2782 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed, 2783 first_unparsed ? first_unparsed : &dummy_first_unparsed, 2784 ret_val, 2785 list, 2786 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 2787 final_value_type ? final_value_type : &dummy_final_value_type, 2788 options, 2789 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); 2790 } 2791 // in any non-covered case, just do the obviously right thing 2792 list->Append(ret_val); 2793 return 1; 2794 } 2795 2796 ValueObjectSP 2797 ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr, 2798 const char** first_unparsed, 2799 ExpressionPathScanEndReason* reason_to_stop, 2800 ExpressionPathEndResultType* final_result, 2801 const GetValueForExpressionPathOptions& options, 2802 ExpressionPathAftermath* what_next) 2803 { 2804 ValueObjectSP root = GetSP(); 2805 2806 if (!root.get()) 2807 return ValueObjectSP(); 2808 2809 *first_unparsed = expression_cstr; 2810 2811 while (true) 2812 { 2813 2814 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr 2815 2816 CompilerType root_compiler_type = root->GetCompilerType(); 2817 CompilerType pointee_compiler_type; 2818 Flags pointee_compiler_type_info; 2819 2820 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type)); 2821 if (pointee_compiler_type) 2822 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo()); 2823 2824 if (!expression_cstr || *expression_cstr == '\0') 2825 { 2826 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; 2827 return root; 2828 } 2829 2830 switch (*expression_cstr) 2831 { 2832 case '-': 2833 { 2834 if (options.m_check_dot_vs_arrow_syntax && 2835 root_compiler_type_info.Test(eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error 2836 { 2837 *first_unparsed = expression_cstr; 2838 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot; 2839 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2840 return ValueObjectSP(); 2841 } 2842 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden 2843 root_compiler_type_info.Test(eTypeIsPointer) && 2844 options.m_no_fragile_ivar) 2845 { 2846 *first_unparsed = expression_cstr; 2847 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed; 2848 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2849 return ValueObjectSP(); 2850 } 2851 if (expression_cstr[1] != '>') 2852 { 2853 *first_unparsed = expression_cstr; 2854 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2855 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2856 return ValueObjectSP(); 2857 } 2858 expression_cstr++; // skip the - 2859 } 2860 case '.': // or fallthrough from -> 2861 { 2862 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' && 2863 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error 2864 { 2865 *first_unparsed = expression_cstr; 2866 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow; 2867 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2868 return ValueObjectSP(); 2869 } 2870 expression_cstr++; // skip . 2871 const char *next_separator = strpbrk(expression_cstr+1,"-.["); 2872 ConstString child_name; 2873 if (!next_separator) // if no other separator just expand this last layer 2874 { 2875 child_name.SetCString (expression_cstr); 2876 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true); 2877 2878 if (child_valobj_sp.get()) // we know we are done, so just return 2879 { 2880 *first_unparsed = ""; 2881 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; 2882 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2883 return child_valobj_sp; 2884 } 2885 else 2886 { 2887 switch (options.m_synthetic_children_traversal) 2888 { 2889 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None: 2890 break; 2891 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic: 2892 if (root->IsSynthetic()) 2893 { 2894 child_valobj_sp = root->GetNonSyntheticValue(); 2895 if (child_valobj_sp.get()) 2896 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); 2897 } 2898 break; 2899 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic: 2900 if (!root->IsSynthetic()) 2901 { 2902 child_valobj_sp = root->GetSyntheticValue(); 2903 if (child_valobj_sp.get()) 2904 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); 2905 } 2906 break; 2907 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both: 2908 if (root->IsSynthetic()) 2909 { 2910 child_valobj_sp = root->GetNonSyntheticValue(); 2911 if (child_valobj_sp.get()) 2912 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); 2913 } 2914 else 2915 { 2916 child_valobj_sp = root->GetSyntheticValue(); 2917 if (child_valobj_sp.get()) 2918 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); 2919 } 2920 break; 2921 } 2922 } 2923 2924 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP, 2925 // so we hit the "else" branch, and return an error 2926 if(child_valobj_sp.get()) // if it worked, just return 2927 { 2928 *first_unparsed = ""; 2929 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; 2930 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2931 return child_valobj_sp; 2932 } 2933 else 2934 { 2935 *first_unparsed = expression_cstr; 2936 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2937 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2938 return ValueObjectSP(); 2939 } 2940 } 2941 else // other layers do expand 2942 { 2943 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr); 2944 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true); 2945 if (child_valobj_sp.get()) // store the new root and move on 2946 { 2947 root = child_valobj_sp; 2948 *first_unparsed = next_separator; 2949 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2950 continue; 2951 } 2952 else 2953 { 2954 switch (options.m_synthetic_children_traversal) 2955 { 2956 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None: 2957 break; 2958 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic: 2959 if (root->IsSynthetic()) 2960 { 2961 child_valobj_sp = root->GetNonSyntheticValue(); 2962 if (child_valobj_sp.get()) 2963 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); 2964 } 2965 break; 2966 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic: 2967 if (!root->IsSynthetic()) 2968 { 2969 child_valobj_sp = root->GetSyntheticValue(); 2970 if (child_valobj_sp.get()) 2971 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); 2972 } 2973 break; 2974 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both: 2975 if (root->IsSynthetic()) 2976 { 2977 child_valobj_sp = root->GetNonSyntheticValue(); 2978 if (child_valobj_sp.get()) 2979 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); 2980 } 2981 else 2982 { 2983 child_valobj_sp = root->GetSyntheticValue(); 2984 if (child_valobj_sp.get()) 2985 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); 2986 } 2987 break; 2988 } 2989 } 2990 2991 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP, 2992 // so we hit the "else" branch, and return an error 2993 if(child_valobj_sp.get()) // if it worked, move on 2994 { 2995 root = child_valobj_sp; 2996 *first_unparsed = next_separator; 2997 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2998 continue; 2999 } 3000 else 3001 { 3002 *first_unparsed = expression_cstr; 3003 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3004 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3005 return ValueObjectSP(); 3006 } 3007 } 3008 break; 3009 } 3010 case '[': 3011 { 3012 if (!root_compiler_type_info.Test(eTypeIsArray) && !root_compiler_type_info.Test(eTypeIsPointer) && !root_compiler_type_info.Test(eTypeIsVector)) // if this is not a T[] nor a T* 3013 { 3014 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar... 3015 { 3016 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic 3017 { 3018 *first_unparsed = expression_cstr; 3019 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid; 3020 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3021 return ValueObjectSP(); 3022 } 3023 } 3024 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields 3025 { 3026 *first_unparsed = expression_cstr; 3027 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed; 3028 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3029 return ValueObjectSP(); 3030 } 3031 } 3032 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays 3033 { 3034 if (!root_compiler_type_info.Test(eTypeIsArray)) 3035 { 3036 *first_unparsed = expression_cstr; 3037 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 3038 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3039 return ValueObjectSP(); 3040 } 3041 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it 3042 { 3043 *first_unparsed = expression_cstr+2; 3044 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; 3045 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange; 3046 return root; 3047 } 3048 } 3049 const char *separator_position = ::strchr(expression_cstr+1,'-'); 3050 const char *close_bracket_position = ::strchr(expression_cstr+1,']'); 3051 if (!close_bracket_position) // if there is no ], this is a syntax error 3052 { 3053 *first_unparsed = expression_cstr; 3054 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3055 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3056 return ValueObjectSP(); 3057 } 3058 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] 3059 { 3060 char *end = NULL; 3061 unsigned long index = ::strtoul (expression_cstr+1, &end, 0); 3062 if (!end || end != close_bracket_position) // if something weird is in our way return an error 3063 { 3064 *first_unparsed = expression_cstr; 3065 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3066 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3067 return ValueObjectSP(); 3068 } 3069 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays 3070 { 3071 if (root_compiler_type_info.Test(eTypeIsArray)) 3072 { 3073 *first_unparsed = expression_cstr+2; 3074 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; 3075 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange; 3076 return root; 3077 } 3078 else 3079 { 3080 *first_unparsed = expression_cstr; 3081 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 3082 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3083 return ValueObjectSP(); 3084 } 3085 } 3086 // from here on we do have a valid index 3087 if (root_compiler_type_info.Test(eTypeIsArray)) 3088 { 3089 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); 3090 if (!child_valobj_sp) 3091 child_valobj_sp = root->GetSyntheticArrayMember(index, true); 3092 if (!child_valobj_sp) 3093 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index) 3094 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true); 3095 if (child_valobj_sp) 3096 { 3097 root = child_valobj_sp; 3098 *first_unparsed = end+1; // skip ] 3099 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 3100 continue; 3101 } 3102 else 3103 { 3104 *first_unparsed = expression_cstr; 3105 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3106 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3107 return ValueObjectSP(); 3108 } 3109 } 3110 else if (root_compiler_type_info.Test(eTypeIsPointer)) 3111 { 3112 if (*what_next == ValueObject::eExpressionPathAftermathDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield 3113 pointee_compiler_type_info.Test(eTypeIsScalar)) 3114 { 3115 Error error; 3116 root = root->Dereference(error); 3117 if (error.Fail() || !root.get()) 3118 { 3119 *first_unparsed = expression_cstr; 3120 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 3121 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3122 return ValueObjectSP(); 3123 } 3124 else 3125 { 3126 *what_next = eExpressionPathAftermathNothing; 3127 continue; 3128 } 3129 } 3130 else 3131 { 3132 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC 3133 && pointee_compiler_type_info.AllClear(eTypeIsPointer) 3134 && root->HasSyntheticValue() 3135 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic || 3136 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)) 3137 { 3138 root = root->GetSyntheticValue()->GetChildAtIndex(index, true); 3139 } 3140 else 3141 root = root->GetSyntheticArrayMember(index, true); 3142 if (!root.get()) 3143 { 3144 *first_unparsed = expression_cstr; 3145 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3146 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3147 return ValueObjectSP(); 3148 } 3149 else 3150 { 3151 *first_unparsed = end+1; // skip ] 3152 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 3153 continue; 3154 } 3155 } 3156 } 3157 else if (root_compiler_type_info.Test(eTypeIsScalar)) 3158 { 3159 root = root->GetSyntheticBitFieldChild(index, index, true); 3160 if (!root.get()) 3161 { 3162 *first_unparsed = expression_cstr; 3163 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3164 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3165 return ValueObjectSP(); 3166 } 3167 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing 3168 { 3169 *first_unparsed = end+1; // skip ] 3170 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet; 3171 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; 3172 return root; 3173 } 3174 } 3175 else if (root_compiler_type_info.Test(eTypeIsVector)) 3176 { 3177 root = root->GetChildAtIndex(index, true); 3178 if (!root.get()) 3179 { 3180 *first_unparsed = expression_cstr; 3181 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3182 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3183 return ValueObjectSP(); 3184 } 3185 else 3186 { 3187 *first_unparsed = end+1; // skip ] 3188 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 3189 continue; 3190 } 3191 } 3192 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic || 3193 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both) 3194 { 3195 if (root->HasSyntheticValue()) 3196 root = root->GetSyntheticValue(); 3197 else if (!root->IsSynthetic()) 3198 { 3199 *first_unparsed = expression_cstr; 3200 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; 3201 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3202 return ValueObjectSP(); 3203 } 3204 // if we are here, then root itself is a synthetic VO.. should be good to go 3205 3206 if (!root.get()) 3207 { 3208 *first_unparsed = expression_cstr; 3209 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; 3210 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3211 return ValueObjectSP(); 3212 } 3213 root = root->GetChildAtIndex(index, true); 3214 if (!root.get()) 3215 { 3216 *first_unparsed = expression_cstr; 3217 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3218 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3219 return ValueObjectSP(); 3220 } 3221 else 3222 { 3223 *first_unparsed = end+1; // skip ] 3224 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 3225 continue; 3226 } 3227 } 3228 else 3229 { 3230 *first_unparsed = expression_cstr; 3231 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3232 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3233 return ValueObjectSP(); 3234 } 3235 } 3236 else // we have a low and a high index 3237 { 3238 char *end = NULL; 3239 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); 3240 if (!end || end != separator_position) // if something weird is in our way return an error 3241 { 3242 *first_unparsed = expression_cstr; 3243 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3244 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3245 return ValueObjectSP(); 3246 } 3247 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); 3248 if (!end || end != close_bracket_position) // if something weird is in our way return an error 3249 { 3250 *first_unparsed = expression_cstr; 3251 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3252 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3253 return ValueObjectSP(); 3254 } 3255 if (index_lower > index_higher) // swap indices if required 3256 { 3257 unsigned long temp = index_lower; 3258 index_lower = index_higher; 3259 index_higher = temp; 3260 } 3261 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars 3262 { 3263 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); 3264 if (!root.get()) 3265 { 3266 *first_unparsed = expression_cstr; 3267 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3268 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3269 return ValueObjectSP(); 3270 } 3271 else 3272 { 3273 *first_unparsed = end+1; // skip ] 3274 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet; 3275 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; 3276 return root; 3277 } 3278 } 3279 else if (root_compiler_type_info.Test(eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield 3280 *what_next == ValueObject::eExpressionPathAftermathDereference && 3281 pointee_compiler_type_info.Test(eTypeIsScalar)) 3282 { 3283 Error error; 3284 root = root->Dereference(error); 3285 if (error.Fail() || !root.get()) 3286 { 3287 *first_unparsed = expression_cstr; 3288 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 3289 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3290 return ValueObjectSP(); 3291 } 3292 else 3293 { 3294 *what_next = ValueObject::eExpressionPathAftermathNothing; 3295 continue; 3296 } 3297 } 3298 else 3299 { 3300 *first_unparsed = expression_cstr; 3301 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; 3302 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange; 3303 return root; 3304 } 3305 } 3306 break; 3307 } 3308 default: // some non-separator is in the way 3309 { 3310 *first_unparsed = expression_cstr; 3311 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3312 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3313 return ValueObjectSP(); 3314 break; 3315 } 3316 } 3317 } 3318 } 3319 3320 int 3321 ValueObject::ExpandArraySliceExpression(const char* expression_cstr, 3322 const char** first_unparsed, 3323 ValueObjectSP root, 3324 ValueObjectListSP& list, 3325 ExpressionPathScanEndReason* reason_to_stop, 3326 ExpressionPathEndResultType* final_result, 3327 const GetValueForExpressionPathOptions& options, 3328 ExpressionPathAftermath* what_next) 3329 { 3330 if (!root.get()) 3331 return 0; 3332 3333 *first_unparsed = expression_cstr; 3334 3335 while (true) 3336 { 3337 3338 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr 3339 3340 CompilerType root_compiler_type = root->GetCompilerType(); 3341 CompilerType pointee_compiler_type; 3342 Flags pointee_compiler_type_info; 3343 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type)); 3344 if (pointee_compiler_type) 3345 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo()); 3346 3347 if (!expression_cstr || *expression_cstr == '\0') 3348 { 3349 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; 3350 list->Append(root); 3351 return 1; 3352 } 3353 3354 switch (*expression_cstr) 3355 { 3356 case '[': 3357 { 3358 if (!root_compiler_type_info.Test(eTypeIsArray) && !root_compiler_type_info.Test(eTypeIsPointer)) // if this is not a T[] nor a T* 3359 { 3360 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong! 3361 { 3362 *first_unparsed = expression_cstr; 3363 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid; 3364 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3365 return 0; 3366 } 3367 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields 3368 { 3369 *first_unparsed = expression_cstr; 3370 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed; 3371 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3372 return 0; 3373 } 3374 } 3375 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays 3376 { 3377 if (!root_compiler_type_info.Test(eTypeIsArray)) 3378 { 3379 *first_unparsed = expression_cstr; 3380 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 3381 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3382 return 0; 3383 } 3384 else // expand this into list 3385 { 3386 const size_t max_index = root->GetNumChildren() - 1; 3387 for (size_t index = 0; index < max_index; index++) 3388 { 3389 ValueObjectSP child = 3390 root->GetChildAtIndex(index, true); 3391 list->Append(child); 3392 } 3393 *first_unparsed = expression_cstr+2; 3394 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3395 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; 3396 return max_index; // tell me number of items I added to the VOList 3397 } 3398 } 3399 const char *separator_position = ::strchr(expression_cstr+1,'-'); 3400 const char *close_bracket_position = ::strchr(expression_cstr+1,']'); 3401 if (!close_bracket_position) // if there is no ], this is a syntax error 3402 { 3403 *first_unparsed = expression_cstr; 3404 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3405 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3406 return 0; 3407 } 3408 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] 3409 { 3410 char *end = NULL; 3411 unsigned long index = ::strtoul (expression_cstr+1, &end, 0); 3412 if (!end || end != close_bracket_position) // if something weird is in our way return an error 3413 { 3414 *first_unparsed = expression_cstr; 3415 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3416 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3417 return 0; 3418 } 3419 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays 3420 { 3421 if (root_compiler_type_info.Test(eTypeIsArray)) 3422 { 3423 const size_t max_index = root->GetNumChildren() - 1; 3424 for (size_t index = 0; index < max_index; index++) 3425 { 3426 ValueObjectSP child = 3427 root->GetChildAtIndex(index, true); 3428 list->Append(child); 3429 } 3430 *first_unparsed = expression_cstr+2; 3431 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3432 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; 3433 return max_index; // tell me number of items I added to the VOList 3434 } 3435 else 3436 { 3437 *first_unparsed = expression_cstr; 3438 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 3439 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3440 return 0; 3441 } 3442 } 3443 // from here on we do have a valid index 3444 if (root_compiler_type_info.Test(eTypeIsArray)) 3445 { 3446 root = root->GetChildAtIndex(index, true); 3447 if (!root.get()) 3448 { 3449 *first_unparsed = expression_cstr; 3450 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3451 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3452 return 0; 3453 } 3454 else 3455 { 3456 list->Append(root); 3457 *first_unparsed = end+1; // skip ] 3458 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3459 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; 3460 return 1; 3461 } 3462 } 3463 else if (root_compiler_type_info.Test(eTypeIsPointer)) 3464 { 3465 if (*what_next == ValueObject::eExpressionPathAftermathDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield 3466 pointee_compiler_type_info.Test(eTypeIsScalar)) 3467 { 3468 Error error; 3469 root = root->Dereference(error); 3470 if (error.Fail() || !root.get()) 3471 { 3472 *first_unparsed = expression_cstr; 3473 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 3474 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3475 return 0; 3476 } 3477 else 3478 { 3479 *what_next = eExpressionPathAftermathNothing; 3480 continue; 3481 } 3482 } 3483 else 3484 { 3485 root = root->GetSyntheticArrayMember(index, true); 3486 if (!root.get()) 3487 { 3488 *first_unparsed = expression_cstr; 3489 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3490 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3491 return 0; 3492 } 3493 else 3494 { 3495 list->Append(root); 3496 *first_unparsed = end+1; // skip ] 3497 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3498 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; 3499 return 1; 3500 } 3501 } 3502 } 3503 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/ 3504 { 3505 root = root->GetSyntheticBitFieldChild(index, index, true); 3506 if (!root.get()) 3507 { 3508 *first_unparsed = expression_cstr; 3509 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3510 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3511 return 0; 3512 } 3513 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing 3514 { 3515 list->Append(root); 3516 *first_unparsed = end+1; // skip ] 3517 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3518 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; 3519 return 1; 3520 } 3521 } 3522 } 3523 else // we have a low and a high index 3524 { 3525 char *end = NULL; 3526 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); 3527 if (!end || end != separator_position) // if something weird is in our way return an error 3528 { 3529 *first_unparsed = expression_cstr; 3530 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3531 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3532 return 0; 3533 } 3534 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); 3535 if (!end || end != close_bracket_position) // if something weird is in our way return an error 3536 { 3537 *first_unparsed = expression_cstr; 3538 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3539 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3540 return 0; 3541 } 3542 if (index_lower > index_higher) // swap indices if required 3543 { 3544 unsigned long temp = index_lower; 3545 index_lower = index_higher; 3546 index_higher = temp; 3547 } 3548 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars 3549 { 3550 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); 3551 if (!root.get()) 3552 { 3553 *first_unparsed = expression_cstr; 3554 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3555 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3556 return 0; 3557 } 3558 else 3559 { 3560 list->Append(root); 3561 *first_unparsed = end+1; // skip ] 3562 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3563 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; 3564 return 1; 3565 } 3566 } 3567 else if (root_compiler_type_info.Test(eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield 3568 *what_next == ValueObject::eExpressionPathAftermathDereference && 3569 pointee_compiler_type_info.Test(eTypeIsScalar)) 3570 { 3571 Error error; 3572 root = root->Dereference(error); 3573 if (error.Fail() || !root.get()) 3574 { 3575 *first_unparsed = expression_cstr; 3576 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 3577 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3578 return 0; 3579 } 3580 else 3581 { 3582 *what_next = ValueObject::eExpressionPathAftermathNothing; 3583 continue; 3584 } 3585 } 3586 else 3587 { 3588 for (unsigned long index = index_lower; 3589 index <= index_higher; index++) 3590 { 3591 ValueObjectSP child = 3592 root->GetChildAtIndex(index, true); 3593 list->Append(child); 3594 } 3595 *first_unparsed = end+1; 3596 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3597 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; 3598 return index_higher-index_lower+1; // tell me number of items I added to the VOList 3599 } 3600 } 3601 break; 3602 } 3603 default: // some non-[ separator, or something entirely wrong, is in the way 3604 { 3605 *first_unparsed = expression_cstr; 3606 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3607 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3608 return 0; 3609 break; 3610 } 3611 } 3612 } 3613 } 3614 3615 void 3616 ValueObject::LogValueObject (Log *log) 3617 { 3618 if (log) 3619 return LogValueObject (log, DumpValueObjectOptions(*this)); 3620 } 3621 3622 void 3623 ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options) 3624 { 3625 if (log) 3626 { 3627 StreamString s; 3628 Dump (s, options); 3629 if (s.GetSize()) 3630 log->PutCString(s.GetData()); 3631 } 3632 } 3633 3634 void 3635 ValueObject::Dump (Stream &s) 3636 { 3637 Dump (s, DumpValueObjectOptions(*this)); 3638 } 3639 3640 void 3641 ValueObject::Dump (Stream &s, 3642 const DumpValueObjectOptions& options) 3643 { 3644 ValueObjectPrinter printer(this,&s,options); 3645 printer.PrintValueObject(); 3646 } 3647 3648 ValueObjectSP 3649 ValueObject::CreateConstantValue (const ConstString &name) 3650 { 3651 ValueObjectSP valobj_sp; 3652 3653 if (UpdateValueIfNeeded(false) && m_error.Success()) 3654 { 3655 ExecutionContext exe_ctx (GetExecutionContextRef()); 3656 3657 DataExtractor data; 3658 data.SetByteOrder (m_data.GetByteOrder()); 3659 data.SetAddressByteSize(m_data.GetAddressByteSize()); 3660 3661 if (IsBitfield()) 3662 { 3663 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX))); 3664 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get()); 3665 } 3666 else 3667 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get()); 3668 3669 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), 3670 GetCompilerType(), 3671 name, 3672 data, 3673 GetAddressOf()); 3674 } 3675 3676 if (!valobj_sp) 3677 { 3678 ExecutionContext exe_ctx (GetExecutionContextRef()); 3679 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error); 3680 } 3681 return valobj_sp; 3682 } 3683 3684 ValueObjectSP 3685 ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue, 3686 bool synthValue) 3687 { 3688 ValueObjectSP result_sp(GetSP()); 3689 3690 switch (dynValue) 3691 { 3692 case lldb::eDynamicCanRunTarget: 3693 case lldb::eDynamicDontRunTarget: 3694 { 3695 if (!result_sp->IsDynamic()) 3696 { 3697 if (result_sp->GetDynamicValue(dynValue)) 3698 result_sp = result_sp->GetDynamicValue(dynValue); 3699 } 3700 } 3701 break; 3702 case lldb::eNoDynamicValues: 3703 { 3704 if (result_sp->IsDynamic()) 3705 { 3706 if (result_sp->GetStaticValue()) 3707 result_sp = result_sp->GetStaticValue(); 3708 } 3709 } 3710 break; 3711 } 3712 3713 if (synthValue) 3714 { 3715 if (!result_sp->IsSynthetic()) 3716 { 3717 if (result_sp->GetSyntheticValue()) 3718 result_sp = result_sp->GetSyntheticValue(); 3719 } 3720 } 3721 else 3722 { 3723 if (result_sp->IsSynthetic()) 3724 { 3725 if (result_sp->GetNonSyntheticValue()) 3726 result_sp = result_sp->GetNonSyntheticValue(); 3727 } 3728 } 3729 3730 return result_sp; 3731 } 3732 3733 lldb::addr_t 3734 ValueObject::GetCPPVTableAddress (AddressType &address_type) 3735 { 3736 CompilerType pointee_type; 3737 CompilerType this_type(GetCompilerType()); 3738 uint32_t type_info = this_type.GetTypeInfo(&pointee_type); 3739 if (type_info) 3740 { 3741 bool ptr_or_ref = false; 3742 if (type_info & (eTypeIsPointer | eTypeIsReference)) 3743 { 3744 ptr_or_ref = true; 3745 type_info = pointee_type.GetTypeInfo(); 3746 } 3747 3748 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus; 3749 if ((type_info & cpp_class) == cpp_class) 3750 { 3751 if (ptr_or_ref) 3752 { 3753 address_type = GetAddressTypeOfChildren(); 3754 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS); 3755 } 3756 else 3757 return GetAddressOf (false, &address_type); 3758 } 3759 } 3760 3761 address_type = eAddressTypeInvalid; 3762 return LLDB_INVALID_ADDRESS; 3763 } 3764 3765 ValueObjectSP 3766 ValueObject::Dereference (Error &error) 3767 { 3768 if (m_deref_valobj) 3769 return m_deref_valobj->GetSP(); 3770 3771 const bool is_pointer_or_reference_type = IsPointerOrReferenceType(); 3772 if (is_pointer_or_reference_type) 3773 { 3774 bool omit_empty_base_classes = true; 3775 bool ignore_array_bounds = false; 3776 3777 std::string child_name_str; 3778 uint32_t child_byte_size = 0; 3779 int32_t child_byte_offset = 0; 3780 uint32_t child_bitfield_bit_size = 0; 3781 uint32_t child_bitfield_bit_offset = 0; 3782 bool child_is_base_class = false; 3783 bool child_is_deref_of_parent = false; 3784 const bool transparent_pointers = false; 3785 CompilerType compiler_type = GetCompilerType(); 3786 CompilerType child_compiler_type; 3787 3788 ExecutionContext exe_ctx (GetExecutionContextRef()); 3789 3790 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx, 3791 0, 3792 transparent_pointers, 3793 omit_empty_base_classes, 3794 ignore_array_bounds, 3795 child_name_str, 3796 child_byte_size, 3797 child_byte_offset, 3798 child_bitfield_bit_size, 3799 child_bitfield_bit_offset, 3800 child_is_base_class, 3801 child_is_deref_of_parent, 3802 this); 3803 if (child_compiler_type && child_byte_size) 3804 { 3805 ConstString child_name; 3806 if (!child_name_str.empty()) 3807 child_name.SetCString (child_name_str.c_str()); 3808 3809 m_deref_valobj = new ValueObjectChild (*this, 3810 child_compiler_type, 3811 child_name, 3812 child_byte_size, 3813 child_byte_offset, 3814 child_bitfield_bit_size, 3815 child_bitfield_bit_offset, 3816 child_is_base_class, 3817 child_is_deref_of_parent, 3818 eAddressTypeInvalid); 3819 } 3820 } 3821 3822 if (m_deref_valobj) 3823 { 3824 error.Clear(); 3825 return m_deref_valobj->GetSP(); 3826 } 3827 else 3828 { 3829 StreamString strm; 3830 GetExpressionPath(strm, true); 3831 3832 if (is_pointer_or_reference_type) 3833 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); 3834 else 3835 error.SetErrorStringWithFormat("not a pointer or reference type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); 3836 return ValueObjectSP(); 3837 } 3838 } 3839 3840 ValueObjectSP 3841 ValueObject::AddressOf (Error &error) 3842 { 3843 if (m_addr_of_valobj_sp) 3844 return m_addr_of_valobj_sp; 3845 3846 AddressType address_type = eAddressTypeInvalid; 3847 const bool scalar_is_load_address = false; 3848 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type); 3849 error.Clear(); 3850 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost) 3851 { 3852 switch (address_type) 3853 { 3854 case eAddressTypeInvalid: 3855 { 3856 StreamString expr_path_strm; 3857 GetExpressionPath(expr_path_strm, true); 3858 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str()); 3859 } 3860 break; 3861 3862 case eAddressTypeFile: 3863 case eAddressTypeLoad: 3864 { 3865 CompilerType compiler_type = GetCompilerType(); 3866 if (compiler_type) 3867 { 3868 std::string name (1, '&'); 3869 name.append (m_name.AsCString("")); 3870 ExecutionContext exe_ctx (GetExecutionContextRef()); 3871 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), 3872 compiler_type.GetPointerType(), 3873 ConstString (name.c_str()), 3874 addr, 3875 eAddressTypeInvalid, 3876 m_data.GetAddressByteSize()); 3877 } 3878 } 3879 break; 3880 default: 3881 break; 3882 } 3883 } 3884 else 3885 { 3886 StreamString expr_path_strm; 3887 GetExpressionPath(expr_path_strm, true); 3888 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str()); 3889 } 3890 3891 return m_addr_of_valobj_sp; 3892 } 3893 3894 ValueObjectSP 3895 ValueObject::Cast (const CompilerType &compiler_type) 3896 { 3897 return ValueObjectCast::Create (*this, GetName(), compiler_type); 3898 } 3899 3900 ValueObjectSP 3901 ValueObject::CastPointerType (const char *name, CompilerType &compiler_type) 3902 { 3903 ValueObjectSP valobj_sp; 3904 AddressType address_type; 3905 addr_t ptr_value = GetPointerValue (&address_type); 3906 3907 if (ptr_value != LLDB_INVALID_ADDRESS) 3908 { 3909 Address ptr_addr (ptr_value); 3910 ExecutionContext exe_ctx (GetExecutionContextRef()); 3911 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), 3912 name, 3913 ptr_addr, 3914 compiler_type); 3915 } 3916 return valobj_sp; 3917 } 3918 3919 ValueObjectSP 3920 ValueObject::CastPointerType (const char *name, TypeSP &type_sp) 3921 { 3922 ValueObjectSP valobj_sp; 3923 AddressType address_type; 3924 addr_t ptr_value = GetPointerValue (&address_type); 3925 3926 if (ptr_value != LLDB_INVALID_ADDRESS) 3927 { 3928 Address ptr_addr (ptr_value); 3929 ExecutionContext exe_ctx (GetExecutionContextRef()); 3930 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), 3931 name, 3932 ptr_addr, 3933 type_sp); 3934 } 3935 return valobj_sp; 3936 } 3937 3938 ValueObject::EvaluationPoint::EvaluationPoint () : 3939 m_mod_id(), 3940 m_exe_ctx_ref(), 3941 m_needs_update (true) 3942 { 3943 } 3944 3945 ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): 3946 m_mod_id(), 3947 m_exe_ctx_ref(), 3948 m_needs_update (true) 3949 { 3950 ExecutionContext exe_ctx(exe_scope); 3951 TargetSP target_sp (exe_ctx.GetTargetSP()); 3952 if (target_sp) 3953 { 3954 m_exe_ctx_ref.SetTargetSP (target_sp); 3955 ProcessSP process_sp (exe_ctx.GetProcessSP()); 3956 if (!process_sp) 3957 process_sp = target_sp->GetProcessSP(); 3958 3959 if (process_sp) 3960 { 3961 m_mod_id = process_sp->GetModID(); 3962 m_exe_ctx_ref.SetProcessSP (process_sp); 3963 3964 ThreadSP thread_sp (exe_ctx.GetThreadSP()); 3965 3966 if (!thread_sp) 3967 { 3968 if (use_selected) 3969 thread_sp = process_sp->GetThreadList().GetSelectedThread(); 3970 } 3971 3972 if (thread_sp) 3973 { 3974 m_exe_ctx_ref.SetThreadSP(thread_sp); 3975 3976 StackFrameSP frame_sp (exe_ctx.GetFrameSP()); 3977 if (!frame_sp) 3978 { 3979 if (use_selected) 3980 frame_sp = thread_sp->GetSelectedFrame(); 3981 } 3982 if (frame_sp) 3983 m_exe_ctx_ref.SetFrameSP(frame_sp); 3984 } 3985 } 3986 } 3987 } 3988 3989 ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : 3990 m_mod_id(), 3991 m_exe_ctx_ref(rhs.m_exe_ctx_ref), 3992 m_needs_update (true) 3993 { 3994 } 3995 3996 ValueObject::EvaluationPoint::~EvaluationPoint () 3997 { 3998 } 3999 4000 // This function checks the EvaluationPoint against the current process state. If the current 4001 // state matches the evaluation point, or the evaluation point is already invalid, then we return 4002 // false, meaning "no change". If the current state is different, we update our state, and return 4003 // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so 4004 // future calls to NeedsUpdate will return true. 4005 // exe_scope will be set to the current execution context scope. 4006 4007 bool 4008 ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx) 4009 { 4010 // Start with the target, if it is NULL, then we're obviously not going to get any further: 4011 const bool thread_and_frame_only_if_stopped = true; 4012 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped)); 4013 4014 if (exe_ctx.GetTargetPtr() == NULL) 4015 return false; 4016 4017 // If we don't have a process nothing can change. 4018 Process *process = exe_ctx.GetProcessPtr(); 4019 if (process == NULL) 4020 return false; 4021 4022 // If our stop id is the current stop ID, nothing has changed: 4023 ProcessModID current_mod_id = process->GetModID(); 4024 4025 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared. 4026 // In either case, we aren't going to be able to sync with the process state. 4027 if (current_mod_id.GetStopID() == 0) 4028 return false; 4029 4030 bool changed = false; 4031 const bool was_valid = m_mod_id.IsValid(); 4032 if (was_valid) 4033 { 4034 if (m_mod_id == current_mod_id) 4035 { 4036 // Everything is already up to date in this object, no need to 4037 // update the execution context scope. 4038 changed = false; 4039 } 4040 else 4041 { 4042 m_mod_id = current_mod_id; 4043 m_needs_update = true; 4044 changed = true; 4045 } 4046 } 4047 4048 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated. 4049 // That way we'll be sure to return a valid exe_scope. 4050 // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid. 4051 4052 if (!accept_invalid_exe_ctx) 4053 { 4054 if (m_exe_ctx_ref.HasThreadRef()) 4055 { 4056 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP()); 4057 if (thread_sp) 4058 { 4059 if (m_exe_ctx_ref.HasFrameRef()) 4060 { 4061 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP()); 4062 if (!frame_sp) 4063 { 4064 // We used to have a frame, but now it is gone 4065 SetInvalid(); 4066 changed = was_valid; 4067 } 4068 } 4069 } 4070 else 4071 { 4072 // We used to have a thread, but now it is gone 4073 SetInvalid(); 4074 changed = was_valid; 4075 } 4076 } 4077 } 4078 4079 return changed; 4080 } 4081 4082 void 4083 ValueObject::EvaluationPoint::SetUpdated () 4084 { 4085 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP()); 4086 if (process_sp) 4087 m_mod_id = process_sp->GetModID(); 4088 m_needs_update = false; 4089 } 4090 4091 4092 4093 void 4094 ValueObject::ClearUserVisibleData(uint32_t clear_mask) 4095 { 4096 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue) 4097 m_value_str.clear(); 4098 4099 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation) 4100 m_location_str.clear(); 4101 4102 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary) 4103 m_summary_str.clear(); 4104 4105 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription) 4106 m_object_desc_str.clear(); 4107 4108 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren) 4109 { 4110 if (m_synthetic_value) 4111 m_synthetic_value = NULL; 4112 } 4113 4114 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator) 4115 m_validation_result.reset(); 4116 } 4117 4118 SymbolContextScope * 4119 ValueObject::GetSymbolContextScope() 4120 { 4121 if (m_parent) 4122 { 4123 if (!m_parent->IsPointerOrReferenceType()) 4124 return m_parent->GetSymbolContextScope(); 4125 } 4126 return NULL; 4127 } 4128 4129 lldb::ValueObjectSP 4130 ValueObject::CreateValueObjectFromExpression (const char* name, 4131 const char* expression, 4132 const ExecutionContext& exe_ctx) 4133 { 4134 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions()); 4135 } 4136 4137 4138 lldb::ValueObjectSP 4139 ValueObject::CreateValueObjectFromExpression (const char* name, 4140 const char* expression, 4141 const ExecutionContext& exe_ctx, 4142 const EvaluateExpressionOptions& options) 4143 { 4144 lldb::ValueObjectSP retval_sp; 4145 lldb::TargetSP target_sp(exe_ctx.GetTargetSP()); 4146 if (!target_sp) 4147 return retval_sp; 4148 if (!expression || !*expression) 4149 return retval_sp; 4150 target_sp->EvaluateExpression (expression, 4151 exe_ctx.GetFrameSP().get(), 4152 retval_sp, 4153 options); 4154 if (retval_sp && name && *name) 4155 retval_sp->SetName(ConstString(name)); 4156 return retval_sp; 4157 } 4158 4159 lldb::ValueObjectSP 4160 ValueObject::CreateValueObjectFromAddress (const char* name, 4161 uint64_t address, 4162 const ExecutionContext& exe_ctx, 4163 CompilerType type) 4164 { 4165 if (type) 4166 { 4167 CompilerType pointer_type(type.GetPointerType()); 4168 if (pointer_type) 4169 { 4170 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); 4171 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), 4172 pointer_type, 4173 ConstString(name), 4174 buffer, 4175 exe_ctx.GetByteOrder(), 4176 exe_ctx.GetAddressByteSize())); 4177 if (ptr_result_valobj_sp) 4178 { 4179 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); 4180 Error err; 4181 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err); 4182 if (ptr_result_valobj_sp && name && *name) 4183 ptr_result_valobj_sp->SetName(ConstString(name)); 4184 } 4185 return ptr_result_valobj_sp; 4186 } 4187 } 4188 return lldb::ValueObjectSP(); 4189 } 4190 4191 lldb::ValueObjectSP 4192 ValueObject::CreateValueObjectFromData (const char* name, 4193 const DataExtractor& data, 4194 const ExecutionContext& exe_ctx, 4195 CompilerType type) 4196 { 4197 lldb::ValueObjectSP new_value_sp; 4198 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), 4199 type, 4200 ConstString(name), 4201 data, 4202 LLDB_INVALID_ADDRESS); 4203 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); 4204 if (new_value_sp && name && *name) 4205 new_value_sp->SetName(ConstString(name)); 4206 return new_value_sp; 4207 } 4208 4209 ModuleSP 4210 ValueObject::GetModule () 4211 { 4212 ValueObject* root(GetRoot()); 4213 if (root != this) 4214 return root->GetModule(); 4215 return lldb::ModuleSP(); 4216 } 4217 4218 ValueObject* 4219 ValueObject::GetRoot () 4220 { 4221 if (m_root) 4222 return m_root; 4223 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool { 4224 return (vo->m_parent != nullptr); 4225 })); 4226 } 4227 4228 ValueObject* 4229 ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f) 4230 { 4231 ValueObject* vo = this; 4232 while (vo) 4233 { 4234 if (f(vo) == false) 4235 break; 4236 vo = vo->m_parent; 4237 } 4238 return vo; 4239 } 4240 4241 AddressType 4242 ValueObject::GetAddressTypeOfChildren() 4243 { 4244 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) 4245 { 4246 ValueObject* root(GetRoot()); 4247 if (root != this) 4248 return root->GetAddressTypeOfChildren(); 4249 } 4250 return m_address_type_of_ptr_or_ref_children; 4251 } 4252 4253 lldb::DynamicValueType 4254 ValueObject::GetDynamicValueType () 4255 { 4256 ValueObject* with_dv_info = this; 4257 while (with_dv_info) 4258 { 4259 if (with_dv_info->HasDynamicValueTypeInfo()) 4260 return with_dv_info->GetDynamicValueTypeImpl(); 4261 with_dv_info = with_dv_info->m_parent; 4262 } 4263 return lldb::eNoDynamicValues; 4264 } 4265 4266 lldb::Format 4267 ValueObject::GetFormat () const 4268 { 4269 const ValueObject* with_fmt_info = this; 4270 while (with_fmt_info) 4271 { 4272 if (with_fmt_info->m_format != lldb::eFormatDefault) 4273 return with_fmt_info->m_format; 4274 with_fmt_info = with_fmt_info->m_parent; 4275 } 4276 return m_format; 4277 } 4278 4279 lldb::LanguageType 4280 ValueObject::GetPreferredDisplayLanguage () 4281 { 4282 lldb::LanguageType type = m_preferred_display_language; 4283 if (m_preferred_display_language == lldb::eLanguageTypeUnknown) 4284 { 4285 if (GetRoot()) 4286 { 4287 if (GetRoot() == this) 4288 { 4289 if (StackFrameSP frame_sp = GetFrameSP()) 4290 { 4291 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit)); 4292 if (CompileUnit* cu = sc.comp_unit) 4293 type = cu->GetLanguage(); 4294 } 4295 } 4296 else 4297 { 4298 type = GetRoot()->GetPreferredDisplayLanguage(); 4299 } 4300 } 4301 } 4302 return (m_preferred_display_language = type); // only compute it once 4303 } 4304 4305 void 4306 ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt) 4307 { 4308 m_preferred_display_language = lt; 4309 } 4310 4311 void 4312 ValueObject::SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType lt) 4313 { 4314 if (m_preferred_display_language == lldb::eLanguageTypeUnknown) 4315 SetPreferredDisplayLanguage(lt); 4316 } 4317 4318 bool 4319 ValueObject::CanProvideValue () 4320 { 4321 // we need to support invalid types as providers of values because some bare-board 4322 // debugging scenarios have no notion of types, but still manage to have raw numeric 4323 // values for things like registers. sigh. 4324 const CompilerType &type(GetCompilerType()); 4325 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue)); 4326 } 4327 4328 bool 4329 ValueObject::IsChecksumEmpty () 4330 { 4331 return m_value_checksum.empty(); 4332 } 4333 4334 ValueObjectSP 4335 ValueObject::Persist () 4336 { 4337 if (!UpdateValueIfNeeded()) 4338 return nullptr; 4339 4340 TargetSP target_sp(GetTargetSP()); 4341 if (!target_sp) 4342 return nullptr; 4343 4344 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage()); 4345 4346 if (!persistent_state) 4347 return nullptr; 4348 4349 ConstString name(persistent_state->GetNextPersistentVariableName()); 4350 4351 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name); 4352 4353 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp); 4354 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp; 4355 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference; 4356 4357 return clang_var_sp->GetValueObject(); 4358 } 4359 4360 bool 4361 ValueObject::IsSyntheticChildrenGenerated () 4362 { 4363 return m_is_synthetic_children_generated; 4364 } 4365 4366 void 4367 ValueObject::SetSyntheticChildrenGenerated (bool b) 4368 { 4369 m_is_synthetic_children_generated = b; 4370 } 4371