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