22 bool default_stop,
bool default_notify,
23 const char *description,
const char *alias)
24 : m_name(name), m_alias(alias), m_description(),
25 m_suppress(default_suppress), m_stop(default_stop),
26 m_notify(default_notify),
27 m_default_suppress(default_suppress), m_default_stop(default_stop),
28 m_default_notify(default_notify) {
35 switch (triple.getOS()) {
36 case llvm::Triple::Linux:
37 return std::make_shared<LinuxSignals>();
38 case llvm::Triple::FreeBSD:
39 case llvm::Triple::OpenBSD:
40 return std::make_shared<FreeBSDSignals>();
41 case llvm::Triple::NetBSD:
42 return std::make_shared<NetBSDSignals>();
44 return std::make_shared<UnixSignals>();
49 static lldb::UnixSignalsSP s_unix_signals_sp =
50 Create(HostInfo::GetArchitecture());
51 return s_unix_signals_sp;
73 AddSignal(1,
"SIGHUP",
false,
true,
true,
"hangup");
74 AddSignal(2,
"SIGINT",
true,
true,
true,
"interrupt");
75 AddSignal(3,
"SIGQUIT",
false,
true,
true,
"quit");
76 AddSignal(4,
"SIGILL",
false,
true,
true,
"illegal instruction");
77 AddSignal(5,
"SIGTRAP",
true,
true,
true,
"trace trap (not reset when caught)");
78 AddSignal(6,
"SIGABRT",
false,
true,
true,
"abort()");
79 AddSignal(7,
"SIGEMT",
false,
true,
true,
"pollable event");
80 AddSignal(8,
"SIGFPE",
false,
true,
true,
"floating point exception");
81 AddSignal(9,
"SIGKILL",
false,
true,
true,
"kill");
82 AddSignal(10,
"SIGBUS",
false,
true,
true,
"bus error");
83 AddSignal(11,
"SIGSEGV",
false,
true,
true,
"segmentation violation");
84 AddSignal(12,
"SIGSYS",
false,
true,
true,
"bad argument to system call");
85 AddSignal(13,
"SIGPIPE",
false,
false,
false,
"write on a pipe with no one to read it");
86 AddSignal(14,
"SIGALRM",
false,
false,
false,
"alarm clock");
87 AddSignal(15,
"SIGTERM",
false,
true,
true,
"software termination signal from kill");
88 AddSignal(16,
"SIGURG",
false,
false,
false,
"urgent condition on IO channel");
89 AddSignal(17,
"SIGSTOP",
true,
true,
true,
"sendable stop signal not from tty");
90 AddSignal(18,
"SIGTSTP",
false,
true,
true,
"stop signal from tty");
91 AddSignal(19,
"SIGCONT",
false,
false,
true,
"continue a stopped process");
92 AddSignal(20,
"SIGCHLD",
false,
false,
false,
"to parent on child stop or exit");
93 AddSignal(21,
"SIGTTIN",
false,
true,
true,
"to readers process group upon background tty read");
94 AddSignal(22,
"SIGTTOU",
false,
true,
true,
"to readers process group upon background tty write");
95 AddSignal(23,
"SIGIO",
false,
false,
false,
"input/output possible signal");
96 AddSignal(24,
"SIGXCPU",
false,
true,
true,
"exceeded CPU time limit");
97 AddSignal(25,
"SIGXFSZ",
false,
true,
true,
"exceeded file size limit");
98 AddSignal(26,
"SIGVTALRM",
false,
false,
false,
"virtual time alarm");
99 AddSignal(27,
"SIGPROF",
false,
false,
false,
"profiling time alarm");
100 AddSignal(28,
"SIGWINCH",
false,
false,
false,
"window size changes");
101 AddSignal(29,
"SIGINFO",
false,
true,
true,
"information request");
102 AddSignal(30,
"SIGUSR1",
false,
true,
true,
"user defined signal 1");
103 AddSignal(31,
"SIGUSR2",
false,
true,
true,
"user defined signal 2");
108 bool default_stop,
bool default_notify,
109 const char *description,
const char *alias) {
110 Signal new_signal(name, default_suppress, default_stop, default_notify,
112 m_signals.insert(std::make_pair(signo, new_signal));
117 const llvm::StringLiteral description,
119 collection::iterator signal =
m_signals.find(signo);
121 "Tried to add code to signal that does not exist.");
122 signal->second.m_codes.insert(
123 std::pair{code,
SignalCode{description, print_option}});
128 collection::iterator pos =
m_signals.find(signo);
135 collection::const_iterator pos =
m_signals.find(signo);
139 return pos->second.m_name.GetCString();
144 std::optional<lldb::addr_t> addr,
145 std::optional<lldb::addr_t> lower,
146 std::optional<lldb::addr_t> upper)
const {
149 collection::const_iterator pos =
m_signals.find(signo);
151 str = pos->second.m_name.GetCString();
154 std::map<int32_t, SignalCode>::const_iterator cpos =
155 pos->second.m_codes.find(*code);
156 if (cpos != pos->second.m_codes.end()) {
162 std::stringstream strm;
168 strm <<
" (fault address: 0x" << std::hex << *addr <<
")";
171 if (lower && upper && addr) {
172 if ((
unsigned long)(*addr) < *lower)
173 strm <<
"lower bound violation ";
175 strm <<
"upper bound violation ";
177 strm <<
"(fault address: 0x" << std::hex << *addr;
178 strm <<
", lower bound: 0x" << std::hex << *lower;
179 strm <<
", upper bound: 0x" << std::hex << *upper;
207 collection::const_iterator pos, end =
m_signals.end();
208 for (pos =
m_signals.begin(); pos != end; pos++) {
209 if ((const_name == pos->second.m_name) ||
210 (const_name == pos->second.m_alias) ||
217 if (llvm::to_integer(name, signo))
230 collection::const_iterator pos =
m_signals.find(current_signal);
231 collection::const_iterator end =
m_signals.end();
245 bool &should_notify)
const {
246 collection::const_iterator pos =
m_signals.find(signo);
250 const Signal &signal = pos->second;
252 should_stop = signal.
m_stop;
259 collection::const_iterator pos =
m_signals.find(signo);
261 return pos->second.m_suppress;
266 collection::iterator pos =
m_signals.find(signo);
268 pos->second.m_suppress = value;
283 collection::const_iterator pos =
m_signals.find(signo);
285 return pos->second.m_stop;
290 collection::iterator pos =
m_signals.find(signo);
292 pos->second.m_stop = value;
307 collection::const_iterator pos =
m_signals.find(signo);
309 return pos->second.m_notify;
314 collection::iterator pos =
m_signals.find(signo);
316 pos->second.m_notify = value;
333 if (index < 0 ||
m_signals.size() <=
static_cast<size_t>(index))
336 std::advance(it, index);
344 std::optional<bool> should_stop,
345 std::optional<bool> should_notify) {
346 std::vector<int32_t> result;
351 bool signal_suppress =
false;
352 bool signal_stop =
false;
353 bool signal_notify =
false;
354 GetSignalInfo(signo, signal_suppress, signal_stop, signal_notify);
358 if (should_suppress && signal_suppress != *should_suppress)
361 if (should_stop && signal_stop != *should_stop)
364 if (should_notify && signal_notify != *should_notify)
367 result.push_back(signo);
374 collection::iterator pos =
m_signals.find(signo);
376 pos->second.m_hit_count += 1;
380 json::Array json_signals;
382 if (pair.second.m_hit_count > 0)
383 json_signals.emplace_back(json::Object{
384 { pair.second.m_name.GetCString(), pair.second.m_hit_count }
387 return std::move(json_signals);
391 bool reset_suppress) {
401 bool reset_notify,
bool reset_suppress) {
405 (*elem).second.Reset(reset_stop, reset_notify, reset_suppress);
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void AddSignalCode(int signo, int code, const llvm::StringLiteral description, SignalCodePrintOption print_option=SignalCodePrintOption::None)
int32_t GetSignalNumberFromName(const char *name) const
static lldb::UnixSignalsSP CreateForHost()
const char * GetSignalInfo(int32_t signo, bool &should_suppress, bool &should_stop, bool &should_notify) const
ConstString GetShortName(ConstString name) const
int32_t GetSignalAtIndex(int32_t index) const
bool GetShouldNotify(int32_t signo) const
std::vector< int32_t > GetFilteredSignals(std::optional< bool > should_suppress, std::optional< bool > should_stop, std::optional< bool > should_notify)
void IncrementSignalHitCount(int signo)
Track how many times signals are hit as stop reasons.
bool SetShouldStop(int32_t signo, bool value)
void RemoveSignal(int signo)
bool SetShouldSuppress(int32_t signo, bool value)
int32_t GetFirstSignalNumber() const
static lldb::UnixSignalsSP Create(const ArchSpec &arch)
int32_t GetNumSignals() const
bool ResetSignal(int32_t signo, bool reset_stop=true, bool reset_notify=true, bool reset_suppress=true)
bool SignalIsValid(int32_t signo) const
llvm::json::Value GetHitCountStatistics() const
Get the hit count statistics for signals.
void AddSignal(int signo, const char *name, bool default_suppress, bool default_stop, bool default_notify, const char *description, const char *alias=nullptr)
int32_t GetNextSignalNumber(int32_t current_signal) const
bool SetShouldNotify(int32_t signo, bool value)
const char * GetSignalAsCString(int32_t signo) const
bool GetShouldSuppress(int32_t signo) const
bool GetShouldStop(int32_t signo) const
std::string GetSignalDescription(int32_t signo, std::optional< int32_t > code=std::nullopt, std::optional< lldb::addr_t > addr=std::nullopt, std::optional< lldb::addr_t > lower=std::nullopt, std::optional< lldb::addr_t > upper=std::nullopt) const
uint64_t GetVersion() const
#define LLDB_INVALID_SIGNAL_NUMBER
A class that represents a running process on the host machine.
const SignalCodePrintOption m_print_option
const llvm::StringLiteral m_description
Signal(const char *name, bool default_suppress, bool default_stop, bool default_notify, const char *description, const char *alias)
std::string m_description
void Reset(bool reset_stop, bool reset_notify, bool reset_suppress)