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 "SBReproducerPrivate.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() : m_opaque_sp() { 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) : m_opaque_sp() { 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 LLDB_RECORD_RESULT(*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 LLDB_RECORD_RESULT(SBType()); 170 171 return LLDB_RECORD_RESULT( 172 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointerType())))); 173 } 174 175 SBType SBType::GetPointeeType() { 176 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetPointeeType); 177 178 if (!IsValid()) 179 return LLDB_RECORD_RESULT(SBType()); 180 return LLDB_RECORD_RESULT( 181 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointeeType())))); 182 } 183 184 SBType SBType::GetReferenceType() { 185 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetReferenceType); 186 187 if (!IsValid()) 188 return LLDB_RECORD_RESULT(SBType()); 189 return LLDB_RECORD_RESULT( 190 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetReferenceType())))); 191 } 192 193 SBType SBType::GetTypedefedType() { 194 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetTypedefedType); 195 196 if (!IsValid()) 197 return LLDB_RECORD_RESULT(SBType()); 198 return LLDB_RECORD_RESULT( 199 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetTypedefedType())))); 200 } 201 202 SBType SBType::GetDereferencedType() { 203 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetDereferencedType); 204 205 if (!IsValid()) 206 return LLDB_RECORD_RESULT(SBType()); 207 return LLDB_RECORD_RESULT( 208 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetDereferencedType())))); 209 } 210 211 SBType SBType::GetArrayElementType() { 212 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetArrayElementType); 213 214 if (!IsValid()) 215 return LLDB_RECORD_RESULT(SBType()); 216 CompilerType canonical_type = 217 m_opaque_sp->GetCompilerType(true).GetCanonicalType(); 218 return LLDB_RECORD_RESULT(SBType( 219 TypeImplSP(new TypeImpl(canonical_type.GetArrayElementType(nullptr))))); 220 } 221 222 SBType SBType::GetArrayType(uint64_t size) { 223 LLDB_RECORD_METHOD(lldb::SBType, SBType, GetArrayType, (uint64_t), size); 224 225 if (!IsValid()) 226 return LLDB_RECORD_RESULT(SBType()); 227 return LLDB_RECORD_RESULT(SBType(TypeImplSP( 228 new TypeImpl(m_opaque_sp->GetCompilerType(true).GetArrayType(size))))); 229 } 230 231 SBType SBType::GetVectorElementType() { 232 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetVectorElementType); 233 234 SBType type_sb; 235 if (IsValid()) { 236 CompilerType vector_element_type; 237 if (m_opaque_sp->GetCompilerType(true).IsVectorType(&vector_element_type, 238 nullptr)) 239 type_sb.SetSP(TypeImplSP(new TypeImpl(vector_element_type))); 240 } 241 return LLDB_RECORD_RESULT(type_sb); 242 } 243 244 bool SBType::IsFunctionType() { 245 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsFunctionType); 246 247 if (!IsValid()) 248 return false; 249 return m_opaque_sp->GetCompilerType(true).IsFunctionType(); 250 } 251 252 bool SBType::IsPolymorphicClass() { 253 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsPolymorphicClass); 254 255 if (!IsValid()) 256 return false; 257 return m_opaque_sp->GetCompilerType(true).IsPolymorphicClass(); 258 } 259 260 bool SBType::IsTypedefType() { 261 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsTypedefType); 262 263 if (!IsValid()) 264 return false; 265 return m_opaque_sp->GetCompilerType(true).IsTypedefType(); 266 } 267 268 bool SBType::IsAnonymousType() { 269 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsAnonymousType); 270 271 if (!IsValid()) 272 return false; 273 return m_opaque_sp->GetCompilerType(true).IsAnonymousType(); 274 } 275 276 lldb::SBType SBType::GetFunctionReturnType() { 277 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetFunctionReturnType); 278 279 if (IsValid()) { 280 CompilerType return_type( 281 m_opaque_sp->GetCompilerType(true).GetFunctionReturnType()); 282 if (return_type.IsValid()) 283 return LLDB_RECORD_RESULT(SBType(return_type)); 284 } 285 return LLDB_RECORD_RESULT(lldb::SBType()); 286 } 287 288 lldb::SBTypeList SBType::GetFunctionArgumentTypes() { 289 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeList, SBType, 290 GetFunctionArgumentTypes); 291 292 SBTypeList sb_type_list; 293 if (IsValid()) { 294 CompilerType func_type(m_opaque_sp->GetCompilerType(true)); 295 size_t count = func_type.GetNumberOfFunctionArguments(); 296 for (size_t i = 0; i < count; i++) { 297 sb_type_list.Append(SBType(func_type.GetFunctionArgumentAtIndex(i))); 298 } 299 } 300 return LLDB_RECORD_RESULT(sb_type_list); 301 } 302 303 uint32_t SBType::GetNumberOfMemberFunctions() { 304 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfMemberFunctions); 305 306 if (IsValid()) { 307 return m_opaque_sp->GetCompilerType(true).GetNumMemberFunctions(); 308 } 309 return 0; 310 } 311 312 lldb::SBTypeMemberFunction SBType::GetMemberFunctionAtIndex(uint32_t idx) { 313 LLDB_RECORD_METHOD(lldb::SBTypeMemberFunction, SBType, 314 GetMemberFunctionAtIndex, (uint32_t), idx); 315 316 SBTypeMemberFunction sb_func_type; 317 if (IsValid()) 318 sb_func_type.reset(new TypeMemberFunctionImpl( 319 m_opaque_sp->GetCompilerType(true).GetMemberFunctionAtIndex(idx))); 320 return LLDB_RECORD_RESULT(sb_func_type); 321 } 322 323 lldb::SBType SBType::GetUnqualifiedType() { 324 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetUnqualifiedType); 325 326 if (!IsValid()) 327 return LLDB_RECORD_RESULT(SBType()); 328 return LLDB_RECORD_RESULT( 329 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 LLDB_RECORD_RESULT( 337 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetCanonicalType())))); 338 return LLDB_RECORD_RESULT(SBType()); 339 } 340 341 lldb::BasicType SBType::GetBasicType() { 342 LLDB_RECORD_METHOD_NO_ARGS(lldb::BasicType, SBType, GetBasicType); 343 344 if (IsValid()) 345 return m_opaque_sp->GetCompilerType(false).GetBasicTypeEnumeration(); 346 return eBasicTypeInvalid; 347 } 348 349 SBType SBType::GetBasicType(lldb::BasicType basic_type) { 350 LLDB_RECORD_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType), 351 basic_type); 352 353 if (IsValid() && m_opaque_sp->IsValid()) 354 return LLDB_RECORD_RESULT(SBType( 355 m_opaque_sp->GetTypeSystem(false)->GetBasicTypeFromAST(basic_type))); 356 return LLDB_RECORD_RESULT(SBType()); 357 } 358 359 uint32_t SBType::GetNumberOfDirectBaseClasses() { 360 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfDirectBaseClasses); 361 362 if (IsValid()) 363 return m_opaque_sp->GetCompilerType(true).GetNumDirectBaseClasses(); 364 return 0; 365 } 366 367 uint32_t SBType::GetNumberOfVirtualBaseClasses() { 368 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfVirtualBaseClasses); 369 370 if (IsValid()) 371 return m_opaque_sp->GetCompilerType(true).GetNumVirtualBaseClasses(); 372 return 0; 373 } 374 375 uint32_t SBType::GetNumberOfFields() { 376 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfFields); 377 378 if (IsValid()) 379 return m_opaque_sp->GetCompilerType(true).GetNumFields(); 380 return 0; 381 } 382 383 bool SBType::GetDescription(SBStream &description, 384 lldb::DescriptionLevel description_level) { 385 LLDB_RECORD_METHOD(bool, SBType, GetDescription, 386 (lldb::SBStream &, lldb::DescriptionLevel), description, 387 description_level); 388 389 Stream &strm = description.ref(); 390 391 if (m_opaque_sp) { 392 m_opaque_sp->GetDescription(strm, description_level); 393 } else 394 strm.PutCString("No value"); 395 396 return true; 397 } 398 399 SBTypeMember SBType::GetDirectBaseClassAtIndex(uint32_t idx) { 400 LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetDirectBaseClassAtIndex, 401 (uint32_t), idx); 402 403 SBTypeMember sb_type_member; 404 if (IsValid()) { 405 uint32_t bit_offset = 0; 406 CompilerType base_class_type = 407 m_opaque_sp->GetCompilerType(true).GetDirectBaseClassAtIndex( 408 idx, &bit_offset); 409 if (base_class_type.IsValid()) 410 sb_type_member.reset(new TypeMemberImpl( 411 TypeImplSP(new TypeImpl(base_class_type)), bit_offset)); 412 } 413 return LLDB_RECORD_RESULT(sb_type_member); 414 } 415 416 SBTypeMember SBType::GetVirtualBaseClassAtIndex(uint32_t idx) { 417 LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetVirtualBaseClassAtIndex, 418 (uint32_t), idx); 419 420 SBTypeMember sb_type_member; 421 if (IsValid()) { 422 uint32_t bit_offset = 0; 423 CompilerType base_class_type = 424 m_opaque_sp->GetCompilerType(true).GetVirtualBaseClassAtIndex( 425 idx, &bit_offset); 426 if (base_class_type.IsValid()) 427 sb_type_member.reset(new TypeMemberImpl( 428 TypeImplSP(new TypeImpl(base_class_type)), bit_offset)); 429 } 430 return LLDB_RECORD_RESULT(sb_type_member); 431 } 432 433 SBTypeEnumMemberList SBType::GetEnumMembers() { 434 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeEnumMemberList, SBType, 435 GetEnumMembers); 436 437 SBTypeEnumMemberList sb_enum_member_list; 438 if (IsValid()) { 439 CompilerType this_type(m_opaque_sp->GetCompilerType(true)); 440 if (this_type.IsValid()) { 441 this_type.ForEachEnumerator([&sb_enum_member_list]( 442 const CompilerType &integer_type, 443 ConstString name, 444 const llvm::APSInt &value) -> bool { 445 SBTypeEnumMember enum_member( 446 lldb::TypeEnumMemberImplSP(new TypeEnumMemberImpl( 447 lldb::TypeImplSP(new TypeImpl(integer_type)), name, value))); 448 sb_enum_member_list.Append(enum_member); 449 return true; // Keep iterating 450 }); 451 } 452 } 453 return LLDB_RECORD_RESULT(sb_enum_member_list); 454 } 455 456 SBTypeMember SBType::GetFieldAtIndex(uint32_t idx) { 457 LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetFieldAtIndex, (uint32_t), 458 idx); 459 460 SBTypeMember sb_type_member; 461 if (IsValid()) { 462 CompilerType this_type(m_opaque_sp->GetCompilerType(false)); 463 if (this_type.IsValid()) { 464 uint64_t bit_offset = 0; 465 uint32_t bitfield_bit_size = 0; 466 bool is_bitfield = false; 467 std::string name_sstr; 468 CompilerType field_type(this_type.GetFieldAtIndex( 469 idx, name_sstr, &bit_offset, &bitfield_bit_size, &is_bitfield)); 470 if (field_type.IsValid()) { 471 ConstString name; 472 if (!name_sstr.empty()) 473 name.SetCString(name_sstr.c_str()); 474 sb_type_member.reset( 475 new TypeMemberImpl(TypeImplSP(new TypeImpl(field_type)), bit_offset, 476 name, bitfield_bit_size, is_bitfield)); 477 } 478 } 479 } 480 return LLDB_RECORD_RESULT(sb_type_member); 481 } 482 483 bool SBType::IsTypeComplete() { 484 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsTypeComplete); 485 486 if (!IsValid()) 487 return false; 488 return m_opaque_sp->GetCompilerType(false).IsCompleteType(); 489 } 490 491 uint32_t SBType::GetTypeFlags() { 492 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetTypeFlags); 493 494 if (!IsValid()) 495 return 0; 496 return m_opaque_sp->GetCompilerType(true).GetTypeInfo(); 497 } 498 499 lldb::SBModule SBType::GetModule() { 500 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBModule, SBType, GetModule); 501 502 lldb::SBModule sb_module; 503 if (!IsValid()) 504 return LLDB_RECORD_RESULT(sb_module); 505 506 sb_module.SetSP(m_opaque_sp->GetModule()); 507 return LLDB_RECORD_RESULT(sb_module); 508 } 509 510 const char *SBType::GetName() { 511 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetName); 512 513 if (!IsValid()) 514 return ""; 515 return m_opaque_sp->GetName().GetCString(); 516 } 517 518 const char *SBType::GetDisplayTypeName() { 519 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetDisplayTypeName); 520 521 if (!IsValid()) 522 return ""; 523 return m_opaque_sp->GetDisplayTypeName().GetCString(); 524 } 525 526 lldb::TypeClass SBType::GetTypeClass() { 527 LLDB_RECORD_METHOD_NO_ARGS(lldb::TypeClass, SBType, GetTypeClass); 528 529 if (IsValid()) 530 return m_opaque_sp->GetCompilerType(true).GetTypeClass(); 531 return lldb::eTypeClassInvalid; 532 } 533 534 uint32_t SBType::GetNumberOfTemplateArguments() { 535 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfTemplateArguments); 536 537 if (IsValid()) 538 return m_opaque_sp->GetCompilerType(false).GetNumTemplateArguments(); 539 return 0; 540 } 541 542 lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) { 543 LLDB_RECORD_METHOD(lldb::SBType, SBType, GetTemplateArgumentType, (uint32_t), 544 idx); 545 546 if (!IsValid()) 547 return LLDB_RECORD_RESULT(SBType()); 548 549 CompilerType type; 550 switch(GetTemplateArgumentKind(idx)) { 551 case eTemplateArgumentKindType: 552 type = m_opaque_sp->GetCompilerType(false).GetTypeTemplateArgument(idx); 553 break; 554 case eTemplateArgumentKindIntegral: 555 type = m_opaque_sp->GetCompilerType(false) 556 .GetIntegralTemplateArgument(idx) 557 ->type; 558 break; 559 default: 560 break; 561 } 562 if (type.IsValid()) 563 return LLDB_RECORD_RESULT(SBType(type)); 564 return LLDB_RECORD_RESULT(SBType()); 565 } 566 567 lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) { 568 LLDB_RECORD_METHOD(lldb::TemplateArgumentKind, SBType, 569 GetTemplateArgumentKind, (uint32_t), idx); 570 571 if (IsValid()) 572 return m_opaque_sp->GetCompilerType(false).GetTemplateArgumentKind(idx); 573 return eTemplateArgumentKindNull; 574 } 575 576 SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) { 577 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeList); 578 } 579 580 SBTypeList::SBTypeList(const SBTypeList &rhs) 581 : m_opaque_up(new TypeListImpl()) { 582 LLDB_RECORD_CONSTRUCTOR(SBTypeList, (const lldb::SBTypeList &), rhs); 583 584 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize(); 585 i < rhs_size; i++) 586 Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i)); 587 } 588 589 bool SBTypeList::IsValid() { 590 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeList, IsValid); 591 return this->operator bool(); 592 } 593 SBTypeList::operator bool() const { 594 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeList, operator bool); 595 596 return (m_opaque_up != nullptr); 597 } 598 599 SBTypeList &SBTypeList::operator=(const SBTypeList &rhs) { 600 LLDB_RECORD_METHOD(lldb::SBTypeList &, 601 SBTypeList, operator=,(const lldb::SBTypeList &), rhs); 602 603 if (this != &rhs) { 604 m_opaque_up = std::make_unique<TypeListImpl>(); 605 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize(); 606 i < rhs_size; i++) 607 Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i)); 608 } 609 return LLDB_RECORD_RESULT(*this); 610 } 611 612 void SBTypeList::Append(SBType type) { 613 LLDB_RECORD_METHOD(void, SBTypeList, Append, (lldb::SBType), type); 614 615 if (type.IsValid()) 616 m_opaque_up->Append(type.m_opaque_sp); 617 } 618 619 SBType SBTypeList::GetTypeAtIndex(uint32_t index) { 620 LLDB_RECORD_METHOD(lldb::SBType, SBTypeList, GetTypeAtIndex, (uint32_t), 621 index); 622 623 if (m_opaque_up) 624 return LLDB_RECORD_RESULT(SBType(m_opaque_up->GetTypeAtIndex(index))); 625 return LLDB_RECORD_RESULT(SBType()); 626 } 627 628 uint32_t SBTypeList::GetSize() { 629 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeList, GetSize); 630 631 return m_opaque_up->GetSize(); 632 } 633 634 SBTypeList::~SBTypeList() = default; 635 636 SBTypeMember::SBTypeMember() : m_opaque_up() { 637 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMember); 638 } 639 640 SBTypeMember::~SBTypeMember() = default; 641 642 SBTypeMember::SBTypeMember(const SBTypeMember &rhs) : m_opaque_up() { 643 LLDB_RECORD_CONSTRUCTOR(SBTypeMember, (const lldb::SBTypeMember &), rhs); 644 645 if (this != &rhs) { 646 if (rhs.IsValid()) 647 m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref()); 648 } 649 } 650 651 lldb::SBTypeMember &SBTypeMember::operator=(const lldb::SBTypeMember &rhs) { 652 LLDB_RECORD_METHOD(lldb::SBTypeMember &, 653 SBTypeMember, operator=,(const lldb::SBTypeMember &), rhs); 654 655 if (this != &rhs) { 656 if (rhs.IsValid()) 657 m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref()); 658 } 659 return LLDB_RECORD_RESULT(*this); 660 } 661 662 bool SBTypeMember::IsValid() const { 663 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, IsValid); 664 return this->operator bool(); 665 } 666 SBTypeMember::operator bool() const { 667 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, operator bool); 668 669 return m_opaque_up.get(); 670 } 671 672 const char *SBTypeMember::GetName() { 673 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMember, GetName); 674 675 if (m_opaque_up) 676 return m_opaque_up->GetName().GetCString(); 677 return nullptr; 678 } 679 680 SBType SBTypeMember::GetType() { 681 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMember, GetType); 682 683 SBType sb_type; 684 if (m_opaque_up) { 685 sb_type.SetSP(m_opaque_up->GetTypeImpl()); 686 } 687 return LLDB_RECORD_RESULT(sb_type); 688 } 689 690 uint64_t SBTypeMember::GetOffsetInBytes() { 691 LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBytes); 692 693 if (m_opaque_up) 694 return m_opaque_up->GetBitOffset() / 8u; 695 return 0; 696 } 697 698 uint64_t SBTypeMember::GetOffsetInBits() { 699 LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBits); 700 701 if (m_opaque_up) 702 return m_opaque_up->GetBitOffset(); 703 return 0; 704 } 705 706 bool SBTypeMember::IsBitfield() { 707 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeMember, IsBitfield); 708 709 if (m_opaque_up) 710 return m_opaque_up->GetIsBitfield(); 711 return false; 712 } 713 714 uint32_t SBTypeMember::GetBitfieldSizeInBits() { 715 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMember, GetBitfieldSizeInBits); 716 717 if (m_opaque_up) 718 return m_opaque_up->GetBitfieldBitSize(); 719 return 0; 720 } 721 722 bool SBTypeMember::GetDescription(lldb::SBStream &description, 723 lldb::DescriptionLevel description_level) { 724 LLDB_RECORD_METHOD(bool, SBTypeMember, GetDescription, 725 (lldb::SBStream &, lldb::DescriptionLevel), description, 726 description_level); 727 728 Stream &strm = description.ref(); 729 730 if (m_opaque_up) { 731 const uint32_t bit_offset = m_opaque_up->GetBitOffset(); 732 const uint32_t byte_offset = bit_offset / 8u; 733 const uint32_t byte_bit_offset = bit_offset % 8u; 734 const char *name = m_opaque_up->GetName().GetCString(); 735 if (byte_bit_offset) 736 strm.Printf("+%u + %u bits: (", byte_offset, byte_bit_offset); 737 else 738 strm.Printf("+%u: (", byte_offset); 739 740 TypeImplSP type_impl_sp(m_opaque_up->GetTypeImpl()); 741 if (type_impl_sp) 742 type_impl_sp->GetDescription(strm, description_level); 743 744 strm.Printf(") %s", name); 745 if (m_opaque_up->GetIsBitfield()) { 746 const uint32_t bitfield_bit_size = m_opaque_up->GetBitfieldBitSize(); 747 strm.Printf(" : %u", bitfield_bit_size); 748 } 749 } else { 750 strm.PutCString("No value"); 751 } 752 return true; 753 } 754 755 void SBTypeMember::reset(TypeMemberImpl *type_member_impl) { 756 m_opaque_up.reset(type_member_impl); 757 } 758 759 TypeMemberImpl &SBTypeMember::ref() { 760 if (m_opaque_up == nullptr) 761 m_opaque_up = std::make_unique<TypeMemberImpl>(); 762 return *m_opaque_up; 763 } 764 765 const TypeMemberImpl &SBTypeMember::ref() const { return *m_opaque_up; } 766 767 SBTypeMemberFunction::SBTypeMemberFunction() : m_opaque_sp() { 768 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMemberFunction); 769 } 770 771 SBTypeMemberFunction::~SBTypeMemberFunction() = default; 772 773 SBTypeMemberFunction::SBTypeMemberFunction(const SBTypeMemberFunction &rhs) 774 : m_opaque_sp(rhs.m_opaque_sp) { 775 LLDB_RECORD_CONSTRUCTOR(SBTypeMemberFunction, 776 (const lldb::SBTypeMemberFunction &), rhs); 777 } 778 779 lldb::SBTypeMemberFunction &SBTypeMemberFunction:: 780 operator=(const lldb::SBTypeMemberFunction &rhs) { 781 LLDB_RECORD_METHOD( 782 lldb::SBTypeMemberFunction &, 783 SBTypeMemberFunction, operator=,(const lldb::SBTypeMemberFunction &), 784 rhs); 785 786 if (this != &rhs) 787 m_opaque_sp = rhs.m_opaque_sp; 788 return LLDB_RECORD_RESULT(*this); 789 } 790 791 bool SBTypeMemberFunction::IsValid() const { 792 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, IsValid); 793 return this->operator bool(); 794 } 795 SBTypeMemberFunction::operator bool() const { 796 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, operator bool); 797 798 return m_opaque_sp.get(); 799 } 800 801 const char *SBTypeMemberFunction::GetName() { 802 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction, GetName); 803 804 if (m_opaque_sp) 805 return m_opaque_sp->GetName().GetCString(); 806 return nullptr; 807 } 808 809 const char *SBTypeMemberFunction::GetDemangledName() { 810 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction, 811 GetDemangledName); 812 813 if (m_opaque_sp) { 814 ConstString mangled_str = m_opaque_sp->GetMangledName(); 815 if (mangled_str) { 816 Mangled mangled(mangled_str); 817 return mangled.GetDemangledName().GetCString(); 818 } 819 } 820 return nullptr; 821 } 822 823 const char *SBTypeMemberFunction::GetMangledName() { 824 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction, 825 GetMangledName); 826 827 if (m_opaque_sp) 828 return m_opaque_sp->GetMangledName().GetCString(); 829 return nullptr; 830 } 831 832 SBType SBTypeMemberFunction::GetType() { 833 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetType); 834 835 SBType sb_type; 836 if (m_opaque_sp) { 837 sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetType()))); 838 } 839 return LLDB_RECORD_RESULT(sb_type); 840 } 841 842 lldb::SBType SBTypeMemberFunction::GetReturnType() { 843 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetReturnType); 844 845 SBType sb_type; 846 if (m_opaque_sp) { 847 sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetReturnType()))); 848 } 849 return LLDB_RECORD_RESULT(sb_type); 850 } 851 852 uint32_t SBTypeMemberFunction::GetNumberOfArguments() { 853 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMemberFunction, 854 GetNumberOfArguments); 855 856 if (m_opaque_sp) 857 return m_opaque_sp->GetNumArguments(); 858 return 0; 859 } 860 861 lldb::SBType SBTypeMemberFunction::GetArgumentTypeAtIndex(uint32_t i) { 862 LLDB_RECORD_METHOD(lldb::SBType, SBTypeMemberFunction, GetArgumentTypeAtIndex, 863 (uint32_t), i); 864 865 SBType sb_type; 866 if (m_opaque_sp) { 867 sb_type.SetSP( 868 lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetArgumentAtIndex(i)))); 869 } 870 return LLDB_RECORD_RESULT(sb_type); 871 } 872 873 lldb::MemberFunctionKind SBTypeMemberFunction::GetKind() { 874 LLDB_RECORD_METHOD_NO_ARGS(lldb::MemberFunctionKind, SBTypeMemberFunction, 875 GetKind); 876 877 if (m_opaque_sp) 878 return m_opaque_sp->GetKind(); 879 return lldb::eMemberFunctionKindUnknown; 880 } 881 882 bool SBTypeMemberFunction::GetDescription( 883 lldb::SBStream &description, lldb::DescriptionLevel description_level) { 884 LLDB_RECORD_METHOD(bool, SBTypeMemberFunction, GetDescription, 885 (lldb::SBStream &, lldb::DescriptionLevel), description, 886 description_level); 887 888 Stream &strm = description.ref(); 889 890 if (m_opaque_sp) 891 return m_opaque_sp->GetDescription(strm); 892 893 return false; 894 } 895 896 void SBTypeMemberFunction::reset(TypeMemberFunctionImpl *type_member_impl) { 897 m_opaque_sp.reset(type_member_impl); 898 } 899 900 TypeMemberFunctionImpl &SBTypeMemberFunction::ref() { 901 if (!m_opaque_sp) 902 m_opaque_sp = std::make_shared<TypeMemberFunctionImpl>(); 903 return *m_opaque_sp.get(); 904 } 905 906 const TypeMemberFunctionImpl &SBTypeMemberFunction::ref() const { 907 return *m_opaque_sp.get(); 908 } 909 910 namespace lldb_private { 911 namespace repro { 912 913 template <> 914 void RegisterMethods<SBType>(Registry &R) { 915 LLDB_REGISTER_CONSTRUCTOR(SBType, ()); 916 LLDB_REGISTER_CONSTRUCTOR(SBType, (const lldb::SBType &)); 917 LLDB_REGISTER_METHOD(bool, SBType, operator==,(lldb::SBType &)); 918 LLDB_REGISTER_METHOD(bool, SBType, operator!=,(lldb::SBType &)); 919 LLDB_REGISTER_METHOD(lldb::SBType &, 920 SBType, operator=,(const lldb::SBType &)); 921 LLDB_REGISTER_METHOD_CONST(bool, SBType, IsValid, ()); 922 LLDB_REGISTER_METHOD_CONST(bool, SBType, operator bool, ()); 923 LLDB_REGISTER_METHOD(uint64_t, SBType, GetByteSize, ()); 924 LLDB_REGISTER_METHOD(bool, SBType, IsPointerType, ()); 925 LLDB_REGISTER_METHOD(bool, SBType, IsArrayType, ()); 926 LLDB_REGISTER_METHOD(bool, SBType, IsVectorType, ()); 927 LLDB_REGISTER_METHOD(bool, SBType, IsReferenceType, ()); 928 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetPointerType, ()); 929 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetPointeeType, ()); 930 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetReferenceType, ()); 931 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetTypedefedType, ()); 932 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetDereferencedType, ()); 933 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetArrayElementType, ()); 934 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetArrayType, (uint64_t)); 935 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetVectorElementType, ()); 936 LLDB_REGISTER_METHOD(bool, SBType, IsFunctionType, ()); 937 LLDB_REGISTER_METHOD(bool, SBType, IsPolymorphicClass, ()); 938 LLDB_REGISTER_METHOD(bool, SBType, IsTypedefType, ()); 939 LLDB_REGISTER_METHOD(bool, SBType, IsAnonymousType, ()); 940 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetFunctionReturnType, ()); 941 LLDB_REGISTER_METHOD(lldb::SBTypeList, SBType, GetFunctionArgumentTypes, 942 ()); 943 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfMemberFunctions, ()); 944 LLDB_REGISTER_METHOD(lldb::SBTypeMemberFunction, SBType, 945 GetMemberFunctionAtIndex, (uint32_t)); 946 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetUnqualifiedType, ()); 947 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetCanonicalType, ()); 948 LLDB_REGISTER_METHOD(lldb::BasicType, SBType, GetBasicType, ()); 949 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType)); 950 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfDirectBaseClasses, ()); 951 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfVirtualBaseClasses, ()); 952 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfFields, ()); 953 LLDB_REGISTER_METHOD(bool, SBType, GetDescription, 954 (lldb::SBStream &, lldb::DescriptionLevel)); 955 LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetDirectBaseClassAtIndex, 956 (uint32_t)); 957 LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetVirtualBaseClassAtIndex, 958 (uint32_t)); 959 LLDB_REGISTER_METHOD(lldb::SBTypeEnumMemberList, SBType, GetEnumMembers, 960 ()); 961 LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetFieldAtIndex, 962 (uint32_t)); 963 LLDB_REGISTER_METHOD(bool, SBType, IsTypeComplete, ()); 964 LLDB_REGISTER_METHOD(uint32_t, SBType, GetTypeFlags, ()); 965 LLDB_REGISTER_METHOD(lldb::SBModule, SBType, GetModule, ()); 966 LLDB_REGISTER_METHOD(const char *, SBType, GetName, ()); 967 LLDB_REGISTER_METHOD(const char *, SBType, GetDisplayTypeName, ()); 968 LLDB_REGISTER_METHOD(lldb::TypeClass, SBType, GetTypeClass, ()); 969 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfTemplateArguments, ()); 970 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetTemplateArgumentType, 971 (uint32_t)); 972 LLDB_REGISTER_METHOD(lldb::TemplateArgumentKind, SBType, 973 GetTemplateArgumentKind, (uint32_t)); 974 LLDB_REGISTER_CONSTRUCTOR(SBTypeList, ()); 975 LLDB_REGISTER_CONSTRUCTOR(SBTypeList, (const lldb::SBTypeList &)); 976 LLDB_REGISTER_METHOD(bool, SBTypeList, IsValid, ()); 977 LLDB_REGISTER_METHOD_CONST(bool, SBTypeList, operator bool, ()); 978 LLDB_REGISTER_METHOD(lldb::SBTypeList &, 979 SBTypeList, operator=,(const lldb::SBTypeList &)); 980 LLDB_REGISTER_METHOD(void, SBTypeList, Append, (lldb::SBType)); 981 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeList, GetTypeAtIndex, (uint32_t)); 982 LLDB_REGISTER_METHOD(uint32_t, SBTypeList, GetSize, ()); 983 LLDB_REGISTER_CONSTRUCTOR(SBTypeMember, ()); 984 LLDB_REGISTER_CONSTRUCTOR(SBTypeMember, (const lldb::SBTypeMember &)); 985 LLDB_REGISTER_METHOD(lldb::SBTypeMember &, 986 SBTypeMember, operator=,(const lldb::SBTypeMember &)); 987 LLDB_REGISTER_METHOD_CONST(bool, SBTypeMember, IsValid, ()); 988 LLDB_REGISTER_METHOD_CONST(bool, SBTypeMember, operator bool, ()); 989 LLDB_REGISTER_METHOD(const char *, SBTypeMember, GetName, ()); 990 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMember, GetType, ()); 991 LLDB_REGISTER_METHOD(uint64_t, SBTypeMember, GetOffsetInBytes, ()); 992 LLDB_REGISTER_METHOD(uint64_t, SBTypeMember, GetOffsetInBits, ()); 993 LLDB_REGISTER_METHOD(bool, SBTypeMember, IsBitfield, ()); 994 LLDB_REGISTER_METHOD(uint32_t, SBTypeMember, GetBitfieldSizeInBits, ()); 995 LLDB_REGISTER_METHOD(bool, SBTypeMember, GetDescription, 996 (lldb::SBStream &, lldb::DescriptionLevel)); 997 LLDB_REGISTER_CONSTRUCTOR(SBTypeMemberFunction, ()); 998 LLDB_REGISTER_CONSTRUCTOR(SBTypeMemberFunction, 999 (const lldb::SBTypeMemberFunction &)); 1000 LLDB_REGISTER_METHOD( 1001 lldb::SBTypeMemberFunction &, 1002 SBTypeMemberFunction, operator=,(const lldb::SBTypeMemberFunction &)); 1003 LLDB_REGISTER_METHOD_CONST(bool, SBTypeMemberFunction, IsValid, ()); 1004 LLDB_REGISTER_METHOD_CONST(bool, SBTypeMemberFunction, operator bool, ()); 1005 LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetName, ()); 1006 LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetDemangledName, 1007 ()); 1008 LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetMangledName, 1009 ()); 1010 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction, GetType, ()); 1011 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction, GetReturnType, ()); 1012 LLDB_REGISTER_METHOD(uint32_t, SBTypeMemberFunction, GetNumberOfArguments, 1013 ()); 1014 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction, 1015 GetArgumentTypeAtIndex, (uint32_t)); 1016 LLDB_REGISTER_METHOD(lldb::MemberFunctionKind, SBTypeMemberFunction, 1017 GetKind, ()); 1018 LLDB_REGISTER_METHOD(bool, SBTypeMemberFunction, GetDescription, 1019 (lldb::SBStream &, lldb::DescriptionLevel)); 1020 } 1021 1022 } 1023 } 1024