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