blob: afaf9fbe8ed7d9760c64811dfbc85e85c3e08bed [file] [log] [blame]
Raphael Isemann80814282020-01-24 08:23:27 +01001//===-- SBThreadCollection.cpp --------------------------------------------===//
Kuba Breckaa5ea1e22014-09-06 01:21:19 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Kuba Breckaa5ea1e22014-09-06 01:21:19 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/API/SBThreadCollection.h"
Jonas Devliegherebaf56642019-03-06 00:06:00 +000010#include "SBReproducerPrivate.h"
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000011#include "lldb/API/SBThread.h"
12#include "lldb/Target/ThreadList.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
Jonas Devliegherebaf56642019-03-06 00:06:00 +000017SBThreadCollection::SBThreadCollection() : m_opaque_sp() {
18 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThreadCollection);
19}
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000020
Kate Stoneb9c1b512016-09-06 20:57:50 +000021SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs)
Jonas Devliegherebaf56642019-03-06 00:06:00 +000022 : m_opaque_sp(rhs.m_opaque_sp) {
23 LLDB_RECORD_CONSTRUCTOR(SBThreadCollection,
24 (const lldb::SBThreadCollection &), rhs);
25}
Kate Stoneb9c1b512016-09-06 20:57:50 +000026
27const SBThreadCollection &SBThreadCollection::
28operator=(const SBThreadCollection &rhs) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000029 LLDB_RECORD_METHOD(
30 const lldb::SBThreadCollection &,
31 SBThreadCollection, operator=,(const lldb::SBThreadCollection &), rhs);
32
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 if (this != &rhs)
34 m_opaque_sp = rhs.m_opaque_sp;
Jonas Devlieghere306809f2019-04-03 21:31:22 +000035 return LLDB_RECORD_RESULT(*this);
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000036}
37
Kate Stoneb9c1b512016-09-06 20:57:50 +000038SBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads)
39 : m_opaque_sp(threads) {}
40
41SBThreadCollection::~SBThreadCollection() {}
42
43void SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) {
44 m_opaque_sp = threads;
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000045}
46
Kate Stoneb9c1b512016-09-06 20:57:50 +000047lldb_private::ThreadCollection *SBThreadCollection::get() const {
48 return m_opaque_sp.get();
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000049}
50
Kate Stoneb9c1b512016-09-06 20:57:50 +000051lldb_private::ThreadCollection *SBThreadCollection::operator->() const {
52 return m_opaque_sp.operator->();
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000053}
54
Kate Stoneb9c1b512016-09-06 20:57:50 +000055lldb::ThreadCollectionSP &SBThreadCollection::operator*() {
56 return m_opaque_sp;
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000057}
58
Kate Stoneb9c1b512016-09-06 20:57:50 +000059const lldb::ThreadCollectionSP &SBThreadCollection::operator*() const {
60 return m_opaque_sp;
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000061}
62
Jonas Devliegherebaf56642019-03-06 00:06:00 +000063bool SBThreadCollection::IsValid() const {
64 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, IsValid);
Pavel Labath7f5237b2019-03-11 13:58:46 +000065 return this->operator bool();
66}
67SBThreadCollection::operator bool() const {
68 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, operator bool);
Jonas Devliegherebaf56642019-03-06 00:06:00 +000069
Konrad Kleine248a1302019-05-23 11:14:47 +000070 return m_opaque_sp.get() != nullptr;
Jonas Devliegherebaf56642019-03-06 00:06:00 +000071}
Kate Stoneb9c1b512016-09-06 20:57:50 +000072
73size_t SBThreadCollection::GetSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000074 LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadCollection, GetSize);
75
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 if (m_opaque_sp)
77 return m_opaque_sp->GetSize();
78 return 0;
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000079}
80
Kate Stoneb9c1b512016-09-06 20:57:50 +000081SBThread SBThreadCollection::GetThreadAtIndex(size_t idx) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000082 LLDB_RECORD_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex,
83 (size_t), idx);
84
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 SBThread thread;
86 if (m_opaque_sp && idx < m_opaque_sp->GetSize())
87 thread = m_opaque_sp->GetThreadAtIndex(idx);
Jonas Devliegherebaf56642019-03-06 00:06:00 +000088 return LLDB_RECORD_RESULT(thread);
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000089}
Michal Gornyae211ec2019-03-19 17:13:13 +000090
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}