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