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