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