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