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
17#include "lldb/lldb-private.h"
18#include "llvm/Support/JSON.h"
19
20namespace lldb_private {
21
23public:
24 static lldb::UnixSignalsSP Create(const ArchSpec &arch);
26
27 // Constructors and Destructors
29
30 virtual ~UnixSignals();
31
32 llvm::StringRef GetSignalAsStringRef(int32_t signo) const;
33
34 llvm::StringRef GetSignalNumberDescription(int32_t signo) const;
35
36 std::string
37 GetSignalDescription(int32_t signo,
38 std::optional<int32_t> code = std::nullopt,
39 std::optional<lldb::addr_t> addr = std::nullopt,
40 std::optional<lldb::addr_t> lower = std::nullopt,
41 std::optional<lldb::addr_t> upper = std::nullopt,
42 std::optional<uint32_t> pid = std::nullopt,
43 std::optional<uint32_t> uid = std::nullopt) const;
44
45 bool SignalIsValid(int32_t signo) const;
46
47 int32_t GetSignalNumberFromName(const char *name) const;
48
49 /// Gets the information for a particular signal
50 ///
51 /// GetSignalInfo takes a signal number and populates 3 out parameters
52 /// describing how lldb should react when a particular signal is received in
53 /// the inferior.
54 ///
55 /// \param[in] signo
56 /// The signal number to get information about.
57 /// \param[out] should_suppress
58 /// Should we suppress this signal?
59 /// \param[out] should_stop
60 /// Should we stop if this signal is received?
61 /// \param[out] should_notify
62 /// Should we notify the user if this signal is received?
63 ///
64 /// \return
65 /// Returns a boolean value. Returns true if the out parameters were
66 /// successfully populated, false otherwise.
67 bool GetSignalInfo(int32_t signo, bool &should_suppress, bool &should_stop,
68 bool &should_notify) const;
69
70 bool GetShouldSuppress(int32_t signo) const;
71
72 bool SetShouldSuppress(int32_t signo, bool value);
73
74 bool SetShouldSuppress(const char *signal_name, bool value);
75
76 bool GetShouldStop(int32_t signo) const;
77
78 bool SetShouldStop(int32_t signo, bool value);
79 bool SetShouldStop(const char *signal_name, bool value);
80
81 bool GetShouldNotify(int32_t signo) const;
82
83 bool SetShouldNotify(int32_t signo, bool value);
84
85 bool SetShouldNotify(const char *signal_name, bool value);
86
87 bool ResetSignal(int32_t signo, bool reset_stop = true,
88 bool reset_notify = true, bool reset_suppress = true);
89
90 // These provide an iterator through the signals available on this system.
91 // Call GetFirstSignalNumber to get the first entry, then iterate on
92 // GetNextSignalNumber till you get back LLDB_INVALID_SIGNAL_NUMBER.
93 int32_t GetFirstSignalNumber() const;
94
95 int32_t GetNextSignalNumber(int32_t current_signal) const;
96
97 int32_t GetNumSignals() const;
98
99 int32_t GetSignalAtIndex(int32_t index) const;
100
101 // We assume that the elements of this object are constant once it is
102 // constructed, since a process should never need to add or remove symbols as
103 // it runs. So don't call these functions anywhere but the constructor of
104 // your subclass of UnixSignals or in your Process Plugin's GetUnixSignals
105 // method before you return the UnixSignal object.
106
107 void AddSignal(int signo, llvm::StringRef name, bool default_suppress,
108 bool default_stop, bool default_notify,
109 llvm::StringRef description,
110 llvm::StringRef alias = llvm::StringRef());
111
113
114 // Instead of calling this directly, use a ADD_SIGCODE macro to get compile
115 // time checks when on the native platform.
116 void AddSignalCode(
117 int signo, int code, const llvm::StringLiteral description,
119
120 void RemoveSignal(int signo);
121
122 /// Track how many times signals are hit as stop reasons.
123 void IncrementSignalHitCount(int signo);
124
125 /// Get the hit count statistics for signals.
126 ///
127 /// Gettings statistics on the hit counts of signals can help explain why some
128 /// debug sessions are slow since each stop takes a few hundred ms and some
129 /// software use signals a lot and can cause slow debugging performance if
130 /// they are used too often. Even if a signal is not stopped at, it will auto
131 /// continue the process and a delay will happen.
132 llvm::json::Value GetHitCountStatistics() const;
133
134 // Returns a current version of the data stored in this class. Version gets
135 // incremented each time Set... method is called.
136 uint64_t GetVersion() const;
137
138 // Returns a vector of signals that meet criteria provided in arguments. Each
139 // should_[suppress|stop|notify] flag can be std::nullopt - no filtering by
140 // this flag true - only signals that have it set to true are returned false -
141 // only signals that have it set to true are returned
142 std::vector<int32_t> GetFilteredSignals(std::optional<bool> should_suppress,
143 std::optional<bool> should_stop,
144 std::optional<bool> should_notify);
145
146protected:
147 // Classes that inherit from UnixSignals can see and modify these
148
149 struct SignalCode {
150 const llvm::StringLiteral m_description;
152 };
153
154 // The StringRefs in Signal are either backed by string literals or reside in
155 // persistent storage (e.g. a StringSet).
156 struct Signal {
157 llvm::StringRef m_name;
158 llvm::StringRef m_alias;
159 llvm::StringRef m_description;
160 std::map<int32_t, SignalCode> m_codes;
161 uint32_t m_hit_count = 0;
162 bool m_suppress : 1, m_stop : 1, m_notify : 1;
164
165 Signal(llvm::StringRef name, bool default_suppress, bool default_stop,
166 bool default_notify, llvm::StringRef description,
167 llvm::StringRef alias);
168
169 ~Signal() = default;
170 void Reset(bool reset_stop, bool reset_notify, bool reset_suppress);
171 };
172
173 llvm::StringRef GetShortName(llvm::StringRef name) const;
174
175 virtual void Reset();
176
177 typedef std::map<int32_t, Signal> collection;
178
180
181 // This version gets incremented every time something is changing in this
182 // class, including when we call AddSignal from the constructor. So after the
183 // object is constructed m_version is going to be > 0 if it has at least one
184 // signal registered in it.
185 uint64_t m_version = 0;
186
187 // GDBRemote signals need to be copyable.
188 UnixSignals(const UnixSignals &rhs);
189
190 const UnixSignals &operator=(const UnixSignals &rhs) = delete;
191};
192
193} // Namespace lldb
194#endif // LLDB_TARGET_UNIXSIGNALS_H
An architecture specification class.
Definition ArchSpec.h:31
void AddSignalCode(int signo, int code, const llvm::StringLiteral description, SignalCodePrintOption print_option=SignalCodePrintOption::None)
llvm::StringRef GetShortName(llvm::StringRef name) const
int32_t GetSignalNumberFromName(const char *name) const
static lldb::UnixSignalsSP CreateForHost()
bool GetSignalInfo(int32_t signo, bool &should_suppress, bool &should_stop, bool &should_notify) const
Gets the information for a particular signal.
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 AddSignal(int signo, llvm::StringRef name, bool default_suppress, bool default_stop, bool default_notify, llvm::StringRef description, llvm::StringRef alias=llvm::StringRef())
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
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
int32_t GetNextSignalNumber(int32_t current_signal) const
bool SetShouldNotify(int32_t signo, bool value)
bool GetShouldSuppress(int32_t signo) const
llvm::StringRef GetSignalAsStringRef(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, std::optional< uint32_t > pid=std::nullopt, std::optional< uint32_t > uid=std::nullopt) const
bool GetShouldStop(int32_t signo) const
uint64_t GetVersion() const
llvm::StringRef GetSignalNumberDescription(int32_t signo) const
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::UnixSignals > UnixSignalsSP
const SignalCodePrintOption m_print_option
const llvm::StringLiteral m_description
std::map< int32_t, SignalCode > m_codes
Signal(llvm::StringRef name, bool default_suppress, bool default_stop, bool default_notify, llvm::StringRef description, llvm::StringRef alias)