]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBUnixSignals.cpp
MFV r302003,r302037,r302038,r302056:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / API / SBUnixSignals.cpp
1 //===-- SBUnixSignals.cpp -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/lldb-defines.h"
11 #include "lldb/Target/Process.h"
12 #include "lldb/Target/Platform.h"
13 #include "lldb/Target/UnixSignals.h"
14 #include "lldb/Core/Log.h"
15
16 #include "lldb/API/SBUnixSignals.h"
17
18 using namespace lldb;
19 using namespace lldb_private;
20
21 SBUnixSignals::SBUnixSignals ()
22 {}
23
24 SBUnixSignals::SBUnixSignals (const SBUnixSignals &rhs) :
25     m_opaque_wp(rhs.m_opaque_wp)
26 {
27 }
28
29 SBUnixSignals::SBUnixSignals(ProcessSP &process_sp) :
30     m_opaque_wp(process_sp ? process_sp->GetUnixSignals() : nullptr)
31 {
32 }
33
34 SBUnixSignals::SBUnixSignals(PlatformSP &platform_sp) :
35     m_opaque_wp(platform_sp ? platform_sp->GetUnixSignals() : nullptr)
36 {
37 }
38
39 const SBUnixSignals&
40 SBUnixSignals::operator = (const SBUnixSignals& rhs)
41 {
42     if (this != &rhs)
43         m_opaque_wp = rhs.m_opaque_wp;
44     return *this;
45 }
46
47 SBUnixSignals::~SBUnixSignals()
48 {
49 }
50
51 UnixSignalsSP
52 SBUnixSignals::GetSP() const
53 {
54     return m_opaque_wp.lock();
55 }
56
57 void
58 SBUnixSignals::SetSP(const UnixSignalsSP &signals_sp)
59 {
60     m_opaque_wp = signals_sp;
61 }
62
63 void
64 SBUnixSignals::Clear ()
65 {
66     m_opaque_wp.reset();
67 }
68
69 bool
70 SBUnixSignals::IsValid() const
71 {
72     return static_cast<bool>(GetSP());
73 }
74
75 const char *
76 SBUnixSignals::GetSignalAsCString (int32_t signo) const
77 {
78     if (auto signals_sp = GetSP())
79         return signals_sp->GetSignalAsCString(signo);
80
81     return nullptr;
82 }
83
84 int32_t
85 SBUnixSignals::GetSignalNumberFromName (const char *name) const
86 {
87     if (auto signals_sp = GetSP())
88         return signals_sp->GetSignalNumberFromName(name);
89
90     return LLDB_INVALID_SIGNAL_NUMBER;
91 }
92
93 bool
94 SBUnixSignals::GetShouldSuppress (int32_t signo) const
95 {
96     if (auto signals_sp = GetSP())
97         return signals_sp->GetShouldSuppress(signo);
98
99     return false;
100 }
101
102 bool
103 SBUnixSignals::SetShouldSuppress (int32_t signo, bool value)
104 {
105     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
106     auto signals_sp = GetSP();
107
108     if (log)
109     {
110         log->Printf ("SBUnixSignals(%p)::SetShouldSuppress (signo=%d, value=%d)",
111                      static_cast<void*>(signals_sp.get()),
112                      signo,
113                      value);
114     }
115
116     if (signals_sp)
117         return signals_sp->SetShouldSuppress(signo, value);
118
119     return false;
120 }
121
122 bool
123 SBUnixSignals::GetShouldStop (int32_t signo) const
124 {
125     if (auto signals_sp = GetSP())
126         return signals_sp->GetShouldStop(signo);
127
128     return false;
129 }
130
131 bool
132 SBUnixSignals::SetShouldStop (int32_t signo, bool value)
133 {
134     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
135     auto signals_sp = GetSP();
136
137     if (log)
138     {
139         log->Printf ("SBUnixSignals(%p)::SetShouldStop (signo=%d, value=%d)",
140                      static_cast<void*>(signals_sp.get()),
141                      signo,
142                      value);
143     }
144
145     if (signals_sp)
146         return signals_sp->SetShouldStop(signo, value);
147
148     return false;
149 }
150
151 bool
152 SBUnixSignals::GetShouldNotify (int32_t signo) const
153 {
154     if (auto signals_sp = GetSP())
155         return signals_sp->GetShouldNotify(signo);
156
157     return false;
158 }
159
160 bool
161 SBUnixSignals::SetShouldNotify (int32_t signo, bool value)
162 {
163     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
164     auto signals_sp = GetSP();
165
166     if (log)
167     {
168         log->Printf ("SBUnixSignals(%p)::SetShouldNotify (signo=%d, value=%d)",
169                      static_cast<void*>(signals_sp.get()),
170                      signo,
171                      value);
172     }
173
174     if (signals_sp)
175         return signals_sp->SetShouldNotify(signo, value);
176
177     return false;
178 }
179
180 int32_t
181 SBUnixSignals::GetNumSignals () const
182 {
183     if (auto signals_sp = GetSP())
184         return signals_sp->GetNumSignals();
185
186     return -1;
187 }
188
189 int32_t
190 SBUnixSignals::GetSignalAtIndex (int32_t index) const
191 {
192     if (auto signals_sp = GetSP())
193         return signals_sp->GetSignalAtIndex(index);
194
195     return LLDB_INVALID_SIGNAL_NUMBER;
196 }