1 //===-- SBType.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/API/SBType.h" 10 #include "lldb/Utility/ReproducerInstrumentation.h" 11 #include "lldb/API/SBDefines.h" 12 #include "lldb/API/SBModule.h" 13 #include "lldb/API/SBStream.h" 14 #include "lldb/API/SBTypeEnumMember.h" 15 #include "lldb/Core/Mangled.h" 16 #include "lldb/Symbol/CompilerType.h" 17 #include "lldb/Symbol/Type.h" 18 #include "lldb/Symbol/TypeSystem.h" 19 #include "lldb/Utility/ConstString.h" 20 #include "lldb/Utility/Stream.h" 21 22 #include "llvm/ADT/APSInt.h" 23 24 #include <memory> 25 26 using namespace lldb; 27 using namespace lldb_private; 28 29 SBType::SBType() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBType); } 30 31 SBType::SBType(const CompilerType &type) 32 : m_opaque_sp(new TypeImpl( 33 CompilerType(type.GetTypeSystem(), type.GetOpaqueQualType()))) {} 34 35 SBType::SBType(const lldb::TypeSP &type_sp) 36 : m_opaque_sp(new TypeImpl(type_sp)) {} 37 38 SBType::SBType(const lldb::TypeImplSP &type_impl_sp) 39 : m_opaque_sp(type_impl_sp) {} 40 41 SBType::SBType(const SBType &rhs) { 42 LLDB_RECORD_CONSTRUCTOR(SBType, (const lldb::SBType &), rhs); 43 44 if (this != &rhs) { 45 m_opaque_sp = rhs.m_opaque_sp; 46 } 47 } 48 49 // SBType::SBType (TypeImpl* impl) : 50 // m_opaque_up(impl) 51 //{} 52 // 53 bool SBType::operator==(SBType &rhs) { 54 LLDB_RECORD_METHOD(bool, SBType, operator==,(lldb::SBType &), rhs); 55 56 if (!IsValid()) 57 return !rhs.IsValid(); 58 59 if (!rhs.IsValid()) 60 return false; 61 62 return *m_opaque_sp.get() == *rhs.m_opaque_sp.get(); 63 } 64 65 bool SBType::operator!=(SBType &rhs) { 66 LLDB_RECORD_METHOD(bool, SBType, operator!=,(lldb::SBType &), rhs); 67 68 if (!IsValid()) 69 return rhs.IsValid(); 70 71 if (!rhs.IsValid()) 72 return true; 73 74 return *m_opaque_sp.get() != *rhs.m_opaque_sp.get(); 75 } 76 77 lldb::TypeImplSP SBType::GetSP() { return m_opaque_sp; } 78 79 void SBType::SetSP(const lldb::TypeImplSP &type_impl_sp) { 80 m_opaque_sp = type_impl_sp; 81 } 82 83 SBType &SBType::operator=(const SBType &rhs) { 84 LLDB_RECORD_METHOD(lldb::SBType &, SBType, operator=,(const lldb::SBType &), 85 rhs); 86 87 if (this != &rhs) { 88 m_opaque_sp = rhs.m_opaque_sp; 89 } 90 return *this; 91 } 92 93 SBType::~SBType() = default; 94 95 TypeImpl &SBType::ref() { 96 if (m_opaque_sp.get() == nullptr) 97 m_opaque_sp = std::make_shared<TypeImpl>(); 98 return *m_opaque_sp; 99 } 100 101 const TypeImpl &SBType::ref() const { 102 // "const SBAddress &addr" should already have checked "addr.IsValid()" prior 103 // to calling this function. In case you didn't we will assert and die to let 104 // you know. 105 assert(m_opaque_sp.get()); 106 return *m_opaque_sp; 107 } 108 109 bool SBType::IsValid() const { 110 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBType, IsValid); 111 return this->operator bool(); 112 } 113 SBType::operator bool() const { 114 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBType, operator bool); 115 116 if (m_opaque_sp.get() == nullptr) 117 return false; 118 119 return m_opaque_sp->IsValid(); 120 } 121 122 uint64_t SBType::GetByteSize() { 123 LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBType, GetByteSize); 124 125 if (IsValid()) 126 if (llvm::Optional<uint64_t> size = 127 m_opaque_sp->GetCompilerType(false).GetByteSize(nullptr)) 128 return *size; 129 return 0; 130 } 131 132 bool SBType::IsPointerType() { 133 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsPointerType); 134 135 if (!IsValid()) 136 return false; 137 return m_opaque_sp->GetCompilerType(true).IsPointerType(); 138 } 139 140 bool SBType::IsArrayType() { 141 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsArrayType); 142 143 if (!IsValid()) 144 return false; 145 return m_opaque_sp->GetCompilerType(true).IsArrayType(nullptr, nullptr, 146 nullptr); 147 } 148 149 bool SBType::IsVectorType() { 150 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsVectorType); 151 152 if (!IsValid()) 153 return false; 154 return m_opaque_sp->GetCompilerType(true).IsVectorType(nullptr, nullptr); 155 } 156 157 bool SBType::IsReferenceType() { 158 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsReferenceType); 159 160 if (!IsValid()) 161 return false; 162 return m_opaque_sp->GetCompilerType(true).IsReferenceType(); 163 } 164 165 SBType SBType::GetPointerType() { 166 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetPointerType); 167 168 if (!IsValid()) 169 return SBType(); 170 171 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointerType()))); 172 } 173 174 SBType SBType::GetPointeeType() { 175 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetPointeeType); 176 177 if (!IsValid()) 178 return SBType(); 179 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointeeType()))); 180 } 181 182 SBType SBType::GetReferenceType() { 183 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetReferenceType); 184 185 if (!IsValid()) 186 return SBType(); 187 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetReferenceType()))); 188 } 189 190 SBType SBType::GetTypedefedType() { 191 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetTypedefedType); 192 193 if (!IsValid()) 194 return SBType(); 195 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetTypedefedType()))); 196 } 197 198 SBType SBType::GetDereferencedType() { 199 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetDereferencedType); 200 201 if (!IsValid()) 202 return SBType(); 203 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetDereferencedType()))); 204 } 205 206 SBType SBType::GetArrayElementType() { 207 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetArrayElementType); 208 209 if (!IsValid()) 210 return SBType(); 211 return SBType(TypeImplSP(new TypeImpl( 212 m_opaque_sp->GetCompilerType(true).GetArrayElementType(nullptr)))); 213 } 214 215 SBType SBType::GetArrayType(uint64_t size) { 216 LLDB_RECORD_METHOD(lldb::SBType, SBType, GetArrayType, (uint64_t), size); 217 218 if (!IsValid()) 219 return SBType(); 220 return SBType(TypeImplSP( 221 new TypeImpl(m_opaque_sp->GetCompilerType(true).GetArrayType(size)))); 222 } 223 224 SBType SBType::GetVectorElementType() { 225 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetVectorElementType); 226 227 SBType type_sb; 228 if (IsValid()) { 229 CompilerType vector_element_type; 230 if (m_opaque_sp->GetCompilerType(true).IsVectorType(&vector_element_type, 231 nullptr)) 232 type_sb.SetSP(TypeImplSP(new TypeImpl(vector_element_type))); 233 } 234 return type_sb; 235 } 236 237 bool SBType::IsFunctionType() { 238 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsFunctionType); 239 240 if (!IsValid()) 241 return false; 242 return m_opaque_sp->GetCompilerType(true).IsFunctionType(); 243 } 244 245 bool SBType::IsPolymorphicClass() { 246 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsPolymorphicClass); 247 248 if (!IsValid()) 249 return false; 250 return m_opaque_sp->GetCompilerType(true).IsPolymorphicClass(); 251 } 252 253 bool SBType::IsTypedefType() { 254 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsTypedefType); 255 256 if (!IsValid()) 257 return false; 258 return m_opaque_sp->GetCompilerType(true).IsTypedefType(); 259 } 260 261 bool SBType::IsAnonymousType() { 262 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsAnonymousType); 263 264 if (!IsValid()) 265 return false; 266 return m_opaque_sp->GetCompilerType(true).IsAnonymousType(); 267 } 268 269 bool SBType::IsScopedEnumerationType() { 270 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsScopedEnumerationType); 271 272 if (!IsValid()) 273 return false; 274 return m_opaque_sp->GetCompilerType(true).IsScopedEnumerationType(); 275 } 276 277 lldb::SBType SBType::GetFunctionReturnType() { 278 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetFunctionReturnType); 279 280 if (IsValid()) { 281 CompilerType return_type( 282 m_opaque_sp->GetCompilerType(true).GetFunctionReturnType()); 283 if (return_type.IsValid()) 284 return SBType(return_type); 285 } 286 return lldb::SBType(); 287 } 288 289 lldb::SBTypeList SBType::GetFunctionArgumentTypes() { 290 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeList, SBType, 291 GetFunctionArgumentTypes); 292 293 SBTypeList sb_type_list; 294 if (IsValid()) { 295 CompilerType func_type(m_opaque_sp->GetCompilerType(true)); 296 size_t count = func_type.GetNumberOfFunctionArguments(); 297 for (size_t i = 0; i < count; i++) { 298 sb_type_list.Append(SBType(func_type.GetFunctionArgumentAtIndex(i))); 299 } 300 } 301 return sb_type_list; 302 } 303 304 uint32_t SBType::GetNumberOfMemberFunctions() { 305 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfMemberFunctions); 306 307 if (IsValid()) { 308 return m_opaque_sp->GetCompilerType(true).GetNumMemberFunctions(); 309 } 310 return 0; 311 } 312 313 lldb::SBTypeMemberFunction SBType::GetMemberFunctionAtIndex(uint32_t idx) { 314 LLDB_RECORD_METHOD(lldb::SBTypeMemberFunction, SBType, 315 GetMemberFunctionAtIndex, (uint32_t), idx); 316 317 SBTypeMemberFunction sb_func_type; 318 if (IsValid()) 319 sb_func_type.reset(new TypeMemberFunctionImpl( 320 m_opaque_sp->GetCompilerType(true).GetMemberFunctionAtIndex(idx))); 321 return sb_func_type; 322 } 323 324 lldb::SBType SBType::GetUnqualifiedType() { 325 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetUnqualifiedType); 326 327 if (!IsValid()) 328 return SBType(); 329 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetUnqualifiedType()))); 330 } 331 332 lldb::SBType SBType::GetCanonicalType() { 333 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetCanonicalType); 334 335 if (IsValid()) 336 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetCanonicalType()))); 337 return SBType(); 338 } 339 340 SBType SBType::GetEnumerationIntegerType() { 341 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetEnumerationIntegerType); 342 343 if (IsValid()) { 344 return SBType( 345 m_opaque_sp->GetCompilerType(true).GetEnumerationIntegerType()); 346 } 347 return SBType(); 348 } 349 350 lldb::BasicType SBType::GetBasicType() { 351 LLDB_RECORD_METHOD_NO_ARGS(lldb::BasicType, SBType, GetBasicType); 352 353 if (IsValid()) 354 return m_opaque_sp->GetCompilerType(false).GetBasicTypeEnumeration(); 355 return eBasicTypeInvalid; 356 } 357 358 SBType SBType::GetBasicType(lldb::BasicType basic_type) { 359 LLDB_RECORD_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType), 360 basic_type); 361 362 if (IsValid() && m_opaque_sp->IsValid()) 363 return SBType( 364 m_opaque_sp->GetTypeSystem(false)->GetBasicTypeFromAST(basic_type)); 365 return SBType(); 366 } 367 368 uint32_t SBType::GetNumberOfDirectBaseClasses() { 369 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfDirectBaseClasses); 370 371 if (IsValid()) 372 return m_opaque_sp->GetCompilerType(true).GetNumDirectBaseClasses(); 373 return 0; 374 } 375 376 uint32_t SBType::GetNumberOfVirtualBaseClasses() { 377 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfVirtualBaseClasses); 378 379 if (IsValid()) 380 return m_opaque_sp->GetCompilerType(true).GetNumVirtualBaseClasses(); 381 return 0; 382 } 383 384 uint32_t SBType::GetNumberOfFields() { 385 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfFields); 386 387 if (IsValid()) 388 return m_opaque_sp->GetCompilerType(true).GetNumFields(); 389 return 0; 390 } 391 392 bool SBType::GetDescription(SBStream &description, 393 lldb::DescriptionLevel description_level) { 394 LLDB_RECORD_METHOD(bool, SBType, GetDescription, 395 (lldb::SBStream &, lldb::DescriptionLevel), description, 396 description_level); 397 398 Stream &strm = description.ref(); 399 400 if (m_opaque_sp) { 401 m_opaque_sp->GetDescription(strm, description_level); 402 } else 403 strm.PutCString("No value"); 404 405 return true; 406 } 407 408 SBTypeMember SBType::GetDirectBaseClassAtIndex(uint32_t idx) { 409 LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetDirectBaseClassAtIndex, 410 (uint32_t), idx); 411 412 SBTypeMember sb_type_member; 413 if (IsValid()) { 414 uint32_t bit_offset = 0; 415 CompilerType base_class_type = 416 m_opaque_sp->GetCompilerType(true).GetDirectBaseClassAtIndex( 417 idx, &bit_offset); 418 if (base_class_type.IsValid()) 419 sb_type_member.reset(new TypeMemberImpl( 420 TypeImplSP(new TypeImpl(base_class_type)), bit_offset)); 421 } 422 return sb_type_member; 423 } 424 425 SBTypeMember SBType::GetVirtualBaseClassAtIndex(uint32_t idx) { 426 LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetVirtualBaseClassAtIndex, 427 (uint32_t), idx); 428 429 SBTypeMember sb_type_member; 430 if (IsValid()) { 431 uint32_t bit_offset = 0; 432 CompilerType base_class_type = 433 m_opaque_sp->GetCompilerType(true).GetVirtualBaseClassAtIndex( 434 idx, &bit_offset); 435 if (base_class_type.IsValid()) 436 sb_type_member.reset(new TypeMemberImpl( 437 TypeImplSP(new TypeImpl(base_class_type)), bit_offset)); 438 } 439 return sb_type_member; 440 } 441 442 SBTypeEnumMemberList SBType::GetEnumMembers() { 443 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeEnumMemberList, SBType, 444 GetEnumMembers); 445 446 SBTypeEnumMemberList sb_enum_member_list; 447 if (IsValid()) { 448 CompilerType this_type(m_opaque_sp->GetCompilerType(true)); 449 if (this_type.IsValid()) { 450 this_type.ForEachEnumerator([&sb_enum_member_list]( 451 const CompilerType &integer_type, 452 ConstString name, 453 const llvm::APSInt &value) -> bool { 454 SBTypeEnumMember enum_member( 455 lldb::TypeEnumMemberImplSP(new TypeEnumMemberImpl( 456 lldb::TypeImplSP(new TypeImpl(integer_type)), name, value))); 457 sb_enum_member_list.Append(enum_member); 458 return true; // Keep iterating 459 }); 460 } 461 } 462 return sb_enum_member_list; 463 } 464 465 SBTypeMember SBType::GetFieldAtIndex(uint32_t idx) { 466 LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetFieldAtIndex, (uint32_t), 467 idx); 468 469 SBTypeMember sb_type_member; 470 if (IsValid()) { 471 CompilerType this_type(m_opaque_sp->GetCompilerType(false)); 472 if (this_type.IsValid()) { 473 uint64_t bit_offset = 0; 474 uint32_t bitfield_bit_size = 0; 475 bool is_bitfield = false; 476 std::string name_sstr; 477 CompilerType field_type(this_type.GetFieldAtIndex( 478 idx, name_sstr, &bit_offset, &bitfield_bit_size, &is_bitfield)); 479 if (field_type.IsValid()) { 480 ConstString name; 481 if (!name_sstr.empty()) 482 name.SetCString(name_sstr.c_str()); 483 sb_type_member.reset( 484 new TypeMemberImpl(TypeImplSP(new TypeImpl(field_type)), bit_offset, 485 name, bitfield_bit_size, is_bitfield)); 486 } 487 } 488 } 489 return sb_type_member; 490 } 491 492 bool SBType::IsTypeComplete() { 493 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsTypeComplete); 494 495 if (!IsValid()) 496 return false; 497 return m_opaque_sp->GetCompilerType(false).IsCompleteType(); 498 } 499 500 uint32_t SBType::GetTypeFlags() { 501 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetTypeFlags); 502 503 if (!IsValid()) 504 return 0; 505 return m_opaque_sp->GetCompilerType(true).GetTypeInfo(); 506 } 507 508 lldb::SBModule SBType::GetModule() { 509 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBModule, SBType, GetModule); 510 511 lldb::SBModule sb_module; 512 if (!IsValid()) 513 return sb_module; 514 515 sb_module.SetSP(m_opaque_sp->GetModule()); 516 return sb_module; 517 } 518 519 const char *SBType::GetName() { 520 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetName); 521 522 if (!IsValid()) 523 return ""; 524 return m_opaque_sp->GetName().GetCString(); 525 } 526 527 const char *SBType::GetDisplayTypeName() { 528 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetDisplayTypeName); 529 530 if (!IsValid()) 531 return ""; 532 return m_opaque_sp->GetDisplayTypeName().GetCString(); 533 } 534 535 lldb::TypeClass SBType::GetTypeClass() { 536 LLDB_RECORD_METHOD_NO_ARGS(lldb::TypeClass, SBType, GetTypeClass); 537 538 if (IsValid()) 539 return m_opaque_sp->GetCompilerType(true).GetTypeClass(); 540 return lldb::eTypeClassInvalid; 541 } 542 543 uint32_t SBType::GetNumberOfTemplateArguments() { 544 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfTemplateArguments); 545 546 if (IsValid()) 547 return m_opaque_sp->GetCompilerType(false).GetNumTemplateArguments(); 548 return 0; 549 } 550 551 lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) { 552 LLDB_RECORD_METHOD(lldb::SBType, SBType, GetTemplateArgumentType, (uint32_t), 553 idx); 554 555 if (!IsValid()) 556 return SBType(); 557 558 CompilerType type; 559 switch(GetTemplateArgumentKind(idx)) { 560 case eTemplateArgumentKindType: 561 type = m_opaque_sp->GetCompilerType(false).GetTypeTemplateArgument(idx); 562 break; 563 case eTemplateArgumentKindIntegral: 564 type = m_opaque_sp->GetCompilerType(false) 565 .GetIntegralTemplateArgument(idx) 566 ->type; 567 break; 568 default: 569 break; 570 } 571 if (type.IsValid()) 572 return SBType(type); 573 return SBType(); 574 } 575 576 lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) { 577 LLDB_RECORD_METHOD(lldb::TemplateArgumentKind, SBType, 578 GetTemplateArgumentKind, (uint32_t), idx); 579 580 if (IsValid()) 581 return m_opaque_sp->GetCompilerType(false).GetTemplateArgumentKind(idx); 582 return eTemplateArgumentKindNull; 583 } 584 585 SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) { 586 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeList); 587 } 588 589 SBTypeList::SBTypeList(const SBTypeList &rhs) 590 : m_opaque_up(new TypeListImpl()) { 591 LLDB_RECORD_CONSTRUCTOR(SBTypeList, (const lldb::SBTypeList &), rhs); 592 593 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize(); 594 i < rhs_size; i++) 595 Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i)); 596 } 597 598 bool SBTypeList::IsValid() { 599 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeList, IsValid); 600 return this->operator bool(); 601 } 602 SBTypeList::operator bool() const { 603 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeList, operator bool); 604 605 return (m_opaque_up != nullptr); 606 } 607 608 SBTypeList &SBTypeList::operator=(const SBTypeList &rhs) { 609 LLDB_RECORD_METHOD(lldb::SBTypeList &, 610 SBTypeList, operator=,(const lldb::SBTypeList &), rhs); 611 612 if (this != &rhs) { 613 m_opaque_up = std::make_unique<TypeListImpl>(); 614 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize(); 615 i < rhs_size; i++) 616 Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i)); 617 } 618 return *this; 619 } 620 621 void SBTypeList::Append(SBType type) { 622 LLDB_RECORD_METHOD(void, SBTypeList, Append, (lldb::SBType), type); 623 624 if (type.IsValid()) 625 m_opaque_up->Append(type.m_opaque_sp); 626 } 627 628 SBType SBTypeList::GetTypeAtIndex(uint32_t index) { 629 LLDB_RECORD_METHOD(lldb::SBType, SBTypeList, GetTypeAtIndex, (uint32_t), 630 index); 631 632 if (m_opaque_up) 633 return SBType(m_opaque_up->GetTypeAtIndex(index)); 634 return SBType(); 635 } 636 637 uint32_t SBTypeList::GetSize() { 638 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeList, GetSize); 639 640 return m_opaque_up->GetSize(); 641 } 642 643 SBTypeList::~SBTypeList() = default; 644 645 SBTypeMember::SBTypeMember() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMember); } 646 647 SBTypeMember::~SBTypeMember() = default; 648 649 SBTypeMember::SBTypeMember(const SBTypeMember &rhs) { 650 LLDB_RECORD_CONSTRUCTOR(SBTypeMember, (const lldb::SBTypeMember &), rhs); 651 652 if (this != &rhs) { 653 if (rhs.IsValid()) 654 m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref()); 655 } 656 } 657 658 lldb::SBTypeMember &SBTypeMember::operator=(const lldb::SBTypeMember &rhs) { 659 LLDB_RECORD_METHOD(lldb::SBTypeMember &, 660 SBTypeMember, operator=,(const lldb::SBTypeMember &), rhs); 661 662 if (this != &rhs) { 663 if (rhs.IsValid()) 664 m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref()); 665 } 666 return *this; 667 } 668 669 bool SBTypeMember::IsValid() const { 670 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, IsValid); 671 return this->operator bool(); 672 } 673 SBTypeMember::operator bool() const { 674 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, operator bool); 675 676 return m_opaque_up.get(); 677 } 678 679 const char *SBTypeMember::GetName() { 680 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMember, GetName); 681 682 if (m_opaque_up) 683 return m_opaque_up->GetName().GetCString(); 684 return nullptr; 685 } 686 687 SBType SBTypeMember::GetType() { 688 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMember, GetType); 689 690 SBType sb_type; 691 if (m_opaque_up) { 692 sb_type.SetSP(m_opaque_up->GetTypeImpl()); 693 } 694 return sb_type; 695 } 696 697 uint64_t SBTypeMember::GetOffsetInBytes() { 698 LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBytes); 699 700 if (m_opaque_up) 701 return m_opaque_up->GetBitOffset() / 8u; 702 return 0; 703 } 704 705 uint64_t SBTypeMember::GetOffsetInBits() { 706 LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBits); 707 708 if (m_opaque_up) 709 return m_opaque_up->GetBitOffset(); 710 return 0; 711 } 712 713 bool SBTypeMember::IsBitfield() { 714 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeMember, IsBitfield); 715 716 if (m_opaque_up) 717 return m_opaque_up->GetIsBitfield(); 718 return false; 719 } 720 721 uint32_t SBTypeMember::GetBitfieldSizeInBits() { 722 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMember, GetBitfieldSizeInBits); 723 724 if (m_opaque_up) 725 return m_opaque_up->GetBitfieldBitSize(); 726 return 0; 727 } 728 729 bool SBTypeMember::GetDescription(lldb::SBStream &description, 730 lldb::DescriptionLevel description_level) { 731 LLDB_RECORD_METHOD(bool, SBTypeMember, GetDescription, 732 (lldb::SBStream &, lldb::DescriptionLevel), description, 733 description_level); 734 735 Stream &strm = description.ref(); 736 737 if (m_opaque_up) { 738 const uint32_t bit_offset = m_opaque_up->GetBitOffset(); 739 const uint32_t byte_offset = bit_offset / 8u; 740 const uint32_t byte_bit_offset = bit_offset % 8u; 741 const char *name = m_opaque_up->GetName().GetCString(); 742 if (byte_bit_offset) 743 strm.Printf("+%u + %u bits: (", byte_offset, byte_bit_offset); 744 else 745 strm.Printf("+%u: (", byte_offset); 746 747 TypeImplSP type_impl_sp(m_opaque_up->GetTypeImpl()); 748 if (type_impl_sp) 749 type_impl_sp->GetDescription(strm, description_level); 750 751 strm.Printf(") %s", name); 752 if (m_opaque_up->GetIsBitfield()) { 753 const uint32_t bitfield_bit_size = m_opaque_up->GetBitfieldBitSize(); 754 strm.Printf(" : %u", bitfield_bit_size); 755 } 756 } else { 757 strm.PutCString("No value"); 758 } 759 return true; 760 } 761 762 void SBTypeMember::reset(TypeMemberImpl *type_member_impl) { 763 m_opaque_up.reset(type_member_impl); 764 } 765 766 TypeMemberImpl &SBTypeMember::ref() { 767 if (m_opaque_up == nullptr) 768 m_opaque_up = std::make_unique<TypeMemberImpl>(); 769 return *m_opaque_up; 770 } 771 772 const TypeMemberImpl &SBTypeMember::ref() const { return *m_opaque_up; } 773 774 SBTypeMemberFunction::SBTypeMemberFunction() { 775 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMemberFunction); 776 } 777 778 SBTypeMemberFunction::~SBTypeMemberFunction() = default; 779 780 SBTypeMemberFunction::SBTypeMemberFunction(const SBTypeMemberFunction &rhs) 781 : m_opaque_sp(rhs.m_opaque_sp) { 782 LLDB_RECORD_CONSTRUCTOR(SBTypeMemberFunction, 783 (const lldb::SBTypeMemberFunction &), rhs); 784 } 785 786 lldb::SBTypeMemberFunction &SBTypeMemberFunction:: 787 operator=(const lldb::SBTypeMemberFunction &rhs) { 788 LLDB_RECORD_METHOD( 789 lldb::SBTypeMemberFunction &, 790 SBTypeMemberFunction, operator=,(const lldb::SBTypeMemberFunction &), 791 rhs); 792 793 if (this != &rhs) 794 m_opaque_sp = rhs.m_opaque_sp; 795 return *this; 796 } 797 798 bool SBTypeMemberFunction::IsValid() const { 799 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, IsValid); 800 return this->operator bool(); 801 } 802 SBTypeMemberFunction::operator bool() const { 803 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, operator bool); 804 805 return m_opaque_sp.get(); 806 } 807 808 const char *SBTypeMemberFunction::GetName() { 809 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction, GetName); 810 811 if (m_opaque_sp) 812 return m_opaque_sp->GetName().GetCString(); 813 return nullptr; 814 } 815 816 const char *SBTypeMemberFunction::GetDemangledName() { 817 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction, 818 GetDemangledName); 819 820 if (m_opaque_sp) { 821 ConstString mangled_str = m_opaque_sp->GetMangledName(); 822 if (mangled_str) { 823 Mangled mangled(mangled_str); 824 return mangled.GetDemangledName().GetCString(); 825 } 826 } 827 return nullptr; 828 } 829 830 const char *SBTypeMemberFunction::GetMangledName() { 831 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction, 832 GetMangledName); 833 834 if (m_opaque_sp) 835 return m_opaque_sp->GetMangledName().GetCString(); 836 return nullptr; 837 } 838 839 SBType SBTypeMemberFunction::GetType() { 840 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetType); 841 842 SBType sb_type; 843 if (m_opaque_sp) { 844 sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetType()))); 845 } 846 return sb_type; 847 } 848 849 lldb::SBType SBTypeMemberFunction::GetReturnType() { 850 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetReturnType); 851 852 SBType sb_type; 853 if (m_opaque_sp) { 854 sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetReturnType()))); 855 } 856 return sb_type; 857 } 858 859 uint32_t SBTypeMemberFunction::GetNumberOfArguments() { 860 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMemberFunction, 861 GetNumberOfArguments); 862 863 if (m_opaque_sp) 864 return m_opaque_sp->GetNumArguments(); 865 return 0; 866 } 867 868 lldb::SBType SBTypeMemberFunction::GetArgumentTypeAtIndex(uint32_t i) { 869 LLDB_RECORD_METHOD(lldb::SBType, SBTypeMemberFunction, GetArgumentTypeAtIndex, 870 (uint32_t), i); 871 872 SBType sb_type; 873 if (m_opaque_sp) { 874 sb_type.SetSP( 875 lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetArgumentAtIndex(i)))); 876 } 877 return sb_type; 878 } 879 880 lldb::MemberFunctionKind SBTypeMemberFunction::GetKind() { 881 LLDB_RECORD_METHOD_NO_ARGS(lldb::MemberFunctionKind, SBTypeMemberFunction, 882 GetKind); 883 884 if (m_opaque_sp) 885 return m_opaque_sp->GetKind(); 886 return lldb::eMemberFunctionKindUnknown; 887 } 888 889 bool SBTypeMemberFunction::GetDescription( 890 lldb::SBStream &description, lldb::DescriptionLevel description_level) { 891 LLDB_RECORD_METHOD(bool, SBTypeMemberFunction, GetDescription, 892 (lldb::SBStream &, lldb::DescriptionLevel), description, 893 description_level); 894 895 Stream &strm = description.ref(); 896 897 if (m_opaque_sp) 898 return m_opaque_sp->GetDescription(strm); 899 900 return false; 901 } 902 903 void SBTypeMemberFunction::reset(TypeMemberFunctionImpl *type_member_impl) { 904 m_opaque_sp.reset(type_member_impl); 905 } 906 907 TypeMemberFunctionImpl &SBTypeMemberFunction::ref() { 908 if (!m_opaque_sp) 909 m_opaque_sp = std::make_shared<TypeMemberFunctionImpl>(); 910 return *m_opaque_sp.get(); 911 } 912 913 const TypeMemberFunctionImpl &SBTypeMemberFunction::ref() const { 914 return *m_opaque_sp.get(); 915 } 916