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