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