1 //===-- SBUnixSignals.cpp -------------------------------------------*- C++
2 //-*-===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
9
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"
15
16 #include "lldb/API/SBUnixSignals.h"
17
18 using namespace lldb;
19 using namespace lldb_private;
20
SBUnixSignals()21 SBUnixSignals::SBUnixSignals() {
22 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBUnixSignals);
23 }
24
SBUnixSignals(const SBUnixSignals & rhs)25 SBUnixSignals::SBUnixSignals(const SBUnixSignals &rhs)
26 : m_opaque_wp(rhs.m_opaque_wp) {
27 LLDB_RECORD_CONSTRUCTOR(SBUnixSignals, (const lldb::SBUnixSignals &), rhs);
28 }
29
SBUnixSignals(ProcessSP & process_sp)30 SBUnixSignals::SBUnixSignals(ProcessSP &process_sp)
31 : m_opaque_wp(process_sp ? process_sp->GetUnixSignals() : nullptr) {}
32
SBUnixSignals(PlatformSP & platform_sp)33 SBUnixSignals::SBUnixSignals(PlatformSP &platform_sp)
34 : m_opaque_wp(platform_sp ? platform_sp->GetUnixSignals() : nullptr) {}
35
operator =(const SBUnixSignals & rhs)36 const SBUnixSignals &SBUnixSignals::operator=(const SBUnixSignals &rhs) {
37 LLDB_RECORD_METHOD(const lldb::SBUnixSignals &,
38 SBUnixSignals, operator=,(const lldb::SBUnixSignals &),
39 rhs);
40
41 if (this != &rhs)
42 m_opaque_wp = rhs.m_opaque_wp;
43 return LLDB_RECORD_RESULT(*this);
44 }
45
~SBUnixSignals()46 SBUnixSignals::~SBUnixSignals() {}
47
GetSP() const48 UnixSignalsSP SBUnixSignals::GetSP() const { return m_opaque_wp.lock(); }
49
SetSP(const UnixSignalsSP & signals_sp)50 void SBUnixSignals::SetSP(const UnixSignalsSP &signals_sp) {
51 m_opaque_wp = signals_sp;
52 }
53
Clear()54 void SBUnixSignals::Clear() {
55 LLDB_RECORD_METHOD_NO_ARGS(void, SBUnixSignals, Clear);
56
57 m_opaque_wp.reset();
58 }
59
IsValid() const60 bool SBUnixSignals::IsValid() const {
61 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBUnixSignals, IsValid);
62 return this->operator bool();
63 }
operator bool() const64 SBUnixSignals::operator bool() const {
65 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBUnixSignals, operator bool);
66
67 return static_cast<bool>(GetSP());
68 }
69
GetSignalAsCString(int32_t signo) const70 const char *SBUnixSignals::GetSignalAsCString(int32_t signo) const {
71 LLDB_RECORD_METHOD_CONST(const char *, SBUnixSignals, GetSignalAsCString,
72 (int32_t), signo);
73
74 if (auto signals_sp = GetSP())
75 return signals_sp->GetSignalAsCString(signo);
76
77 return nullptr;
78 }
79
GetSignalNumberFromName(const char * name) const80 int32_t SBUnixSignals::GetSignalNumberFromName(const char *name) const {
81 LLDB_RECORD_METHOD_CONST(int32_t, SBUnixSignals, GetSignalNumberFromName,
82 (const char *), name);
83
84 if (auto signals_sp = GetSP())
85 return signals_sp->GetSignalNumberFromName(name);
86
87 return LLDB_INVALID_SIGNAL_NUMBER;
88 }
89
GetShouldSuppress(int32_t signo) const90 bool SBUnixSignals::GetShouldSuppress(int32_t signo) const {
91 LLDB_RECORD_METHOD_CONST(bool, SBUnixSignals, GetShouldSuppress, (int32_t),
92 signo);
93
94 if (auto signals_sp = GetSP())
95 return signals_sp->GetShouldSuppress(signo);
96
97 return false;
98 }
99
SetShouldSuppress(int32_t signo,bool value)100 bool SBUnixSignals::SetShouldSuppress(int32_t signo, bool value) {
101 LLDB_RECORD_METHOD(bool, SBUnixSignals, SetShouldSuppress, (int32_t, bool),
102 signo, value);
103
104 auto signals_sp = GetSP();
105
106 if (signals_sp)
107 return signals_sp->SetShouldSuppress(signo, value);
108
109 return false;
110 }
111
GetShouldStop(int32_t signo) const112 bool SBUnixSignals::GetShouldStop(int32_t signo) const {
113 LLDB_RECORD_METHOD_CONST(bool, SBUnixSignals, GetShouldStop, (int32_t),
114 signo);
115
116 if (auto signals_sp = GetSP())
117 return signals_sp->GetShouldStop(signo);
118
119 return false;
120 }
121
SetShouldStop(int32_t signo,bool value)122 bool SBUnixSignals::SetShouldStop(int32_t signo, bool value) {
123 LLDB_RECORD_METHOD(bool, SBUnixSignals, SetShouldStop, (int32_t, bool), signo,
124 value);
125
126 auto signals_sp = GetSP();
127
128 if (signals_sp)
129 return signals_sp->SetShouldStop(signo, value);
130
131 return false;
132 }
133
GetShouldNotify(int32_t signo) const134 bool SBUnixSignals::GetShouldNotify(int32_t signo) const {
135 LLDB_RECORD_METHOD_CONST(bool, SBUnixSignals, GetShouldNotify, (int32_t),
136 signo);
137
138 if (auto signals_sp = GetSP())
139 return signals_sp->GetShouldNotify(signo);
140
141 return false;
142 }
143
SetShouldNotify(int32_t signo,bool value)144 bool SBUnixSignals::SetShouldNotify(int32_t signo, bool value) {
145 LLDB_RECORD_METHOD(bool, SBUnixSignals, SetShouldNotify, (int32_t, bool),
146 signo, value);
147
148 auto signals_sp = GetSP();
149
150 if (signals_sp)
151 return signals_sp->SetShouldNotify(signo, value);
152
153 return false;
154 }
155
GetNumSignals() const156 int32_t SBUnixSignals::GetNumSignals() const {
157 LLDB_RECORD_METHOD_CONST_NO_ARGS(int32_t, SBUnixSignals, GetNumSignals);
158
159 if (auto signals_sp = GetSP())
160 return signals_sp->GetNumSignals();
161
162 return -1;
163 }
164
GetSignalAtIndex(int32_t index) const165 int32_t SBUnixSignals::GetSignalAtIndex(int32_t index) const {
166 LLDB_RECORD_METHOD_CONST(int32_t, SBUnixSignals, GetSignalAtIndex, (int32_t),
167 index);
168
169 if (auto signals_sp = GetSP())
170 return signals_sp->GetSignalAtIndex(index);
171
172 return LLDB_INVALID_SIGNAL_NUMBER;
173 }
174
175 namespace lldb_private {
176 namespace repro {
177
178 template <>
RegisterMethods(Registry & R)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,
189 (int32_t));
190 LLDB_REGISTER_METHOD_CONST(int32_t, SBUnixSignals, GetSignalNumberFromName,
191 (const char *));
192 LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals, GetShouldSuppress,
193 (int32_t));
194 LLDB_REGISTER_METHOD(bool, SBUnixSignals, SetShouldSuppress,
195 (int32_t, bool));
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,
202 (int32_t));
203 }
204
205 }
206 }
207