xref: /src/contrib/llvm-project/lldb/source/API/SBUnixSignals.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1cfca06d7SDimitry Andric //===-- SBUnixSignals.cpp -------------------------------------------------===//
20cac4ca3SEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60cac4ca3SEd Maste //
70cac4ca3SEd Maste //===----------------------------------------------------------------------===//
80cac4ca3SEd Maste 
914f1b3e8SDimitry Andric #include "lldb/Target/Platform.h"
1014f1b3e8SDimitry Andric #include "lldb/Target/Process.h"
1114f1b3e8SDimitry Andric #include "lldb/Target/UnixSignals.h"
126f8fc217SDimitry Andric #include "lldb/Utility/Instrumentation.h"
1314f1b3e8SDimitry Andric #include "lldb/lldb-defines.h"
140cac4ca3SEd Maste 
150cac4ca3SEd Maste #include "lldb/API/SBUnixSignals.h"
160cac4ca3SEd Maste 
170cac4ca3SEd Maste using namespace lldb;
180cac4ca3SEd Maste using namespace lldb_private;
190cac4ca3SEd Maste 
SBUnixSignals()206f8fc217SDimitry Andric SBUnixSignals::SBUnixSignals() { LLDB_INSTRUMENT_VA(this); }
210cac4ca3SEd Maste 
SBUnixSignals(const SBUnixSignals & rhs)2214f1b3e8SDimitry Andric SBUnixSignals::SBUnixSignals(const SBUnixSignals &rhs)
235f29bb8aSDimitry Andric     : m_opaque_wp(rhs.m_opaque_wp) {
246f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
255f29bb8aSDimitry Andric }
260cac4ca3SEd Maste 
SBUnixSignals(ProcessSP & process_sp)2714f1b3e8SDimitry Andric SBUnixSignals::SBUnixSignals(ProcessSP &process_sp)
2814f1b3e8SDimitry Andric     : m_opaque_wp(process_sp ? process_sp->GetUnixSignals() : nullptr) {}
29027f1c96SDimitry Andric 
SBUnixSignals(PlatformSP & platform_sp)3014f1b3e8SDimitry Andric SBUnixSignals::SBUnixSignals(PlatformSP &platform_sp)
3114f1b3e8SDimitry Andric     : m_opaque_wp(platform_sp ? platform_sp->GetUnixSignals() : nullptr) {}
320cac4ca3SEd Maste 
operator =(const SBUnixSignals & rhs)3314f1b3e8SDimitry Andric const SBUnixSignals &SBUnixSignals::operator=(const SBUnixSignals &rhs) {
346f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
355f29bb8aSDimitry Andric 
360cac4ca3SEd Maste   if (this != &rhs)
370cac4ca3SEd Maste     m_opaque_wp = rhs.m_opaque_wp;
386f8fc217SDimitry Andric   return *this;
390cac4ca3SEd Maste }
400cac4ca3SEd Maste 
41cfca06d7SDimitry Andric SBUnixSignals::~SBUnixSignals() = default;
420cac4ca3SEd Maste 
GetSP() const4314f1b3e8SDimitry Andric UnixSignalsSP SBUnixSignals::GetSP() const { return m_opaque_wp.lock(); }
440cac4ca3SEd Maste 
SetSP(const UnixSignalsSP & signals_sp)4514f1b3e8SDimitry Andric void SBUnixSignals::SetSP(const UnixSignalsSP &signals_sp) {
46027f1c96SDimitry Andric   m_opaque_wp = signals_sp;
470cac4ca3SEd Maste }
480cac4ca3SEd Maste 
Clear()495f29bb8aSDimitry Andric void SBUnixSignals::Clear() {
506f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
510cac4ca3SEd Maste 
525f29bb8aSDimitry Andric   m_opaque_wp.reset();
535f29bb8aSDimitry Andric }
545f29bb8aSDimitry Andric 
IsValid() const555f29bb8aSDimitry Andric bool SBUnixSignals::IsValid() const {
566f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
575f29bb8aSDimitry Andric   return this->operator bool();
585f29bb8aSDimitry Andric }
operator bool() const595f29bb8aSDimitry Andric SBUnixSignals::operator bool() const {
606f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
615f29bb8aSDimitry Andric 
625f29bb8aSDimitry Andric   return static_cast<bool>(GetSP());
635f29bb8aSDimitry Andric }
640cac4ca3SEd Maste 
GetSignalAsCString(int32_t signo) const6514f1b3e8SDimitry Andric const char *SBUnixSignals::GetSignalAsCString(int32_t signo) const {
666f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, signo);
675f29bb8aSDimitry Andric 
68027f1c96SDimitry Andric   if (auto signals_sp = GetSP())
69b1c73532SDimitry Andric     return ConstString(signals_sp->GetSignalAsStringRef(signo)).GetCString();
70027f1c96SDimitry Andric 
71027f1c96SDimitry Andric   return nullptr;
720cac4ca3SEd Maste }
730cac4ca3SEd Maste 
GetSignalNumberFromName(const char * name) const7414f1b3e8SDimitry Andric int32_t SBUnixSignals::GetSignalNumberFromName(const char *name) const {
756f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name);
765f29bb8aSDimitry Andric 
77027f1c96SDimitry Andric   if (auto signals_sp = GetSP())
78027f1c96SDimitry Andric     return signals_sp->GetSignalNumberFromName(name);
79027f1c96SDimitry Andric 
80027f1c96SDimitry Andric   return LLDB_INVALID_SIGNAL_NUMBER;
810cac4ca3SEd Maste }
820cac4ca3SEd Maste 
GetShouldSuppress(int32_t signo) const8314f1b3e8SDimitry Andric bool SBUnixSignals::GetShouldSuppress(int32_t signo) const {
846f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, signo);
855f29bb8aSDimitry Andric 
86027f1c96SDimitry Andric   if (auto signals_sp = GetSP())
87027f1c96SDimitry Andric     return signals_sp->GetShouldSuppress(signo);
88027f1c96SDimitry Andric 
890cac4ca3SEd Maste   return false;
900cac4ca3SEd Maste }
910cac4ca3SEd Maste 
SetShouldSuppress(int32_t signo,bool value)9214f1b3e8SDimitry Andric bool SBUnixSignals::SetShouldSuppress(int32_t signo, bool value) {
936f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, signo, value);
940cac4ca3SEd Maste 
955f29bb8aSDimitry Andric   auto signals_sp = GetSP();
960cac4ca3SEd Maste 
97027f1c96SDimitry Andric   if (signals_sp)
98027f1c96SDimitry Andric     return signals_sp->SetShouldSuppress(signo, value);
99027f1c96SDimitry Andric 
1000cac4ca3SEd Maste   return false;
1010cac4ca3SEd Maste }
1020cac4ca3SEd Maste 
GetShouldStop(int32_t signo) const10314f1b3e8SDimitry Andric bool SBUnixSignals::GetShouldStop(int32_t signo) const {
1046f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, signo);
1055f29bb8aSDimitry Andric 
106027f1c96SDimitry Andric   if (auto signals_sp = GetSP())
107027f1c96SDimitry Andric     return signals_sp->GetShouldStop(signo);
108027f1c96SDimitry Andric 
1090cac4ca3SEd Maste   return false;
1100cac4ca3SEd Maste }
1110cac4ca3SEd Maste 
SetShouldStop(int32_t signo,bool value)11214f1b3e8SDimitry Andric bool SBUnixSignals::SetShouldStop(int32_t signo, bool value) {
1136f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, signo, value);
1140cac4ca3SEd Maste 
1155f29bb8aSDimitry Andric   auto signals_sp = GetSP();
1160cac4ca3SEd Maste 
117027f1c96SDimitry Andric   if (signals_sp)
118027f1c96SDimitry Andric     return signals_sp->SetShouldStop(signo, value);
119027f1c96SDimitry Andric 
1200cac4ca3SEd Maste   return false;
1210cac4ca3SEd Maste }
1220cac4ca3SEd Maste 
GetShouldNotify(int32_t signo) const12314f1b3e8SDimitry Andric bool SBUnixSignals::GetShouldNotify(int32_t signo) const {
1246f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, signo);
1255f29bb8aSDimitry Andric 
126027f1c96SDimitry Andric   if (auto signals_sp = GetSP())
127027f1c96SDimitry Andric     return signals_sp->GetShouldNotify(signo);
128027f1c96SDimitry Andric 
1290cac4ca3SEd Maste   return false;
1300cac4ca3SEd Maste }
1310cac4ca3SEd Maste 
SetShouldNotify(int32_t signo,bool value)13214f1b3e8SDimitry Andric bool SBUnixSignals::SetShouldNotify(int32_t signo, bool value) {
1336f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, signo, value);
1340cac4ca3SEd Maste 
1355f29bb8aSDimitry Andric   auto signals_sp = GetSP();
1360cac4ca3SEd Maste 
137027f1c96SDimitry Andric   if (signals_sp)
138027f1c96SDimitry Andric     return signals_sp->SetShouldNotify(signo, value);
139027f1c96SDimitry Andric 
1400cac4ca3SEd Maste   return false;
1410cac4ca3SEd Maste }
1420cac4ca3SEd Maste 
GetNumSignals() const14314f1b3e8SDimitry Andric int32_t SBUnixSignals::GetNumSignals() const {
1446f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1455f29bb8aSDimitry Andric 
146027f1c96SDimitry Andric   if (auto signals_sp = GetSP())
147027f1c96SDimitry Andric     return signals_sp->GetNumSignals();
148027f1c96SDimitry Andric 
149027f1c96SDimitry Andric   return -1;
1500cac4ca3SEd Maste }
1510cac4ca3SEd Maste 
GetSignalAtIndex(int32_t index) const15214f1b3e8SDimitry Andric int32_t SBUnixSignals::GetSignalAtIndex(int32_t index) const {
1536f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, index);
1545f29bb8aSDimitry Andric 
155027f1c96SDimitry Andric   if (auto signals_sp = GetSP())
156027f1c96SDimitry Andric     return signals_sp->GetSignalAtIndex(index);
157027f1c96SDimitry Andric 
1580cac4ca3SEd Maste   return LLDB_INVALID_SIGNAL_NUMBER;
1590cac4ca3SEd Maste }
160