LLDB  mainline
SBUnixSignals.cpp
Go to the documentation of this file.
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 "SBReproducerPrivate.h"
10 #include "lldb/Target/Platform.h"
11 #include "lldb/Target/Process.h"
13 #include "lldb/lldb-defines.h"
14 
15 #include "lldb/API/SBUnixSignals.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
22 }
23 
25  : m_opaque_wp(rhs.m_opaque_wp) {
27 }
28 
29 SBUnixSignals::SBUnixSignals(ProcessSP &process_sp)
30  : m_opaque_wp(process_sp ? process_sp->GetUnixSignals() : nullptr) {}
31 
32 SBUnixSignals::SBUnixSignals(PlatformSP &platform_sp)
33  : m_opaque_wp(platform_sp ? platform_sp->GetUnixSignals() : nullptr) {}
34 
37  SBUnixSignals, operator=,(const lldb::SBUnixSignals &),
38  rhs);
39 
40  if (this != &rhs)
42  return LLDB_RECORD_RESULT(*this);
43 }
44 
46 
47 UnixSignalsSP SBUnixSignals::GetSP() const { return m_opaque_wp.lock(); }
48 
49 void SBUnixSignals::SetSP(const UnixSignalsSP &signals_sp) {
50  m_opaque_wp = signals_sp;
51 }
52 
55 
56  m_opaque_wp.reset();
57 }
58 
59 bool SBUnixSignals::IsValid() const {
61  return this->operator bool();
62 }
63 SBUnixSignals::operator bool() const {
64  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBUnixSignals, operator bool);
65 
66  return static_cast<bool>(GetSP());
67 }
68 
69 const char *SBUnixSignals::GetSignalAsCString(int32_t signo) const {
71  (int32_t), signo);
72 
73  if (auto signals_sp = GetSP())
74  return signals_sp->GetSignalAsCString(signo);
75 
76  return nullptr;
77 }
78 
79 int32_t SBUnixSignals::GetSignalNumberFromName(const char *name) const {
81  (const char *), name);
82 
83  if (auto signals_sp = GetSP())
84  return signals_sp->GetSignalNumberFromName(name);
85 
87 }
88 
89 bool SBUnixSignals::GetShouldSuppress(int32_t signo) const {
91  signo);
92 
93  if (auto signals_sp = GetSP())
94  return signals_sp->GetShouldSuppress(signo);
95 
96  return false;
97 }
98 
99 bool SBUnixSignals::SetShouldSuppress(int32_t signo, bool value) {
100  LLDB_RECORD_METHOD(bool, SBUnixSignals, SetShouldSuppress, (int32_t, bool),
101  signo, value);
102 
103  auto signals_sp = GetSP();
104 
105  if (signals_sp)
106  return signals_sp->SetShouldSuppress(signo, value);
107 
108  return false;
109 }
110 
111 bool SBUnixSignals::GetShouldStop(int32_t signo) const {
113  signo);
114 
115  if (auto signals_sp = GetSP())
116  return signals_sp->GetShouldStop(signo);
117 
118  return false;
119 }
120 
121 bool SBUnixSignals::SetShouldStop(int32_t signo, bool value) {
122  LLDB_RECORD_METHOD(bool, SBUnixSignals, SetShouldStop, (int32_t, bool), signo,
123  value);
124 
125  auto signals_sp = GetSP();
126 
127  if (signals_sp)
128  return signals_sp->SetShouldStop(signo, value);
129 
130  return false;
131 }
132 
133 bool SBUnixSignals::GetShouldNotify(int32_t signo) const {
135  signo);
136 
137  if (auto signals_sp = GetSP())
138  return signals_sp->GetShouldNotify(signo);
139 
140  return false;
141 }
142 
143 bool SBUnixSignals::SetShouldNotify(int32_t signo, bool value) {
144  LLDB_RECORD_METHOD(bool, SBUnixSignals, SetShouldNotify, (int32_t, bool),
145  signo, value);
146 
147  auto signals_sp = GetSP();
148 
149  if (signals_sp)
150  return signals_sp->SetShouldNotify(signo, value);
151 
152  return false;
153 }
154 
157 
158  if (auto signals_sp = GetSP())
159  return signals_sp->GetNumSignals();
160 
161  return -1;
162 }
163 
164 int32_t SBUnixSignals::GetSignalAtIndex(int32_t index) const {
166  index);
167 
168  if (auto signals_sp = GetSP())
169  return signals_sp->GetSignalAtIndex(index);
170 
172 }
173 
174 namespace lldb_private {
175 namespace repro {
176 
177 template <>
182  const lldb::SBUnixSignals &,
183  SBUnixSignals, operator=,(const lldb::SBUnixSignals &));
184  LLDB_REGISTER_METHOD(void, SBUnixSignals, Clear, ());
185  LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals, IsValid, ());
186  LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals, operator bool, ());
187  LLDB_REGISTER_METHOD_CONST(const char *, SBUnixSignals, GetSignalAsCString,
188  (int32_t));
189  LLDB_REGISTER_METHOD_CONST(int32_t, SBUnixSignals, GetSignalNumberFromName,
190  (const char *));
191  LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals, GetShouldSuppress,
192  (int32_t));
193  LLDB_REGISTER_METHOD(bool, SBUnixSignals, SetShouldSuppress,
194  (int32_t, bool));
195  LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals, GetShouldStop, (int32_t));
196  LLDB_REGISTER_METHOD(bool, SBUnixSignals, SetShouldStop, (int32_t, bool));
197  LLDB_REGISTER_METHOD_CONST(bool, SBUnixSignals, GetShouldNotify, (int32_t));
198  LLDB_REGISTER_METHOD(bool, SBUnixSignals, SetShouldNotify, (int32_t, bool));
199  LLDB_REGISTER_METHOD_CONST(int32_t, SBUnixSignals, GetNumSignals, ());
200  LLDB_REGISTER_METHOD_CONST(int32_t, SBUnixSignals, GetSignalAtIndex,
201  (int32_t));
202 }
203 
204 }
205 }
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
lldb-defines.h
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
lldb::SBUnixSignals::GetShouldNotify
bool GetShouldNotify(int32_t signo) const
Definition: SBUnixSignals.cpp:133
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
SBReproducerPrivate.h
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
Process.h
Platform.h
LLDB_INVALID_SIGNAL_NUMBER
#define LLDB_INVALID_SIGNAL_NUMBER
Definition: lldb-defines.h:96
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
UnixSignals.h
lldb::SBUnixSignals::SetShouldNotify
bool SetShouldNotify(int32_t signo, bool value)
Definition: SBUnixSignals.cpp:143
lldb::SBUnixSignals::GetSignalAsCString
const char * GetSignalAsCString(int32_t signo) const
Definition: SBUnixSignals.cpp:69
lldb::SBUnixSignals::SetSP
void SetSP(const lldb::UnixSignalsSP &signals_sp)
Definition: SBUnixSignals.cpp:49
lldb::SBUnixSignals::GetSignalAtIndex
int32_t GetSignalAtIndex(int32_t index) const
Definition: SBUnixSignals.cpp:164
lldb::SBUnixSignals::IsValid
bool IsValid() const
Definition: SBUnixSignals.cpp:59
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb_private::repro::RegisterMethods< SBUnixSignals >
void RegisterMethods< SBUnixSignals >(Registry &R)
Definition: SBUnixSignals.cpp:178
lldb::SBUnixSignals::~SBUnixSignals
~SBUnixSignals()
lldb::SBUnixSignals::GetSignalNumberFromName
int32_t GetSignalNumberFromName(const char *name) const
Definition: SBUnixSignals.cpp:79
lldb::SBUnixSignals::GetShouldSuppress
bool GetShouldSuppress(int32_t signo) const
Definition: SBUnixSignals.cpp:89
lldb::SBUnixSignals::SetShouldSuppress
bool SetShouldSuppress(int32_t signo, bool value)
Definition: SBUnixSignals.cpp:99
lldb::SBUnixSignals::GetNumSignals
int32_t GetNumSignals() const
Definition: SBUnixSignals.cpp:155
lldb::SBUnixSignals::m_opaque_wp
lldb::UnixSignalsWP m_opaque_wp
Definition: SBUnixSignals.h:66
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBUnixSignals::SBUnixSignals
SBUnixSignals()
Definition: SBUnixSignals.cpp:20
SBUnixSignals.h
lldb::SBUnixSignals::SetShouldStop
bool SetShouldStop(int32_t signo, bool value)
Definition: SBUnixSignals.cpp:121
LLDB_RECORD_METHOD_CONST
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:161
lldb
Definition: SBAddress.h:15
lldb::SBUnixSignals::operator=
const SBUnixSignals & operator=(const lldb::SBUnixSignals &rhs)
Definition: SBUnixSignals.cpp:35
lldb::SBUnixSignals::GetSP
lldb::UnixSignalsSP GetSP() const
Definition: SBUnixSignals.cpp:47
lldb::SBUnixSignals
Definition: SBUnixSignals.h:17
lldb::SBUnixSignals::Clear
void Clear()
Definition: SBUnixSignals.cpp:53
lldb::SBUnixSignals::GetShouldStop
bool GetShouldStop(int32_t signo) const
Definition: SBUnixSignals.cpp:111
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93