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