1 //===-- CompilerType.cpp --------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Symbol/CompilerType.h" 10 11 #include "lldb/Core/Debugger.h" 12 #include "lldb/Core/StreamFile.h" 13 #include "lldb/Symbol/Type.h" 14 #include "lldb/Target/ExecutionContext.h" 15 #include "lldb/Target/Process.h" 16 #include "lldb/Utility/ConstString.h" 17 #include "lldb/Utility/DataBufferHeap.h" 18 #include "lldb/Utility/DataExtractor.h" 19 #include "lldb/Utility/Scalar.h" 20 #include "lldb/Utility/Stream.h" 21 #include "lldb/Utility/StreamString.h" 22 23 #include <iterator> 24 #include <mutex> 25 26 using namespace lldb; 27 using namespace lldb_private; 28 29 // Tests 30 31 bool CompilerType::IsAggregateType() const { 32 if (IsValid()) 33 return m_type_system->IsAggregateType(m_type); 34 return false; 35 } 36 37 bool CompilerType::IsAnonymousType() const { 38 if (IsValid()) 39 return m_type_system->IsAnonymousType(m_type); 40 return false; 41 } 42 43 bool CompilerType::IsScopedEnumerationType() const { 44 if (IsValid()) 45 return m_type_system->IsScopedEnumerationType(m_type); 46 return false; 47 } 48 49 bool CompilerType::IsArrayType(CompilerType *element_type_ptr, uint64_t *size, 50 bool *is_incomplete) const { 51 if (IsValid()) 52 return m_type_system->IsArrayType(m_type, element_type_ptr, size, 53 is_incomplete); 54 55 if (element_type_ptr) 56 element_type_ptr->Clear(); 57 if (size) 58 *size = 0; 59 if (is_incomplete) 60 *is_incomplete = false; 61 return false; 62 } 63 64 bool CompilerType::IsVectorType(CompilerType *element_type, 65 uint64_t *size) const { 66 if (IsValid()) 67 return m_type_system->IsVectorType(m_type, element_type, size); 68 return false; 69 } 70 71 bool CompilerType::IsRuntimeGeneratedType() const { 72 if (IsValid()) 73 return m_type_system->IsRuntimeGeneratedType(m_type); 74 return false; 75 } 76 77 bool CompilerType::IsCharType() const { 78 if (IsValid()) 79 return m_type_system->IsCharType(m_type); 80 return false; 81 } 82 83 bool CompilerType::IsCompleteType() const { 84 if (IsValid()) 85 return m_type_system->IsCompleteType(m_type); 86 return false; 87 } 88 89 bool CompilerType::IsConst() const { 90 if (IsValid()) 91 return m_type_system->IsConst(m_type); 92 return false; 93 } 94 95 bool CompilerType::IsCStringType(uint32_t &length) const { 96 if (IsValid()) 97 return m_type_system->IsCStringType(m_type, length); 98 return false; 99 } 100 101 bool CompilerType::IsFunctionType() const { 102 if (IsValid()) 103 return m_type_system->IsFunctionType(m_type); 104 return false; 105 } 106 107 // Used to detect "Homogeneous Floating-point Aggregates" 108 uint32_t 109 CompilerType::IsHomogeneousAggregate(CompilerType *base_type_ptr) const { 110 if (IsValid()) 111 return m_type_system->IsHomogeneousAggregate(m_type, base_type_ptr); 112 return 0; 113 } 114 115 size_t CompilerType::GetNumberOfFunctionArguments() const { 116 if (IsValid()) 117 return m_type_system->GetNumberOfFunctionArguments(m_type); 118 return 0; 119 } 120 121 CompilerType 122 CompilerType::GetFunctionArgumentAtIndex(const size_t index) const { 123 if (IsValid()) 124 return m_type_system->GetFunctionArgumentAtIndex(m_type, index); 125 return CompilerType(); 126 } 127 128 bool CompilerType::IsFunctionPointerType() const { 129 if (IsValid()) 130 return m_type_system->IsFunctionPointerType(m_type); 131 return false; 132 } 133 134 bool CompilerType::IsBlockPointerType( 135 CompilerType *function_pointer_type_ptr) const { 136 if (IsValid()) 137 return m_type_system->IsBlockPointerType(m_type, function_pointer_type_ptr); 138 return false; 139 } 140 141 bool CompilerType::IsIntegerType(bool &is_signed) const { 142 if (IsValid()) 143 return m_type_system->IsIntegerType(m_type, is_signed); 144 return false; 145 } 146 147 bool CompilerType::IsEnumerationType(bool &is_signed) const { 148 if (IsValid()) 149 return m_type_system->IsEnumerationType(m_type, is_signed); 150 return false; 151 } 152 153 bool CompilerType::IsIntegerOrEnumerationType(bool &is_signed) const { 154 return IsIntegerType(is_signed) || IsEnumerationType(is_signed); 155 } 156 157 bool CompilerType::IsPointerType(CompilerType *pointee_type) const { 158 if (IsValid()) { 159 return m_type_system->IsPointerType(m_type, pointee_type); 160 } 161 if (pointee_type) 162 pointee_type->Clear(); 163 return false; 164 } 165 166 bool CompilerType::IsPointerOrReferenceType(CompilerType *pointee_type) const { 167 if (IsValid()) { 168 return m_type_system->IsPointerOrReferenceType(m_type, pointee_type); 169 } 170 if (pointee_type) 171 pointee_type->Clear(); 172 return false; 173 } 174 175 bool CompilerType::IsReferenceType(CompilerType *pointee_type, 176 bool *is_rvalue) const { 177 if (IsValid()) { 178 return m_type_system->IsReferenceType(m_type, pointee_type, is_rvalue); 179 } 180 if (pointee_type) 181 pointee_type->Clear(); 182 return false; 183 } 184 185 bool CompilerType::ShouldTreatScalarValueAsAddress() const { 186 if (IsValid()) 187 return m_type_system->ShouldTreatScalarValueAsAddress(m_type); 188 return false; 189 } 190 191 bool CompilerType::IsFloatingPointType(uint32_t &count, 192 bool &is_complex) const { 193 if (IsValid()) { 194 return m_type_system->IsFloatingPointType(m_type, count, is_complex); 195 } 196 count = 0; 197 is_complex = false; 198 return false; 199 } 200 201 bool CompilerType::IsDefined() const { 202 if (IsValid()) 203 return m_type_system->IsDefined(m_type); 204 return true; 205 } 206 207 bool CompilerType::IsPolymorphicClass() const { 208 if (IsValid()) { 209 return m_type_system->IsPolymorphicClass(m_type); 210 } 211 return false; 212 } 213 214 bool CompilerType::IsPossibleDynamicType(CompilerType *dynamic_pointee_type, 215 bool check_cplusplus, 216 bool check_objc) const { 217 if (IsValid()) 218 return m_type_system->IsPossibleDynamicType(m_type, dynamic_pointee_type, 219 check_cplusplus, check_objc); 220 return false; 221 } 222 223 bool CompilerType::IsScalarType() const { 224 if (!IsValid()) 225 return false; 226 227 return m_type_system->IsScalarType(m_type); 228 } 229 230 bool CompilerType::IsTypedefType() const { 231 if (!IsValid()) 232 return false; 233 return m_type_system->IsTypedefType(m_type); 234 } 235 236 bool CompilerType::IsVoidType() const { 237 if (!IsValid()) 238 return false; 239 return m_type_system->IsVoidType(m_type); 240 } 241 242 bool CompilerType::IsPointerToScalarType() const { 243 if (!IsValid()) 244 return false; 245 246 return IsPointerType() && GetPointeeType().IsScalarType(); 247 } 248 249 bool CompilerType::IsArrayOfScalarType() const { 250 CompilerType element_type; 251 if (IsArrayType(&element_type, nullptr, nullptr)) 252 return element_type.IsScalarType(); 253 return false; 254 } 255 256 bool CompilerType::IsBeingDefined() const { 257 if (!IsValid()) 258 return false; 259 return m_type_system->IsBeingDefined(m_type); 260 } 261 262 // Type Completion 263 264 bool CompilerType::GetCompleteType() const { 265 if (!IsValid()) 266 return false; 267 return m_type_system->GetCompleteType(m_type); 268 } 269 270 // AST related queries 271 size_t CompilerType::GetPointerByteSize() const { 272 if (m_type_system) 273 return m_type_system->GetPointerByteSize(); 274 return 0; 275 } 276 277 ConstString CompilerType::GetTypeName() const { 278 if (IsValid()) { 279 return m_type_system->GetTypeName(m_type); 280 } 281 return ConstString("<invalid>"); 282 } 283 284 ConstString CompilerType::GetDisplayTypeName() const { 285 if (IsValid()) 286 return m_type_system->GetDisplayTypeName(m_type); 287 return ConstString("<invalid>"); 288 } 289 290 uint32_t CompilerType::GetTypeInfo( 291 CompilerType *pointee_or_element_compiler_type) const { 292 if (!IsValid()) 293 return 0; 294 295 return m_type_system->GetTypeInfo(m_type, pointee_or_element_compiler_type); 296 } 297 298 lldb::LanguageType CompilerType::GetMinimumLanguage() { 299 if (!IsValid()) 300 return lldb::eLanguageTypeC; 301 302 return m_type_system->GetMinimumLanguage(m_type); 303 } 304 305 lldb::TypeClass CompilerType::GetTypeClass() const { 306 if (!IsValid()) 307 return lldb::eTypeClassInvalid; 308 309 return m_type_system->GetTypeClass(m_type); 310 } 311 312 void CompilerType::SetCompilerType(TypeSystem *type_system, 313 lldb::opaque_compiler_type_t type) { 314 m_type_system = type_system; 315 m_type = type; 316 } 317 318 unsigned CompilerType::GetTypeQualifiers() const { 319 if (IsValid()) 320 return m_type_system->GetTypeQualifiers(m_type); 321 return 0; 322 } 323 324 // Creating related types 325 326 CompilerType 327 CompilerType::GetArrayElementType(ExecutionContextScope *exe_scope) const { 328 if (IsValid()) { 329 return m_type_system->GetArrayElementType(m_type, exe_scope); 330 } 331 return CompilerType(); 332 } 333 334 CompilerType CompilerType::GetArrayType(uint64_t size) const { 335 if (IsValid()) { 336 return m_type_system->GetArrayType(m_type, size); 337 } 338 return CompilerType(); 339 } 340 341 CompilerType CompilerType::GetCanonicalType() const { 342 if (IsValid()) 343 return m_type_system->GetCanonicalType(m_type); 344 return CompilerType(); 345 } 346 347 CompilerType CompilerType::GetFullyUnqualifiedType() const { 348 if (IsValid()) 349 return m_type_system->GetFullyUnqualifiedType(m_type); 350 return CompilerType(); 351 } 352 353 int CompilerType::GetFunctionArgumentCount() const { 354 if (IsValid()) { 355 return m_type_system->GetFunctionArgumentCount(m_type); 356 } 357 return -1; 358 } 359 360 CompilerType CompilerType::GetFunctionArgumentTypeAtIndex(size_t idx) const { 361 if (IsValid()) { 362 return m_type_system->GetFunctionArgumentTypeAtIndex(m_type, idx); 363 } 364 return CompilerType(); 365 } 366 367 CompilerType CompilerType::GetFunctionReturnType() const { 368 if (IsValid()) { 369 return m_type_system->GetFunctionReturnType(m_type); 370 } 371 return CompilerType(); 372 } 373 374 size_t CompilerType::GetNumMemberFunctions() const { 375 if (IsValid()) { 376 return m_type_system->GetNumMemberFunctions(m_type); 377 } 378 return 0; 379 } 380 381 TypeMemberFunctionImpl CompilerType::GetMemberFunctionAtIndex(size_t idx) { 382 if (IsValid()) { 383 return m_type_system->GetMemberFunctionAtIndex(m_type, idx); 384 } 385 return TypeMemberFunctionImpl(); 386 } 387 388 CompilerType CompilerType::GetNonReferenceType() const { 389 if (IsValid()) 390 return m_type_system->GetNonReferenceType(m_type); 391 return CompilerType(); 392 } 393 394 CompilerType CompilerType::GetPointeeType() const { 395 if (IsValid()) { 396 return m_type_system->GetPointeeType(m_type); 397 } 398 return CompilerType(); 399 } 400 401 CompilerType CompilerType::GetPointerType() const { 402 if (IsValid()) { 403 return m_type_system->GetPointerType(m_type); 404 } 405 return CompilerType(); 406 } 407 408 CompilerType CompilerType::GetLValueReferenceType() const { 409 if (IsValid()) 410 return m_type_system->GetLValueReferenceType(m_type); 411 else 412 return CompilerType(); 413 } 414 415 CompilerType CompilerType::GetRValueReferenceType() const { 416 if (IsValid()) 417 return m_type_system->GetRValueReferenceType(m_type); 418 else 419 return CompilerType(); 420 } 421 422 CompilerType CompilerType::GetAtomicType() const { 423 if (IsValid()) 424 return m_type_system->GetAtomicType(m_type); 425 return CompilerType(); 426 } 427 428 CompilerType CompilerType::AddConstModifier() const { 429 if (IsValid()) 430 return m_type_system->AddConstModifier(m_type); 431 else 432 return CompilerType(); 433 } 434 435 CompilerType CompilerType::AddVolatileModifier() const { 436 if (IsValid()) 437 return m_type_system->AddVolatileModifier(m_type); 438 else 439 return CompilerType(); 440 } 441 442 CompilerType CompilerType::AddRestrictModifier() const { 443 if (IsValid()) 444 return m_type_system->AddRestrictModifier(m_type); 445 else 446 return CompilerType(); 447 } 448 449 CompilerType CompilerType::CreateTypedef(const char *name, 450 const CompilerDeclContext &decl_ctx, 451 uint32_t payload) const { 452 if (IsValid()) 453 return m_type_system->CreateTypedef(m_type, name, decl_ctx, payload); 454 else 455 return CompilerType(); 456 } 457 458 CompilerType CompilerType::GetTypedefedType() const { 459 if (IsValid()) 460 return m_type_system->GetTypedefedType(m_type); 461 else 462 return CompilerType(); 463 } 464 465 // Create related types using the current type's AST 466 467 CompilerType 468 CompilerType::GetBasicTypeFromAST(lldb::BasicType basic_type) const { 469 if (IsValid()) 470 return m_type_system->GetBasicTypeFromAST(basic_type); 471 return CompilerType(); 472 } 473 // Exploring the type 474 475 llvm::Optional<uint64_t> 476 CompilerType::GetBitSize(ExecutionContextScope *exe_scope) const { 477 if (IsValid()) 478 return m_type_system->GetBitSize(m_type, exe_scope); 479 return {}; 480 } 481 482 llvm::Optional<uint64_t> 483 CompilerType::GetByteSize(ExecutionContextScope *exe_scope) const { 484 if (llvm::Optional<uint64_t> bit_size = GetBitSize(exe_scope)) 485 return (*bit_size + 7) / 8; 486 return {}; 487 } 488 489 llvm::Optional<size_t> CompilerType::GetTypeBitAlign(ExecutionContextScope *exe_scope) const { 490 if (IsValid()) 491 return m_type_system->GetTypeBitAlign(m_type, exe_scope); 492 return {}; 493 } 494 495 lldb::Encoding CompilerType::GetEncoding(uint64_t &count) const { 496 if (!IsValid()) 497 return lldb::eEncodingInvalid; 498 499 return m_type_system->GetEncoding(m_type, count); 500 } 501 502 lldb::Format CompilerType::GetFormat() const { 503 if (!IsValid()) 504 return lldb::eFormatDefault; 505 506 return m_type_system->GetFormat(m_type); 507 } 508 509 uint32_t CompilerType::GetNumChildren(bool omit_empty_base_classes, 510 const ExecutionContext *exe_ctx) const { 511 if (!IsValid()) 512 return 0; 513 return m_type_system->GetNumChildren(m_type, omit_empty_base_classes, 514 exe_ctx); 515 } 516 517 lldb::BasicType CompilerType::GetBasicTypeEnumeration() const { 518 if (IsValid()) 519 return m_type_system->GetBasicTypeEnumeration(m_type); 520 return eBasicTypeInvalid; 521 } 522 523 void CompilerType::ForEachEnumerator( 524 std::function<bool(const CompilerType &integer_type, 525 ConstString name, 526 const llvm::APSInt &value)> const &callback) const { 527 if (IsValid()) 528 return m_type_system->ForEachEnumerator(m_type, callback); 529 } 530 531 uint32_t CompilerType::GetNumFields() const { 532 if (!IsValid()) 533 return 0; 534 return m_type_system->GetNumFields(m_type); 535 } 536 537 CompilerType CompilerType::GetFieldAtIndex(size_t idx, std::string &name, 538 uint64_t *bit_offset_ptr, 539 uint32_t *bitfield_bit_size_ptr, 540 bool *is_bitfield_ptr) const { 541 if (!IsValid()) 542 return CompilerType(); 543 return m_type_system->GetFieldAtIndex(m_type, idx, name, bit_offset_ptr, 544 bitfield_bit_size_ptr, is_bitfield_ptr); 545 } 546 547 uint32_t CompilerType::GetNumDirectBaseClasses() const { 548 if (IsValid()) 549 return m_type_system->GetNumDirectBaseClasses(m_type); 550 return 0; 551 } 552 553 uint32_t CompilerType::GetNumVirtualBaseClasses() const { 554 if (IsValid()) 555 return m_type_system->GetNumVirtualBaseClasses(m_type); 556 return 0; 557 } 558 559 CompilerType 560 CompilerType::GetDirectBaseClassAtIndex(size_t idx, 561 uint32_t *bit_offset_ptr) const { 562 if (IsValid()) 563 return m_type_system->GetDirectBaseClassAtIndex(m_type, idx, 564 bit_offset_ptr); 565 return CompilerType(); 566 } 567 568 CompilerType 569 CompilerType::GetVirtualBaseClassAtIndex(size_t idx, 570 uint32_t *bit_offset_ptr) const { 571 if (IsValid()) 572 return m_type_system->GetVirtualBaseClassAtIndex(m_type, idx, 573 bit_offset_ptr); 574 return CompilerType(); 575 } 576 577 uint32_t CompilerType::GetIndexOfFieldWithName( 578 const char *name, CompilerType *field_compiler_type_ptr, 579 uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, 580 bool *is_bitfield_ptr) const { 581 unsigned count = GetNumFields(); 582 std::string field_name; 583 for (unsigned index = 0; index < count; index++) { 584 CompilerType field_compiler_type( 585 GetFieldAtIndex(index, field_name, bit_offset_ptr, 586 bitfield_bit_size_ptr, is_bitfield_ptr)); 587 if (strcmp(field_name.c_str(), name) == 0) { 588 if (field_compiler_type_ptr) 589 *field_compiler_type_ptr = field_compiler_type; 590 return index; 591 } 592 } 593 return UINT32_MAX; 594 } 595 596 CompilerType CompilerType::GetChildCompilerTypeAtIndex( 597 ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, 598 bool omit_empty_base_classes, bool ignore_array_bounds, 599 std::string &child_name, uint32_t &child_byte_size, 600 int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, 601 uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, 602 bool &child_is_deref_of_parent, ValueObject *valobj, 603 uint64_t &language_flags) const { 604 if (!IsValid()) 605 return CompilerType(); 606 return m_type_system->GetChildCompilerTypeAtIndex( 607 m_type, exe_ctx, idx, transparent_pointers, omit_empty_base_classes, 608 ignore_array_bounds, child_name, child_byte_size, child_byte_offset, 609 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, 610 child_is_deref_of_parent, valobj, language_flags); 611 } 612 613 // Look for a child member (doesn't include base classes, but it does include 614 // their members) in the type hierarchy. Returns an index path into 615 // "clang_type" on how to reach the appropriate member. 616 // 617 // class A 618 // { 619 // public: 620 // int m_a; 621 // int m_b; 622 // }; 623 // 624 // class B 625 // { 626 // }; 627 // 628 // class C : 629 // public B, 630 // public A 631 // { 632 // }; 633 // 634 // If we have a clang type that describes "class C", and we wanted to looked 635 // "m_b" in it: 636 // 637 // With omit_empty_base_classes == false we would get an integer array back 638 // with: { 1, 1 } The first index 1 is the child index for "class A" within 639 // class C The second index 1 is the child index for "m_b" within class A 640 // 641 // With omit_empty_base_classes == true we would get an integer array back 642 // with: { 0, 1 } The first index 0 is the child index for "class A" within 643 // class C (since class B doesn't have any members it doesn't count) The second 644 // index 1 is the child index for "m_b" within class A 645 646 size_t CompilerType::GetIndexOfChildMemberWithName( 647 const char *name, bool omit_empty_base_classes, 648 std::vector<uint32_t> &child_indexes) const { 649 if (IsValid() && name && name[0]) { 650 return m_type_system->GetIndexOfChildMemberWithName( 651 m_type, name, omit_empty_base_classes, child_indexes); 652 } 653 return 0; 654 } 655 656 size_t CompilerType::GetNumTemplateArguments() const { 657 if (IsValid()) { 658 return m_type_system->GetNumTemplateArguments(m_type); 659 } 660 return 0; 661 } 662 663 TemplateArgumentKind CompilerType::GetTemplateArgumentKind(size_t idx) const { 664 if (IsValid()) 665 return m_type_system->GetTemplateArgumentKind(m_type, idx); 666 return eTemplateArgumentKindNull; 667 } 668 669 CompilerType CompilerType::GetTypeTemplateArgument(size_t idx) const { 670 if (IsValid()) { 671 return m_type_system->GetTypeTemplateArgument(m_type, idx); 672 } 673 return CompilerType(); 674 } 675 676 llvm::Optional<CompilerType::IntegralTemplateArgument> 677 CompilerType::GetIntegralTemplateArgument(size_t idx) const { 678 if (IsValid()) 679 return m_type_system->GetIntegralTemplateArgument(m_type, idx); 680 return llvm::None; 681 } 682 683 CompilerType CompilerType::GetTypeForFormatters() const { 684 if (IsValid()) 685 return m_type_system->GetTypeForFormatters(m_type); 686 return CompilerType(); 687 } 688 689 LazyBool CompilerType::ShouldPrintAsOneLiner(ValueObject *valobj) const { 690 if (IsValid()) 691 return m_type_system->ShouldPrintAsOneLiner(m_type, valobj); 692 return eLazyBoolCalculate; 693 } 694 695 bool CompilerType::IsMeaninglessWithoutDynamicResolution() const { 696 if (IsValid()) 697 return m_type_system->IsMeaninglessWithoutDynamicResolution(m_type); 698 return false; 699 } 700 701 // Get the index of the child of "clang_type" whose name matches. This function 702 // doesn't descend into the children, but only looks one level deep and name 703 // matches can include base class names. 704 705 uint32_t 706 CompilerType::GetIndexOfChildWithName(const char *name, 707 bool omit_empty_base_classes) const { 708 if (IsValid() && name && name[0]) { 709 return m_type_system->GetIndexOfChildWithName(m_type, name, 710 omit_empty_base_classes); 711 } 712 return UINT32_MAX; 713 } 714 715 // Dumping types 716 717 void CompilerType::DumpValue(ExecutionContext *exe_ctx, Stream *s, 718 lldb::Format format, const DataExtractor &data, 719 lldb::offset_t data_byte_offset, 720 size_t data_byte_size, uint32_t bitfield_bit_size, 721 uint32_t bitfield_bit_offset, bool show_types, 722 bool show_summary, bool verbose, uint32_t depth) { 723 if (!IsValid()) 724 return; 725 m_type_system->DumpValue(m_type, exe_ctx, s, format, data, data_byte_offset, 726 data_byte_size, bitfield_bit_size, 727 bitfield_bit_offset, show_types, show_summary, 728 verbose, depth); 729 } 730 731 bool CompilerType::DumpTypeValue(Stream *s, lldb::Format format, 732 const DataExtractor &data, 733 lldb::offset_t byte_offset, size_t byte_size, 734 uint32_t bitfield_bit_size, 735 uint32_t bitfield_bit_offset, 736 ExecutionContextScope *exe_scope) { 737 if (!IsValid()) 738 return false; 739 return m_type_system->DumpTypeValue(m_type, s, format, data, byte_offset, 740 byte_size, bitfield_bit_size, 741 bitfield_bit_offset, exe_scope); 742 } 743 744 void CompilerType::DumpSummary(ExecutionContext *exe_ctx, Stream *s, 745 const DataExtractor &data, 746 lldb::offset_t data_byte_offset, 747 size_t data_byte_size) { 748 if (IsValid()) 749 m_type_system->DumpSummary(m_type, exe_ctx, s, data, data_byte_offset, 750 data_byte_size); 751 } 752 753 void CompilerType::DumpTypeDescription(lldb::DescriptionLevel level) const { 754 if (IsValid()) 755 m_type_system->DumpTypeDescription(m_type, level); 756 } 757 758 void CompilerType::DumpTypeDescription(Stream *s, 759 lldb::DescriptionLevel level) const { 760 if (IsValid()) { 761 m_type_system->DumpTypeDescription(m_type, s, level); 762 } 763 } 764 765 #ifndef NDEBUG 766 LLVM_DUMP_METHOD void CompilerType::dump() const { 767 if (IsValid()) 768 m_type_system->dump(m_type); 769 else 770 llvm::errs() << "<invalid>\n"; 771 } 772 #endif 773 774 bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data, 775 lldb::offset_t data_byte_offset, 776 size_t data_byte_size, Scalar &value, 777 ExecutionContextScope *exe_scope) const { 778 if (!IsValid()) 779 return false; 780 781 if (IsAggregateType()) { 782 return false; // Aggregate types don't have scalar values 783 } else { 784 uint64_t count = 0; 785 lldb::Encoding encoding = GetEncoding(count); 786 787 if (encoding == lldb::eEncodingInvalid || count != 1) 788 return false; 789 790 llvm::Optional<uint64_t> byte_size = GetByteSize(exe_scope); 791 if (!byte_size) 792 return false; 793 lldb::offset_t offset = data_byte_offset; 794 switch (encoding) { 795 case lldb::eEncodingInvalid: 796 break; 797 case lldb::eEncodingVector: 798 break; 799 case lldb::eEncodingUint: 800 if (*byte_size <= sizeof(unsigned long long)) { 801 uint64_t uval64 = data.GetMaxU64(&offset, *byte_size); 802 if (*byte_size <= sizeof(unsigned int)) { 803 value = (unsigned int)uval64; 804 return true; 805 } else if (*byte_size <= sizeof(unsigned long)) { 806 value = (unsigned long)uval64; 807 return true; 808 } else if (*byte_size <= sizeof(unsigned long long)) { 809 value = (unsigned long long)uval64; 810 return true; 811 } else 812 value.Clear(); 813 } 814 break; 815 816 case lldb::eEncodingSint: 817 if (*byte_size <= sizeof(long long)) { 818 int64_t sval64 = data.GetMaxS64(&offset, *byte_size); 819 if (*byte_size <= sizeof(int)) { 820 value = (int)sval64; 821 return true; 822 } else if (*byte_size <= sizeof(long)) { 823 value = (long)sval64; 824 return true; 825 } else if (*byte_size <= sizeof(long long)) { 826 value = (long long)sval64; 827 return true; 828 } else 829 value.Clear(); 830 } 831 break; 832 833 case lldb::eEncodingIEEE754: 834 if (*byte_size <= sizeof(long double)) { 835 uint32_t u32; 836 uint64_t u64; 837 if (*byte_size == sizeof(float)) { 838 if (sizeof(float) == sizeof(uint32_t)) { 839 u32 = data.GetU32(&offset); 840 value = *((float *)&u32); 841 return true; 842 } else if (sizeof(float) == sizeof(uint64_t)) { 843 u64 = data.GetU64(&offset); 844 value = *((float *)&u64); 845 return true; 846 } 847 } else if (*byte_size == sizeof(double)) { 848 if (sizeof(double) == sizeof(uint32_t)) { 849 u32 = data.GetU32(&offset); 850 value = *((double *)&u32); 851 return true; 852 } else if (sizeof(double) == sizeof(uint64_t)) { 853 u64 = data.GetU64(&offset); 854 value = *((double *)&u64); 855 return true; 856 } 857 } else if (*byte_size == sizeof(long double)) { 858 if (sizeof(long double) == sizeof(uint32_t)) { 859 u32 = data.GetU32(&offset); 860 value = *((long double *)&u32); 861 return true; 862 } else if (sizeof(long double) == sizeof(uint64_t)) { 863 u64 = data.GetU64(&offset); 864 value = *((long double *)&u64); 865 return true; 866 } 867 } 868 } 869 break; 870 } 871 } 872 return false; 873 } 874 875 #ifndef NDEBUG 876 bool CompilerType::Verify() const { 877 return !IsValid() || m_type_system->Verify(m_type); 878 } 879 #endif 880 881 bool lldb_private::operator==(const lldb_private::CompilerType &lhs, 882 const lldb_private::CompilerType &rhs) { 883 return lhs.GetTypeSystem() == rhs.GetTypeSystem() && 884 lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType(); 885 } 886 887 bool lldb_private::operator!=(const lldb_private::CompilerType &lhs, 888 const lldb_private::CompilerType &rhs) { 889 return !(lhs == rhs); 890 } 891