1//===-- SBThreadCollection.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/SBThreadCollection.h" 10#include "SBReproducerPrivate.h" 11#include "lldb/API/SBThread.h" 12#include "lldb/Target/ThreadList.h" 13 14using namespace lldb; 15using namespace lldb_private; 16 17SBThreadCollection::SBThreadCollection() : m_opaque_sp() { 18 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThreadCollection); 19} 20 21SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs) 22 : m_opaque_sp(rhs.m_opaque_sp) { 23 LLDB_RECORD_CONSTRUCTOR(SBThreadCollection, 24 (const lldb::SBThreadCollection &), rhs); 25} 26 27const SBThreadCollection &SBThreadCollection:: 28operator=(const SBThreadCollection &rhs) { 29 LLDB_RECORD_METHOD( 30 const lldb::SBThreadCollection &, 31 SBThreadCollection, operator=,(const lldb::SBThreadCollection &), rhs); 32 33 if (this != &rhs) 34 m_opaque_sp = rhs.m_opaque_sp; 35 return LLDB_RECORD_RESULT(*this); 36} 37 38SBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads) 39 : m_opaque_sp(threads) {} 40 41SBThreadCollection::~SBThreadCollection() = default; 42 43void SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) { 44 m_opaque_sp = threads; 45} 46 47lldb_private::ThreadCollection *SBThreadCollection::get() const { 48 return m_opaque_sp.get(); 49} 50 51lldb_private::ThreadCollection *SBThreadCollection::operator->() const { 52 return m_opaque_sp.operator->(); 53} 54 55lldb::ThreadCollectionSP &SBThreadCollection::operator*() { 56 return m_opaque_sp; 57} 58 59const lldb::ThreadCollectionSP &SBThreadCollection::operator*() const { 60 return m_opaque_sp; 61} 62 63bool SBThreadCollection::IsValid() const { 64 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, IsValid); 65 return this->operator bool(); 66} 67SBThreadCollection::operator bool() const { 68 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, operator bool); 69 70 return m_opaque_sp.get() != nullptr; 71} 72 73size_t SBThreadCollection::GetSize() { 74 LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadCollection, GetSize); 75 76 if (m_opaque_sp) 77 return m_opaque_sp->GetSize(); 78 return 0; 79} 80 81SBThread SBThreadCollection::GetThreadAtIndex(size_t idx) { 82 LLDB_RECORD_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex, 83 (size_t), idx); 84 85 SBThread thread; 86 if (m_opaque_sp && idx < m_opaque_sp->GetSize()) 87 thread = m_opaque_sp->GetThreadAtIndex(idx); 88 return LLDB_RECORD_RESULT(thread); 89} 90 91namespace lldb_private { 92namespace repro { 93 94template <> 95void RegisterMethods<SBThreadCollection>(Registry &R) { 96 LLDB_REGISTER_CONSTRUCTOR(SBThreadCollection, ()); 97 LLDB_REGISTER_CONSTRUCTOR(SBThreadCollection, 98 (const lldb::SBThreadCollection &)); 99 LLDB_REGISTER_METHOD( 100 const lldb::SBThreadCollection &, 101 SBThreadCollection, operator=,(const lldb::SBThreadCollection &)); 102 LLDB_REGISTER_METHOD_CONST(bool, SBThreadCollection, IsValid, ()); 103 LLDB_REGISTER_METHOD_CONST(bool, SBThreadCollection, operator bool, ()); 104 LLDB_REGISTER_METHOD(size_t, SBThreadCollection, GetSize, ()); 105 LLDB_REGISTER_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex, 106 (size_t)); 107} 108 109} 110} 111