1*0b57cec5SDimitry Andric //===-- SBThreadCollection.cpp --------------------------------------------===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "lldb/API/SBThreadCollection.h" 10*0b57cec5SDimitry Andric #include "lldb/API/SBThread.h" 11*0b57cec5SDimitry Andric #include "lldb/Target/ThreadList.h" 12*0b57cec5SDimitry Andric #include "lldb/Utility/Instrumentation.h" 13*0b57cec5SDimitry Andric 14*0b57cec5SDimitry Andric using namespace lldb; 15*0b57cec5SDimitry Andric using namespace lldb_private; 16*0b57cec5SDimitry Andric SBThreadCollection()17*0b57cec5SDimitry AndricSBThreadCollection::SBThreadCollection() { LLDB_INSTRUMENT_VA(this); } 18*0b57cec5SDimitry Andric SBThreadCollection(const SBThreadCollection & rhs)19*0b57cec5SDimitry AndricSBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs) 20*0b57cec5SDimitry Andric : m_opaque_sp(rhs.m_opaque_sp) { 21*0b57cec5SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs); 22*0b57cec5SDimitry Andric } 23*0b57cec5SDimitry Andric 24*0b57cec5SDimitry Andric const SBThreadCollection &SBThreadCollection:: operator =(const SBThreadCollection & rhs)25*0b57cec5SDimitry Andricoperator=(const SBThreadCollection &rhs) { 26*0b57cec5SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs); 27*0b57cec5SDimitry Andric 28*0b57cec5SDimitry Andric if (this != &rhs) 29*0b57cec5SDimitry Andric m_opaque_sp = rhs.m_opaque_sp; 30*0b57cec5SDimitry Andric return *this; 31*0b57cec5SDimitry Andric } 32*0b57cec5SDimitry Andric SBThreadCollection(const ThreadCollectionSP & threads)33*0b57cec5SDimitry AndricSBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads) 34*0b57cec5SDimitry Andric : m_opaque_sp(threads) {} 35*0b57cec5SDimitry Andric 36*0b57cec5SDimitry Andric SBThreadCollection::~SBThreadCollection() = default; 37*0b57cec5SDimitry Andric SetOpaque(const lldb::ThreadCollectionSP & threads)38*0b57cec5SDimitry Andricvoid SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) { 39*0b57cec5SDimitry Andric m_opaque_sp = threads; 40*0b57cec5SDimitry Andric } 41*0b57cec5SDimitry Andric get() const42*0b57cec5SDimitry Andriclldb_private::ThreadCollection *SBThreadCollection::get() const { 43*0b57cec5SDimitry Andric return m_opaque_sp.get(); 44*0b57cec5SDimitry Andric } 45*0b57cec5SDimitry Andric operator ->() const46*0b57cec5SDimitry Andriclldb_private::ThreadCollection *SBThreadCollection::operator->() const { 47*0b57cec5SDimitry Andric return m_opaque_sp.operator->(); 48*0b57cec5SDimitry Andric } 49*0b57cec5SDimitry Andric operator *()50*0b57cec5SDimitry Andriclldb::ThreadCollectionSP &SBThreadCollection::operator*() { 51*0b57cec5SDimitry Andric return m_opaque_sp; 52*0b57cec5SDimitry Andric } 53*0b57cec5SDimitry Andric operator *() const54*0b57cec5SDimitry Andricconst lldb::ThreadCollectionSP &SBThreadCollection::operator*() const { 55*0b57cec5SDimitry Andric return m_opaque_sp; 56*0b57cec5SDimitry Andric } 57*0b57cec5SDimitry Andric IsValid() const58*0b57cec5SDimitry Andricbool SBThreadCollection::IsValid() const { 59*0b57cec5SDimitry Andric LLDB_INSTRUMENT_VA(this); 60*0b57cec5SDimitry Andric return this->operator bool(); 61*0b57cec5SDimitry Andric } operator bool() const62*0b57cec5SDimitry AndricSBThreadCollection::operator bool() const { 63*0b57cec5SDimitry Andric LLDB_INSTRUMENT_VA(this); 64*0b57cec5SDimitry Andric 65*0b57cec5SDimitry Andric return m_opaque_sp.get() != nullptr; 66*0b57cec5SDimitry Andric } 67*0b57cec5SDimitry Andric GetSize()68*0b57cec5SDimitry Andricsize_t SBThreadCollection::GetSize() { 69*0b57cec5SDimitry Andric LLDB_INSTRUMENT_VA(this); 70*0b57cec5SDimitry Andric 71*0b57cec5SDimitry Andric if (m_opaque_sp) 72*0b57cec5SDimitry Andric return m_opaque_sp->GetSize(); 73*0b57cec5SDimitry Andric return 0; 74*0b57cec5SDimitry Andric } 75*0b57cec5SDimitry Andric GetThreadAtIndex(size_t idx)76*0b57cec5SDimitry AndricSBThread SBThreadCollection::GetThreadAtIndex(size_t idx) { 77*0b57cec5SDimitry Andric LLDB_INSTRUMENT_VA(this, idx); 78*0b57cec5SDimitry Andric 79*0b57cec5SDimitry Andric SBThread thread; 80*0b57cec5SDimitry Andric if (m_opaque_sp && idx < m_opaque_sp->GetSize()) 81*0b57cec5SDimitry Andric thread = m_opaque_sp->GetThreadAtIndex(idx); 82*0b57cec5SDimitry Andric return thread; 83*0b57cec5SDimitry Andric } 84*0b57cec5SDimitry Andric