Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- SBThreadCollection.cpp --------------------------------------------===// |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // 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 Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/API/SBThreadCollection.h" |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 10 | #include "SBReproducerPrivate.h" |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBThread.h" |
| 12 | #include "lldb/Target/ThreadList.h" |
| 13 | |
| 14 | using namespace lldb; |
| 15 | using namespace lldb_private; |
| 16 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 17 | SBThreadCollection::SBThreadCollection() : m_opaque_sp() { |
| 18 | LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThreadCollection); |
| 19 | } |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 20 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 22 | : m_opaque_sp(rhs.m_opaque_sp) { |
| 23 | LLDB_RECORD_CONSTRUCTOR(SBThreadCollection, |
| 24 | (const lldb::SBThreadCollection &), rhs); |
| 25 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | |
| 27 | const SBThreadCollection &SBThreadCollection:: |
| 28 | operator=(const SBThreadCollection &rhs) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 29 | LLDB_RECORD_METHOD( |
| 30 | const lldb::SBThreadCollection &, |
| 31 | SBThreadCollection, operator=,(const lldb::SBThreadCollection &), rhs); |
| 32 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | if (this != &rhs) |
| 34 | m_opaque_sp = rhs.m_opaque_sp; |
Jonas Devlieghere | 306809f | 2019-04-03 21:31:22 +0000 | [diff] [blame] | 35 | return LLDB_RECORD_RESULT(*this); |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | SBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads) |
| 39 | : m_opaque_sp(threads) {} |
| 40 | |
| 41 | SBThreadCollection::~SBThreadCollection() {} |
| 42 | |
| 43 | void SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) { |
| 44 | m_opaque_sp = threads; |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | lldb_private::ThreadCollection *SBThreadCollection::get() const { |
| 48 | return m_opaque_sp.get(); |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | lldb_private::ThreadCollection *SBThreadCollection::operator->() const { |
| 52 | return m_opaque_sp.operator->(); |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | lldb::ThreadCollectionSP &SBThreadCollection::operator*() { |
| 56 | return m_opaque_sp; |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | const lldb::ThreadCollectionSP &SBThreadCollection::operator*() const { |
| 60 | return m_opaque_sp; |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 63 | bool SBThreadCollection::IsValid() const { |
| 64 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, IsValid); |
Pavel Labath | 7f5237b | 2019-03-11 13:58:46 +0000 | [diff] [blame] | 65 | return this->operator bool(); |
| 66 | } |
| 67 | SBThreadCollection::operator bool() const { |
| 68 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, operator bool); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 69 | |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 70 | return m_opaque_sp.get() != nullptr; |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 71 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | |
| 73 | size_t SBThreadCollection::GetSize() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 74 | LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadCollection, GetSize); |
| 75 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | if (m_opaque_sp) |
| 77 | return m_opaque_sp->GetSize(); |
| 78 | return 0; |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | SBThread SBThreadCollection::GetThreadAtIndex(size_t idx) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 82 | LLDB_RECORD_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex, |
| 83 | (size_t), idx); |
| 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | SBThread thread; |
| 86 | if (m_opaque_sp && idx < m_opaque_sp->GetSize()) |
| 87 | thread = m_opaque_sp->GetThreadAtIndex(idx); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 88 | return LLDB_RECORD_RESULT(thread); |
Kuba Brecka | a5ea1e2 | 2014-09-06 01:21:19 +0000 | [diff] [blame] | 89 | } |
Michal Gorny | ae211ec | 2019-03-19 17:13:13 +0000 | [diff] [blame] | 90 | |
| 91 | namespace lldb_private { |
| 92 | namespace repro { |
| 93 | |
| 94 | template <> |
| 95 | void 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 | } |