1278332Semaste//===-- SBThreadCollection.cpp ----------------------------------*- C++ -*-===// 2278332Semaste// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6278332Semaste// 7278332Semaste//===----------------------------------------------------------------------===// 8278332Semaste 9278332Semaste#include "lldb/API/SBThreadCollection.h" 10353358Sdim#include "SBReproducerPrivate.h" 11278332Semaste#include "lldb/API/SBThread.h" 12278332Semaste#include "lldb/Target/ThreadList.h" 13278332Semaste 14278332Semasteusing namespace lldb; 15278332Semasteusing namespace lldb_private; 16278332Semaste 17353358SdimSBThreadCollection::SBThreadCollection() : m_opaque_sp() { 18353358Sdim LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThreadCollection); 19353358Sdim} 20278332Semaste 21314564SdimSBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs) 22353358Sdim : m_opaque_sp(rhs.m_opaque_sp) { 23353358Sdim LLDB_RECORD_CONSTRUCTOR(SBThreadCollection, 24353358Sdim (const lldb::SBThreadCollection &), rhs); 25353358Sdim} 26278332Semaste 27314564Sdimconst SBThreadCollection &SBThreadCollection:: 28314564Sdimoperator=(const SBThreadCollection &rhs) { 29353358Sdim LLDB_RECORD_METHOD( 30353358Sdim const lldb::SBThreadCollection &, 31353358Sdim SBThreadCollection, operator=,(const lldb::SBThreadCollection &), rhs); 32353358Sdim 33314564Sdim if (this != &rhs) 34314564Sdim m_opaque_sp = rhs.m_opaque_sp; 35353358Sdim return LLDB_RECORD_RESULT(*this); 36278332Semaste} 37278332Semaste 38314564SdimSBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads) 39314564Sdim : m_opaque_sp(threads) {} 40278332Semaste 41314564SdimSBThreadCollection::~SBThreadCollection() {} 42278332Semaste 43314564Sdimvoid SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) { 44314564Sdim m_opaque_sp = threads; 45278332Semaste} 46278332Semaste 47314564Sdimlldb_private::ThreadCollection *SBThreadCollection::get() const { 48314564Sdim return m_opaque_sp.get(); 49278332Semaste} 50278332Semaste 51314564Sdimlldb_private::ThreadCollection *SBThreadCollection::operator->() const { 52314564Sdim return m_opaque_sp.operator->(); 53278332Semaste} 54278332Semaste 55314564Sdimlldb::ThreadCollectionSP &SBThreadCollection::operator*() { 56314564Sdim return m_opaque_sp; 57278332Semaste} 58278332Semaste 59314564Sdimconst lldb::ThreadCollectionSP &SBThreadCollection::operator*() const { 60314564Sdim return m_opaque_sp; 61278332Semaste} 62278332Semaste 63353358Sdimbool SBThreadCollection::IsValid() const { 64353358Sdim LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, IsValid); 65353358Sdim return this->operator bool(); 66353358Sdim} 67353358SdimSBThreadCollection::operator bool() const { 68353358Sdim LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, operator bool); 69278332Semaste 70353358Sdim return m_opaque_sp.get() != nullptr; 71353358Sdim} 72353358Sdim 73314564Sdimsize_t SBThreadCollection::GetSize() { 74353358Sdim LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadCollection, GetSize); 75353358Sdim 76314564Sdim if (m_opaque_sp) 77314564Sdim return m_opaque_sp->GetSize(); 78314564Sdim return 0; 79278332Semaste} 80278332Semaste 81314564SdimSBThread SBThreadCollection::GetThreadAtIndex(size_t idx) { 82353358Sdim LLDB_RECORD_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex, 83353358Sdim (size_t), idx); 84353358Sdim 85314564Sdim SBThread thread; 86314564Sdim if (m_opaque_sp && idx < m_opaque_sp->GetSize()) 87314564Sdim thread = m_opaque_sp->GetThreadAtIndex(idx); 88353358Sdim return LLDB_RECORD_RESULT(thread); 89278332Semaste} 90353358Sdim 91353358Sdimnamespace lldb_private { 92353358Sdimnamespace repro { 93353358Sdim 94353358Sdimtemplate <> 95353358Sdimvoid RegisterMethods<SBThreadCollection>(Registry &R) { 96353358Sdim LLDB_REGISTER_CONSTRUCTOR(SBThreadCollection, ()); 97353358Sdim LLDB_REGISTER_CONSTRUCTOR(SBThreadCollection, 98353358Sdim (const lldb::SBThreadCollection &)); 99353358Sdim LLDB_REGISTER_METHOD( 100353358Sdim const lldb::SBThreadCollection &, 101353358Sdim SBThreadCollection, operator=,(const lldb::SBThreadCollection &)); 102353358Sdim LLDB_REGISTER_METHOD_CONST(bool, SBThreadCollection, IsValid, ()); 103353358Sdim LLDB_REGISTER_METHOD_CONST(bool, SBThreadCollection, operator bool, ()); 104353358Sdim LLDB_REGISTER_METHOD(size_t, SBThreadCollection, GetSize, ()); 105353358Sdim LLDB_REGISTER_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex, 106353358Sdim (size_t)); 107353358Sdim} 108353358Sdim 109353358Sdim} 110353358Sdim} 111