1 //===-- SBUnixSignals.cpp -------------------------------------------*- C++
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #include "SBReproducerPrivate.h"
11 #include "lldb/Target/Platform.h"
12 #include "lldb/Target/Process.h"
13 #include "lldb/Target/UnixSignals.h"
14 #include "lldb/lldb-defines.h"
16 #include "lldb/API/SBUnixSignals.h"
19 using namespace lldb_private
;
21 SBUnixSignals::SBUnixSignals() {
22 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBUnixSignals
);
25 SBUnixSignals::SBUnixSignals(const SBUnixSignals
&rhs
)
26 : m_opaque_wp(rhs
.m_opaque_wp
) {
27 LLDB_RECORD_CONSTRUCTOR(SBUnixSignals
, (const lldb::SBUnixSignals
&), rhs
);
30 SBUnixSignals::SBUnixSignals(ProcessSP
&process_sp
)
31 : m_opaque_wp(process_sp
? process_sp
->GetUnixSignals() : nullptr) {}
33 SBUnixSignals::SBUnixSignals(PlatformSP
&platform_sp
)
34 : m_opaque_wp(platform_sp
? platform_sp
->GetUnixSignals() : nullptr) {}
36 const SBUnixSignals
&SBUnixSignals::operator=(const SBUnixSignals
&rhs
) {
37 LLDB_RECORD_METHOD(const lldb::SBUnixSignals
&,
38 SBUnixSignals
, operator=,(const lldb::SBUnixSignals
&),
42 m_opaque_wp
= rhs
.m_opaque_wp
;
43 return LLDB_RECORD_RESULT(*this);
46 SBUnixSignals::~SBUnixSignals() {}
48 UnixSignalsSP
SBUnixSignals::GetSP() const { return m_opaque_wp
.lock(); }
50 void SBUnixSignals::SetSP(const UnixSignalsSP
&signals_sp
) {
51 m_opaque_wp
= signals_sp
;
54 void SBUnixSignals::Clear() {
55 LLDB_RECORD_METHOD_NO_ARGS(void, SBUnixSignals
, Clear
);
60 bool SBUnixSignals::IsValid() const {
61 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBUnixSignals
, IsValid
);
62 return this->operator bool();
64 SBUnixSignals::operator bool() const {
65 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBUnixSignals
, operator bool);
67 return static_cast<bool>(GetSP());
70 const char *SBUnixSignals::GetSignalAsCString(int32_t signo
) const {
71 LLDB_RECORD_METHOD_CONST(const char *, SBUnixSignals
, GetSignalAsCString
,
74 if (auto signals_sp
= GetSP())
75 return signals_sp
->GetSignalAsCString(signo
);
80 int32_t SBUnixSignals::GetSignalNumberFromName(const char *name
) const {
81 LLDB_RECORD_METHOD_CONST(int32_t, SBUnixSignals
, GetSignalNumberFromName
,
82 (const char *), name
);
84 if (auto signals_sp
= GetSP())
85 return signals_sp
->GetSignalNumberFromName(name
);
87 return LLDB_INVALID_SIGNAL_NUMBER
;
90 bool SBUnixSignals::GetShouldSuppress(int32_t signo
) const {
91 LLDB_RECORD_METHOD_CONST(bool, SBUnixSignals
, GetShouldSuppress
, (int32_t),
94 if (auto signals_sp
= GetSP())
95 return signals_sp
->GetShouldSuppress(signo
);
100 bool SBUnixSignals::SetShouldSuppress(int32_t signo
, bool value
) {
101 LLDB_RECORD_METHOD(bool, SBUnixSignals
, SetShouldSuppress
, (int32_t, bool),
104 auto signals_sp
= GetSP();
107 return signals_sp
->SetShouldSuppress(signo
, value
);
112 bool SBUnixSignals::GetShouldStop(int32_t signo
) const {
113 LLDB_RECORD_METHOD_CONST(bool, SBUnixSignals
, GetShouldStop
, (int32_t),
116 if (auto signals_sp
= GetSP())
117 return signals_sp
->GetShouldStop(signo
);
122 bool SBUnixSignals::SetShouldStop(int32_t signo
, bool value
) {
123 LLDB_RECORD_METHOD(bool, SBUnixSignals
, SetShouldStop
, (int32_t, bool), signo
,
126 auto signals_sp
= GetSP();
129 return signals_sp
->SetShouldStop(signo
, value
);
134 bool SBUnixSignals::GetShouldNotify(int32_t signo
) const {
135 LLDB_RECORD_METHOD_CONST(bool, SBUnixSignals
, GetShouldNotify
, (int32_t),
138 if (auto signals_sp
= GetSP())
139 return signals_sp
->GetShouldNotify(signo
);
144 bool SBUnixSignals::SetShouldNotify(int32_t signo
, bool value
) {
145 LLDB_RECORD_METHOD(bool, SBUnixSignals
, SetShouldNotify
, (int32_t, bool),
148 auto signals_sp
= GetSP();
151 return signals_sp
->SetShouldNotify(signo
, value
);
156 int32_t SBUnixSignals::GetNumSignals() const {
157 LLDB_RECORD_METHOD_CONST_NO_ARGS(int32_t, SBUnixSignals
, GetNumSignals
);
159 if (auto signals_sp
= GetSP())
160 return signals_sp
->GetNumSignals();
165 int32_t SBUnixSignals::GetSignalAtIndex(int32_t index
) const {
166 LLDB_RECORD_METHOD_CONST(int32_t, SBUnixSignals
, GetSignalAtIndex
, (int32_t),
169 if (auto signals_sp
= GetSP())
170 return signals_sp
->GetSignalAtIndex(index
);
172 return LLDB_INVALID_SIGNAL_NUMBER
;
175 namespace lldb_private
{
179 void RegisterMethods
<SBUnixSignals
>(Registry
&R
) {
180 LLDB_REGISTER_CONSTRUCTOR(SBUnixSignals
, ());
181 LLDB_REGISTER_CONSTRUCTOR(SBUnixSignals
, (const lldb::SBUnixSignals
&));
182 LLDB_REGISTER_METHOD(
183 const lldb::SBUnixSignals
&,
184 SBUnixSignals
, operator=,(const lldb::SBUnixSignals
&));
185 LLDB_REGISTER_METHOD(void, SBUnixSignals
, Clear
, ());
186 LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals
, IsValid
, ());
187 LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals
, operator bool, ());
188 LLDB_REGISTER_METHOD_CONST(const char *, SBUnixSignals
, GetSignalAsCString
,
190 LLDB_REGISTER_METHOD_CONST(int32_t, SBUnixSignals
, GetSignalNumberFromName
,
192 LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals
, GetShouldSuppress
,
194 LLDB_REGISTER_METHOD(bool, SBUnixSignals
, SetShouldSuppress
,
196 LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals
, GetShouldStop
, (int32_t));
197 LLDB_REGISTER_METHOD(bool, SBUnixSignals
, SetShouldStop
, (int32_t, bool));
198 LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals
, GetShouldNotify
, (int32_t));
199 LLDB_REGISTER_METHOD(bool, SBUnixSignals
, SetShouldNotify
, (int32_t, bool));
200 LLDB_REGISTER_METHOD_CONST(int32_t, SBUnixSignals
, GetNumSignals
, ());
201 LLDB_REGISTER_METHOD_CONST(int32_t, SBUnixSignals
, GetSignalAtIndex
,