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