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