blob: b9c1e7554682614d2f0007d7d0141ddfa67445bf [file] [log] [blame]
Kuba Breckaa5ea1e22014-09-06 01:21:19 +00001//===-- SBThreadCollection.cpp ----------------------------------*- C++ -*-===//
2//
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;
35 return *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);
65
66 return m_opaque_sp.get() != NULL;
67}
Kate Stoneb9c1b512016-09-06 20:57:50 +000068
69size_t SBThreadCollection::GetSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000070 LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadCollection, GetSize);
71
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 if (m_opaque_sp)
73 return m_opaque_sp->GetSize();
74 return 0;
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000075}
76
Kate Stoneb9c1b512016-09-06 20:57:50 +000077SBThread SBThreadCollection::GetThreadAtIndex(size_t idx) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000078 LLDB_RECORD_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex,
79 (size_t), idx);
80
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 SBThread thread;
82 if (m_opaque_sp && idx < m_opaque_sp->GetSize())
83 thread = m_opaque_sp->GetThreadAtIndex(idx);
Jonas Devliegherebaf56642019-03-06 00:06:00 +000084 return LLDB_RECORD_RESULT(thread);
Kuba Breckaa5ea1e22014-09-06 01:21:19 +000085}