2014-09-06 09:21:19 +08:00
|
|
|
//===-- SBThreadCollection.cpp ----------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-09-06 09:21:19 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBThreadCollection.h"
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
2014-09-06 09:21:19 +08:00
|
|
|
#include "lldb/API/SBThread.h"
|
|
|
|
#include "lldb/Target/ThreadList.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBThreadCollection::SBThreadCollection() : m_opaque_sp() {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThreadCollection);
|
|
|
|
}
|
2014-09-06 09:21:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs)
|
2019-03-06 08:06:00 +08:00
|
|
|
: m_opaque_sp(rhs.m_opaque_sp) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBThreadCollection,
|
|
|
|
(const lldb::SBThreadCollection &), rhs);
|
|
|
|
}
|
2014-09-06 09:21:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const SBThreadCollection &SBThreadCollection::
|
|
|
|
operator=(const SBThreadCollection &rhs) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(
|
|
|
|
const lldb::SBThreadCollection &,
|
|
|
|
SBThreadCollection, operator=,(const lldb::SBThreadCollection &), rhs);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (this != &rhs)
|
|
|
|
m_opaque_sp = rhs.m_opaque_sp;
|
2019-04-04 05:31:22 +08:00
|
|
|
return LLDB_RECORD_RESULT(*this);
|
2014-09-06 09:21:19 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads)
|
|
|
|
: m_opaque_sp(threads) {}
|
2014-09-06 09:21:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBThreadCollection::~SBThreadCollection() {}
|
2014-09-06 09:21:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) {
|
|
|
|
m_opaque_sp = threads;
|
2014-09-06 09:21:19 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb_private::ThreadCollection *SBThreadCollection::get() const {
|
|
|
|
return m_opaque_sp.get();
|
2014-09-06 09:21:19 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb_private::ThreadCollection *SBThreadCollection::operator->() const {
|
|
|
|
return m_opaque_sp.operator->();
|
2014-09-06 09:21:19 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::ThreadCollectionSP &SBThreadCollection::operator*() {
|
|
|
|
return m_opaque_sp;
|
2014-09-06 09:21:19 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb::ThreadCollectionSP &SBThreadCollection::operator*() const {
|
|
|
|
return m_opaque_sp;
|
2014-09-06 09:21:19 +08:00
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
bool SBThreadCollection::IsValid() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, IsValid);
|
Add "operator bool" to SB APIs
Summary:
Our python version of the SB API has (the python equivalent of)
operator bool, but the C++ version doesn't.
This is because our python operators are added by modify-python-lldb.py,
which performs postprocessing on the swig-generated interface files.
In this patch, I add the "operator bool" to all SB classes which have an
IsValid method (which is the same logic used by modify-python-lldb.py).
This way, we make the two interfaces more constent, and it allows us to
rely on swig's automatic syntesis of python __nonzero__ methods instead
of doing manual fixups.
Reviewers: zturner, jingham, clayborg, jfb, serge-sans-paille
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D58792
llvm-svn: 355824
2019-03-11 21:58:46 +08:00
|
|
|
return this->operator bool();
|
|
|
|
}
|
|
|
|
SBThreadCollection::operator bool() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, operator bool);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
|
|
|
return m_opaque_sp.get() != NULL;
|
|
|
|
}
|
2014-09-06 09:21:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t SBThreadCollection::GetSize() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadCollection, GetSize);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
return m_opaque_sp->GetSize();
|
|
|
|
return 0;
|
2014-09-06 09:21:19 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBThread SBThreadCollection::GetThreadAtIndex(size_t idx) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex,
|
|
|
|
(size_t), idx);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBThread thread;
|
|
|
|
if (m_opaque_sp && idx < m_opaque_sp->GetSize())
|
|
|
|
thread = m_opaque_sp->GetThreadAtIndex(idx);
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(thread);
|
2014-09-06 09:21:19 +08:00
|
|
|
}
|
2019-03-20 01:13:13 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
namespace repro {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void RegisterMethods<SBThreadCollection>(Registry &R) {
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBThreadCollection, ());
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBThreadCollection,
|
|
|
|
(const lldb::SBThreadCollection &));
|
|
|
|
LLDB_REGISTER_METHOD(
|
|
|
|
const lldb::SBThreadCollection &,
|
|
|
|
SBThreadCollection, operator=,(const lldb::SBThreadCollection &));
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBThreadCollection, IsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBThreadCollection, operator bool, ());
|
|
|
|
LLDB_REGISTER_METHOD(size_t, SBThreadCollection, GetSize, ());
|
|
|
|
LLDB_REGISTER_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex,
|
|
|
|
(size_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|