1//===-- SBUnixSignals.cpp -------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
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"
14
15#include "lldb/API/SBUnixSignals.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20SBUnixSignals::SBUnixSignals() { LLDB_INSTRUMENT_VA(this); }
21
22SBUnixSignals::SBUnixSignals(const SBUnixSignals &rhs)
23 : m_opaque_wp(rhs.m_opaque_wp) {
24 LLDB_INSTRUMENT_VA(this, rhs);
25}
26
27SBUnixSignals::SBUnixSignals(ProcessSP &process_sp)
28 : m_opaque_wp(process_sp ? process_sp->GetUnixSignals() : nullptr) {}
29
30SBUnixSignals::SBUnixSignals(PlatformSP &platform_sp)
31 : m_opaque_wp(platform_sp ? platform_sp->GetUnixSignals() : nullptr) {}
32
33const SBUnixSignals &SBUnixSignals::operator=(const SBUnixSignals &rhs) {
34 LLDB_INSTRUMENT_VA(this, rhs);
35
36 if (this != &rhs)
37 m_opaque_wp = rhs.m_opaque_wp;
38 return *this;
39}
40
41SBUnixSignals::~SBUnixSignals() = default;
42
43UnixSignalsSP SBUnixSignals::GetSP() const { return m_opaque_wp.lock(); }
44
45void SBUnixSignals::SetSP(const UnixSignalsSP &signals_sp) {
46 m_opaque_wp = signals_sp;
47}
48
49void SBUnixSignals::Clear() {
50 LLDB_INSTRUMENT_VA(this);
51
52 m_opaque_wp.reset();
53}
54
55bool SBUnixSignals::IsValid() const {
56 LLDB_INSTRUMENT_VA(this);
57 return this->operator bool();
58}
59SBUnixSignals::operator bool() const {
60 LLDB_INSTRUMENT_VA(this);
61
62 return static_cast<bool>(GetSP());
63}
64
65const char *SBUnixSignals::GetSignalAsCString(int32_t signo) const {
66 LLDB_INSTRUMENT_VA(this, signo);
67
68 if (auto signals_sp = GetSP())
69 return ConstString(signals_sp->GetSignalAsStringRef(signo)).GetCString();
70
71 return nullptr;
72}
73
74int32_t SBUnixSignals::GetSignalNumberFromName(const char *name) const {
75 LLDB_INSTRUMENT_VA(this, name);
76
77 if (auto signals_sp = GetSP())
78 return signals_sp->GetSignalNumberFromName(name);
79
80 return LLDB_INVALID_SIGNAL_NUMBER;
81}
82
83bool SBUnixSignals::GetShouldSuppress(int32_t signo) const {
84 LLDB_INSTRUMENT_VA(this, signo);
85
86 if (auto signals_sp = GetSP())
87 return signals_sp->GetShouldSuppress(signo);
88
89 return false;
90}
91
92bool SBUnixSignals::SetShouldSuppress(int32_t signo, bool value) {
93 LLDB_INSTRUMENT_VA(this, signo, value);
94
95 auto signals_sp = GetSP();
96
97 if (signals_sp)
98 return signals_sp->SetShouldSuppress(signo, value);
99
100 return false;
101}
102
103bool SBUnixSignals::GetShouldStop(int32_t signo) const {
104 LLDB_INSTRUMENT_VA(this, signo);
105
106 if (auto signals_sp = GetSP())
107 return signals_sp->GetShouldStop(signo);
108
109 return false;
110}
111
112bool SBUnixSignals::SetShouldStop(int32_t signo, bool value) {
113 LLDB_INSTRUMENT_VA(this, signo, value);
114
115 auto signals_sp = GetSP();
116
117 if (signals_sp)
118 return signals_sp->SetShouldStop(signo, value);
119
120 return false;
121}
122
123bool SBUnixSignals::GetShouldNotify(int32_t signo) const {
124 LLDB_INSTRUMENT_VA(this, signo);
125
126 if (auto signals_sp = GetSP())
127 return signals_sp->GetShouldNotify(signo);
128
129 return false;
130}
131
132bool SBUnixSignals::SetShouldNotify(int32_t signo, bool value) {
133 LLDB_INSTRUMENT_VA(this, signo, value);
134
135 auto signals_sp = GetSP();
136
137 if (signals_sp)
138 return signals_sp->SetShouldNotify(signo, value);
139
140 return false;
141}
142
143int32_t SBUnixSignals::GetNumSignals() const {
144 LLDB_INSTRUMENT_VA(this);
145
146 if (auto signals_sp = GetSP())
147 return signals_sp->GetNumSignals();
148
149 return -1;
150}
151
152int32_t SBUnixSignals::GetSignalAtIndex(int32_t index) const {
153 LLDB_INSTRUMENT_VA(this, index);
154
155 if (auto signals_sp = GetSP())
156 return signals_sp->GetSignalAtIndex(index);
157
158 return LLDB_INVALID_SIGNAL_NUMBER;
159}
160

source code of lldb/source/API/SBUnixSignals.cpp