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