blob: 88fefcfab7dd12a6e70eaa8cf73590325f137b9c [file] [log] [blame]
Kate Stoneb9c1b512016-09-06 20:57:50 +00001//===-- SBUnixSignals.cpp -------------------------------------------*- C++
2//-*-===//
Todd Fiala802dc4022014-06-23 19:30:49 +00003//
Chandler Carruth2946cd72019-01-19 08:50:56 +00004// 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
Todd Fiala802dc4022014-06-23 19:30:49 +00007//
8//===----------------------------------------------------------------------===//
9
Kate Stoneb9c1b512016-09-06 20:57:50 +000010#include "lldb/Target/Platform.h"
11#include "lldb/Target/Process.h"
12#include "lldb/Target/UnixSignals.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000013#include "lldb/Utility/Log.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000014#include "lldb/lldb-defines.h"
Todd Fiala802dc4022014-06-23 19:30:49 +000015
16#include "lldb/API/SBUnixSignals.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
Kate Stoneb9c1b512016-09-06 20:57:50 +000021SBUnixSignals::SBUnixSignals() {}
Todd Fiala802dc4022014-06-23 19:30:49 +000022
Kate Stoneb9c1b512016-09-06 20:57:50 +000023SBUnixSignals::SBUnixSignals(const SBUnixSignals &rhs)
24 : m_opaque_wp(rhs.m_opaque_wp) {}
25
26SBUnixSignals::SBUnixSignals(ProcessSP &process_sp)
27 : m_opaque_wp(process_sp ? process_sp->GetUnixSignals() : nullptr) {}
28
29SBUnixSignals::SBUnixSignals(PlatformSP &platform_sp)
30 : m_opaque_wp(platform_sp ? platform_sp->GetUnixSignals() : nullptr) {}
31
32const SBUnixSignals &SBUnixSignals::operator=(const SBUnixSignals &rhs) {
33 if (this != &rhs)
34 m_opaque_wp = rhs.m_opaque_wp;
35 return *this;
Todd Fiala802dc4022014-06-23 19:30:49 +000036}
37
Kate Stoneb9c1b512016-09-06 20:57:50 +000038SBUnixSignals::~SBUnixSignals() {}
39
40UnixSignalsSP SBUnixSignals::GetSP() const { return m_opaque_wp.lock(); }
41
42void SBUnixSignals::SetSP(const UnixSignalsSP &signals_sp) {
43 m_opaque_wp = signals_sp;
Chaoren Lin98d0a4b2015-07-14 01:09:28 +000044}
45
Kate Stoneb9c1b512016-09-06 20:57:50 +000046void SBUnixSignals::Clear() { m_opaque_wp.reset(); }
47
48bool SBUnixSignals::IsValid() const { return static_cast<bool>(GetSP()); }
49
50const char *SBUnixSignals::GetSignalAsCString(int32_t signo) const {
51 if (auto signals_sp = GetSP())
52 return signals_sp->GetSignalAsCString(signo);
53
54 return nullptr;
Todd Fiala802dc4022014-06-23 19:30:49 +000055}
56
Kate Stoneb9c1b512016-09-06 20:57:50 +000057int32_t SBUnixSignals::GetSignalNumberFromName(const char *name) const {
58 if (auto signals_sp = GetSP())
59 return signals_sp->GetSignalNumberFromName(name);
60
61 return LLDB_INVALID_SIGNAL_NUMBER;
Todd Fiala802dc4022014-06-23 19:30:49 +000062}
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064bool SBUnixSignals::GetShouldSuppress(int32_t signo) const {
65 if (auto signals_sp = GetSP())
66 return signals_sp->GetShouldSuppress(signo);
67
68 return false;
Todd Fiala802dc4022014-06-23 19:30:49 +000069}
70
Kate Stoneb9c1b512016-09-06 20:57:50 +000071bool SBUnixSignals::SetShouldSuppress(int32_t signo, bool value) {
72 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
73 auto signals_sp = GetSP();
74
75 if (log) {
76 log->Printf("SBUnixSignals(%p)::SetShouldSuppress (signo=%d, value=%d)",
77 static_cast<void *>(signals_sp.get()), signo, value);
78 }
79
80 if (signals_sp)
81 return signals_sp->SetShouldSuppress(signo, value);
82
83 return false;
Todd Fiala802dc4022014-06-23 19:30:49 +000084}
85
Kate Stoneb9c1b512016-09-06 20:57:50 +000086bool SBUnixSignals::GetShouldStop(int32_t signo) const {
87 if (auto signals_sp = GetSP())
88 return signals_sp->GetShouldStop(signo);
89
90 return false;
Todd Fiala802dc4022014-06-23 19:30:49 +000091}
92
Kate Stoneb9c1b512016-09-06 20:57:50 +000093bool SBUnixSignals::SetShouldStop(int32_t signo, bool value) {
94 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
95 auto signals_sp = GetSP();
96
97 if (log) {
98 log->Printf("SBUnixSignals(%p)::SetShouldStop (signo=%d, value=%d)",
99 static_cast<void *>(signals_sp.get()), signo, value);
100 }
101
102 if (signals_sp)
103 return signals_sp->SetShouldStop(signo, value);
104
105 return false;
Todd Fiala802dc4022014-06-23 19:30:49 +0000106}
107
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108bool SBUnixSignals::GetShouldNotify(int32_t signo) const {
109 if (auto signals_sp = GetSP())
110 return signals_sp->GetShouldNotify(signo);
111
112 return false;
Todd Fiala802dc4022014-06-23 19:30:49 +0000113}
114
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115bool SBUnixSignals::SetShouldNotify(int32_t signo, bool value) {
116 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
117 auto signals_sp = GetSP();
Chaoren Lin98d0a4b2015-07-14 01:09:28 +0000118
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119 if (log) {
120 log->Printf("SBUnixSignals(%p)::SetShouldNotify (signo=%d, value=%d)",
121 static_cast<void *>(signals_sp.get()), signo, value);
122 }
123
124 if (signals_sp)
125 return signals_sp->SetShouldNotify(signo, value);
126
127 return false;
Todd Fiala802dc4022014-06-23 19:30:49 +0000128}
129
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130int32_t SBUnixSignals::GetNumSignals() const {
131 if (auto signals_sp = GetSP())
132 return signals_sp->GetNumSignals();
Chaoren Lin98d0a4b2015-07-14 01:09:28 +0000133
Kate Stoneb9c1b512016-09-06 20:57:50 +0000134 return -1;
Todd Fiala802dc4022014-06-23 19:30:49 +0000135}
136
Kate Stoneb9c1b512016-09-06 20:57:50 +0000137int32_t SBUnixSignals::GetSignalAtIndex(int32_t index) const {
138 if (auto signals_sp = GetSP())
139 return signals_sp->GetSignalAtIndex(index);
Chaoren Lin98d0a4b2015-07-14 01:09:28 +0000140
Kate Stoneb9c1b512016-09-06 20:57:50 +0000141 return LLDB_INVALID_SIGNAL_NUMBER;
Todd Fiala802dc4022014-06-23 19:30:49 +0000142}