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