1 //===-- SBUnixSignals.cpp -------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Target/Platform.h"
10 #include "lldb/Target/Process.h"
11 #include "lldb/Target/UnixSignals.h"
12 #include "lldb/Utility/Instrumentation.h"
13 #include "lldb/lldb-defines.h"
15 #include "lldb/API/SBUnixSignals.h"
18 using namespace lldb_private
;
20 SBUnixSignals::SBUnixSignals() { LLDB_INSTRUMENT_VA(this); }
22 SBUnixSignals::SBUnixSignals(const SBUnixSignals
&rhs
)
23 : m_opaque_wp(rhs
.m_opaque_wp
) {
24 LLDB_INSTRUMENT_VA(this, rhs
);
27 SBUnixSignals::SBUnixSignals(ProcessSP
&process_sp
)
28 : m_opaque_wp(process_sp
? process_sp
->GetUnixSignals() : nullptr) {}
30 SBUnixSignals::SBUnixSignals(PlatformSP
&platform_sp
)
31 : m_opaque_wp(platform_sp
? platform_sp
->GetUnixSignals() : nullptr) {}
33 const SBUnixSignals
&SBUnixSignals::operator=(const SBUnixSignals
&rhs
) {
34 LLDB_INSTRUMENT_VA(this, rhs
);
37 m_opaque_wp
= rhs
.m_opaque_wp
;
41 SBUnixSignals::~SBUnixSignals() = default;
43 UnixSignalsSP
SBUnixSignals::GetSP() const { return m_opaque_wp
.lock(); }
45 void SBUnixSignals::SetSP(const UnixSignalsSP
&signals_sp
) {
46 m_opaque_wp
= signals_sp
;
49 void SBUnixSignals::Clear() {
50 LLDB_INSTRUMENT_VA(this);
55 bool SBUnixSignals::IsValid() const {
56 LLDB_INSTRUMENT_VA(this);
57 return this->operator bool();
59 SBUnixSignals::operator bool() const {
60 LLDB_INSTRUMENT_VA(this);
62 return static_cast<bool>(GetSP());
65 const char *SBUnixSignals::GetSignalAsCString(int32_t signo
) const {
66 LLDB_INSTRUMENT_VA(this, signo
);
68 if (auto signals_sp
= GetSP())
69 return ConstString(signals_sp
->GetSignalAsStringRef(signo
)).GetCString();
74 int32_t SBUnixSignals::GetSignalNumberFromName(const char *name
) const {
75 LLDB_INSTRUMENT_VA(this, name
);
77 if (auto signals_sp
= GetSP())
78 return signals_sp
->GetSignalNumberFromName(name
);
80 return LLDB_INVALID_SIGNAL_NUMBER
;
83 bool SBUnixSignals::GetShouldSuppress(int32_t signo
) const {
84 LLDB_INSTRUMENT_VA(this, signo
);
86 if (auto signals_sp
= GetSP())
87 return signals_sp
->GetShouldSuppress(signo
);
92 bool SBUnixSignals::SetShouldSuppress(int32_t signo
, bool value
) {
93 LLDB_INSTRUMENT_VA(this, signo
, value
);
95 auto signals_sp
= GetSP();
98 return signals_sp
->SetShouldSuppress(signo
, value
);
103 bool SBUnixSignals::GetShouldStop(int32_t signo
) const {
104 LLDB_INSTRUMENT_VA(this, signo
);
106 if (auto signals_sp
= GetSP())
107 return signals_sp
->GetShouldStop(signo
);
112 bool SBUnixSignals::SetShouldStop(int32_t signo
, bool value
) {
113 LLDB_INSTRUMENT_VA(this, signo
, value
);
115 auto signals_sp
= GetSP();
118 return signals_sp
->SetShouldStop(signo
, value
);
123 bool SBUnixSignals::GetShouldNotify(int32_t signo
) const {
124 LLDB_INSTRUMENT_VA(this, signo
);
126 if (auto signals_sp
= GetSP())
127 return signals_sp
->GetShouldNotify(signo
);
132 bool SBUnixSignals::SetShouldNotify(int32_t signo
, bool value
) {
133 LLDB_INSTRUMENT_VA(this, signo
, value
);
135 auto signals_sp
= GetSP();
138 return signals_sp
->SetShouldNotify(signo
, value
);
143 int32_t SBUnixSignals::GetNumSignals() const {
144 LLDB_INSTRUMENT_VA(this);
146 if (auto signals_sp
= GetSP())
147 return signals_sp
->GetNumSignals();
152 int32_t SBUnixSignals::GetSignalAtIndex(int32_t index
) const {
153 LLDB_INSTRUMENT_VA(this, index
);
155 if (auto signals_sp
= GetSP())
156 return signals_sp
->GetSignalAtIndex(index
);
158 return LLDB_INVALID_SIGNAL_NUMBER
;