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