LLDB mainline
UnixSignals.h
Go to the documentation of this file.
1//===-- UnixSignals.h -------------------------------------------*- C++ -*-===//
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#ifndef LLDB_TARGET_UNIXSIGNALS_H
10#define LLDB_TARGET_UNIXSIGNALS_H
11
12#include <map>
13#include <optional>
14#include <string>
15#include <vector>
16
18#include "lldb/lldb-private.h"
19#include "llvm/Support/JSON.h"
20
21namespace lldb_private {
22
24public:
25 static lldb::UnixSignalsSP CreateForHost();
26
27 // Constructors and Destructors
29
30 virtual ~UnixSignals();
31
32 const char *GetSignalAsCString(int32_t signo) const;
33
34 std::string
35 GetSignalDescription(int32_t signo,
36 std::optional<int32_t> code = std::nullopt,
37 std::optional<lldb::addr_t> addr = std::nullopt,
38 std::optional<lldb::addr_t> lower = std::nullopt,
39 std::optional<lldb::addr_t> upper = std::nullopt) const;
40
41 bool SignalIsValid(int32_t signo) const;
42
43 int32_t GetSignalNumberFromName(const char *name) const;
44
45 const char *GetSignalInfo(int32_t signo, bool &should_suppress,
46 bool &should_stop, bool &should_notify) const;
47
48 bool GetShouldSuppress(int32_t signo) const;
49
50 bool SetShouldSuppress(int32_t signo, bool value);
51
52 bool SetShouldSuppress(const char *signal_name, bool value);
53
54 bool GetShouldStop(int32_t signo) const;
55
56 bool SetShouldStop(int32_t signo, bool value);
57 bool SetShouldStop(const char *signal_name, bool value);
58
59 bool GetShouldNotify(int32_t signo) const;
60
61 bool SetShouldNotify(int32_t signo, bool value);
62
63 bool SetShouldNotify(const char *signal_name, bool value);
64
65 bool ResetSignal(int32_t signo, bool reset_stop = true,
66 bool reset_notify = true, bool reset_suppress = true);
67
68 // These provide an iterator through the signals available on this system.
69 // Call GetFirstSignalNumber to get the first entry, then iterate on
70 // GetNextSignalNumber till you get back LLDB_INVALID_SIGNAL_NUMBER.
71 int32_t GetFirstSignalNumber() const;
72
73 int32_t GetNextSignalNumber(int32_t current_signal) const;
74
75 int32_t GetNumSignals() const;
76
77 int32_t GetSignalAtIndex(int32_t index) const;
78
80
81 // We assume that the elements of this object are constant once it is
82 // constructed, since a process should never need to add or remove symbols as
83 // it runs. So don't call these functions anywhere but the constructor of
84 // your subclass of UnixSignals or in your Process Plugin's GetUnixSignals
85 // method before you return the UnixSignal object.
86
87 void AddSignal(int signo, const char *name, bool default_suppress,
88 bool default_stop, bool default_notify,
89 const char *description, const char *alias = nullptr);
90
92
93 void AddSignalCode(
94 int signo, int code, const char *description,
96
97 void RemoveSignal(int signo);
98
99 /// Track how many times signals are hit as stop reasons.
100 void IncrementSignalHitCount(int signo);
101
102 /// Get the hit count statistics for signals.
103 ///
104 /// Gettings statistics on the hit counts of signals can help explain why some
105 /// debug sessions are slow since each stop takes a few hundred ms and some
106 /// software use signals a lot and can cause slow debugging performance if
107 /// they are used too often. Even if a signal is not stopped at, it will auto
108 /// continue the process and a delay will happen.
109 llvm::json::Value GetHitCountStatistics() const;
110
111 // Returns a current version of the data stored in this class. Version gets
112 // incremented each time Set... method is called.
113 uint64_t GetVersion() const;
114
115 // Returns a vector of signals that meet criteria provided in arguments. Each
116 // should_[suppress|stop|notify] flag can be std::nullopt - no filtering by
117 // this flag true - only signals that have it set to true are returned false -
118 // only signals that have it set to true are returned
119 std::vector<int32_t> GetFilteredSignals(std::optional<bool> should_suppress,
120 std::optional<bool> should_stop,
121 std::optional<bool> should_notify);
122
123protected:
124 // Classes that inherit from UnixSignals can see and modify these
125
126 struct SignalCode {
129 };
130
131 struct Signal {
134 std::string m_description;
135 std::map<int32_t, SignalCode> m_codes;
137 bool m_suppress : 1, m_stop : 1, m_notify : 1;
139
140 Signal(const char *name, bool default_suppress, bool default_stop,
141 bool default_notify, const char *description, const char *alias);
142
143 ~Signal() = default;
144 void Reset(bool reset_stop, bool reset_notify, bool reset_suppress);
145 };
146
147 virtual void Reset();
148
149 typedef std::map<int32_t, Signal> collection;
150
152
153 // This version gets incremented every time something is changing in this
154 // class, including when we call AddSignal from the constructor. So after the
155 // object is constructed m_version is going to be > 0 if it has at least one
156 // signal registered in it.
157 uint64_t m_version = 0;
158
159 // GDBRemote signals need to be copyable.
160 UnixSignals(const UnixSignals &rhs);
161
162 const UnixSignals &operator=(const UnixSignals &rhs) = delete;
163};
164
165} // Namespace lldb
166#endif // LLDB_TARGET_UNIXSIGNALS_H
A uniqued constant string class.
Definition: ConstString.h:39
int32_t GetSignalNumberFromName(const char *name) const
static lldb::UnixSignalsSP CreateForHost()
Definition: UnixSignals.cpp:31
void AddSignalCode(int signo, int code, const char *description, SignalCodePrintOption print_option=SignalCodePrintOption::None)
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
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
const UnixSignals & operator=(const UnixSignals &rhs)=delete
llvm::json::Value GetHitCountStatistics() const
Get the hit count statistics for signals.
std::map< int32_t, Signal > collection
Definition: UnixSignals.h:149
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
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
SignalCodePrintOption m_print_option
Definition: UnixSignals.h:128
std::map< int32_t, SignalCode > m_codes
Definition: UnixSignals.h:135