180814287SRaphael Isemann //===-- SBThreadCollection.cpp --------------------------------------------===//
2a5ea1e2bSKuba Brecka //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a5ea1e2bSKuba Brecka //
7a5ea1e2bSKuba Brecka //===----------------------------------------------------------------------===//
8a5ea1e2bSKuba Brecka 
9a5ea1e2bSKuba Brecka #include "lldb/API/SBThreadCollection.h"
10*d51402acSJonas Devlieghere #include "lldb/Utility/ReproducerInstrumentation.h"
11a5ea1e2bSKuba Brecka #include "lldb/API/SBThread.h"
12a5ea1e2bSKuba Brecka #include "lldb/Target/ThreadList.h"
13a5ea1e2bSKuba Brecka 
14a5ea1e2bSKuba Brecka using namespace lldb;
15a5ea1e2bSKuba Brecka using namespace lldb_private;
16a5ea1e2bSKuba Brecka 
17a3436f73SKazu Hirata SBThreadCollection::SBThreadCollection() {
18baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThreadCollection);
19baf5664fSJonas Devlieghere }
20a5ea1e2bSKuba Brecka 
21b9c1b51eSKate Stone SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs)
22baf5664fSJonas Devlieghere     : m_opaque_sp(rhs.m_opaque_sp) {
23baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR(SBThreadCollection,
24baf5664fSJonas Devlieghere                           (const lldb::SBThreadCollection &), rhs);
25baf5664fSJonas Devlieghere }
26a5ea1e2bSKuba Brecka 
27b9c1b51eSKate Stone const SBThreadCollection &SBThreadCollection::
28b9c1b51eSKate Stone operator=(const SBThreadCollection &rhs) {
29baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(
30baf5664fSJonas Devlieghere       const lldb::SBThreadCollection &,
31baf5664fSJonas Devlieghere       SBThreadCollection, operator=,(const lldb::SBThreadCollection &), rhs);
32baf5664fSJonas Devlieghere 
33a5ea1e2bSKuba Brecka   if (this != &rhs)
34a5ea1e2bSKuba Brecka     m_opaque_sp = rhs.m_opaque_sp;
35306809f2SJonas Devlieghere   return LLDB_RECORD_RESULT(*this);
36a5ea1e2bSKuba Brecka }
37a5ea1e2bSKuba Brecka 
38b9c1b51eSKate Stone SBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads)
39b9c1b51eSKate Stone     : m_opaque_sp(threads) {}
40a5ea1e2bSKuba Brecka 
41866b7a65SJonas Devlieghere SBThreadCollection::~SBThreadCollection() = default;
42a5ea1e2bSKuba Brecka 
43b9c1b51eSKate Stone void SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) {
44a5ea1e2bSKuba Brecka   m_opaque_sp = threads;
45a5ea1e2bSKuba Brecka }
46a5ea1e2bSKuba Brecka 
47b9c1b51eSKate Stone lldb_private::ThreadCollection *SBThreadCollection::get() const {
48a5ea1e2bSKuba Brecka   return m_opaque_sp.get();
49a5ea1e2bSKuba Brecka }
50a5ea1e2bSKuba Brecka 
51b9c1b51eSKate Stone lldb_private::ThreadCollection *SBThreadCollection::operator->() const {
52a5ea1e2bSKuba Brecka   return m_opaque_sp.operator->();
53a5ea1e2bSKuba Brecka }
54a5ea1e2bSKuba Brecka 
55b9c1b51eSKate Stone lldb::ThreadCollectionSP &SBThreadCollection::operator*() {
56a5ea1e2bSKuba Brecka   return m_opaque_sp;
57a5ea1e2bSKuba Brecka }
58a5ea1e2bSKuba Brecka 
59b9c1b51eSKate Stone const lldb::ThreadCollectionSP &SBThreadCollection::operator*() const {
60a5ea1e2bSKuba Brecka   return m_opaque_sp;
61a5ea1e2bSKuba Brecka }
62a5ea1e2bSKuba Brecka 
63baf5664fSJonas Devlieghere bool SBThreadCollection::IsValid() const {
64baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, IsValid);
657f5237bcSPavel Labath   return this->operator bool();
667f5237bcSPavel Labath }
677f5237bcSPavel Labath SBThreadCollection::operator bool() const {
687f5237bcSPavel Labath   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, operator bool);
69baf5664fSJonas Devlieghere 
70248a1305SKonrad Kleine   return m_opaque_sp.get() != nullptr;
71baf5664fSJonas Devlieghere }
72a5ea1e2bSKuba Brecka 
73b9c1b51eSKate Stone size_t SBThreadCollection::GetSize() {
74baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadCollection, GetSize);
75baf5664fSJonas Devlieghere 
76a5ea1e2bSKuba Brecka   if (m_opaque_sp)
77a5ea1e2bSKuba Brecka     return m_opaque_sp->GetSize();
78a5ea1e2bSKuba Brecka   return 0;
79a5ea1e2bSKuba Brecka }
80a5ea1e2bSKuba Brecka 
81b9c1b51eSKate Stone SBThread SBThreadCollection::GetThreadAtIndex(size_t idx) {
82baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex,
83baf5664fSJonas Devlieghere                      (size_t), idx);
84baf5664fSJonas Devlieghere 
85a5ea1e2bSKuba Brecka   SBThread thread;
86a5ea1e2bSKuba Brecka   if (m_opaque_sp && idx < m_opaque_sp->GetSize())
87a5ea1e2bSKuba Brecka     thread = m_opaque_sp->GetThreadAtIndex(idx);
88baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(thread);
89a5ea1e2bSKuba Brecka }
90