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