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