1 //===-- UnixSignals.h -------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef lldb_UnixSignals_h_
10 #define lldb_UnixSignals_h_
16 #include "lldb/Utility/ConstString.h"
17 #include "lldb/lldb-private.h"
18 #include "llvm/ADT/Optional.h"
20 namespace lldb_private {
24 static lldb::UnixSignalsSP Create(const ArchSpec &arch);
25 static lldb::UnixSignalsSP CreateForHost();
27 // Constructors and Destructors
30 virtual ~UnixSignals();
32 const char *GetSignalAsCString(int32_t signo) const;
34 bool SignalIsValid(int32_t signo) const;
36 int32_t GetSignalNumberFromName(const char *name) const;
38 const char *GetSignalInfo(int32_t signo, bool &should_suppress,
39 bool &should_stop, bool &should_notify) const;
41 bool GetShouldSuppress(int32_t signo) const;
43 bool SetShouldSuppress(int32_t signo, bool value);
45 bool SetShouldSuppress(const char *signal_name, bool value);
47 bool GetShouldStop(int32_t signo) const;
49 bool SetShouldStop(int32_t signo, bool value);
50 bool SetShouldStop(const char *signal_name, bool value);
52 bool GetShouldNotify(int32_t signo) const;
54 bool SetShouldNotify(int32_t signo, bool value);
56 bool SetShouldNotify(const char *signal_name, bool value);
58 // These provide an iterator through the signals available on this system.
59 // Call GetFirstSignalNumber to get the first entry, then iterate on
60 // GetNextSignalNumber till you get back LLDB_INVALID_SIGNAL_NUMBER.
61 int32_t GetFirstSignalNumber() const;
63 int32_t GetNextSignalNumber(int32_t current_signal) const;
65 int32_t GetNumSignals() const;
67 int32_t GetSignalAtIndex(int32_t index) const;
69 ConstString GetShortName(ConstString name) const;
71 // We assume that the elements of this object are constant once it is
72 // constructed, since a process should never need to add or remove symbols as
73 // it runs. So don't call these functions anywhere but the constructor of
74 // your subclass of UnixSignals or in your Process Plugin's GetUnixSignals
75 // method before you return the UnixSignal object.
77 void AddSignal(int signo, const char *name, bool default_suppress,
78 bool default_stop, bool default_notify,
79 const char *description, const char *alias = nullptr);
81 void RemoveSignal(int signo);
83 // Returns a current version of the data stored in this class. Version gets
84 // incremented each time Set... method is called.
85 uint64_t GetVersion() const;
87 // Returns a vector of signals that meet criteria provided in arguments. Each
88 // should_[suppress|stop|notify] flag can be None - no filtering by this
89 // flag true - only signals that have it set to true are returned false -
90 // only signals that have it set to true are returned
91 std::vector<int32_t> GetFilteredSignals(llvm::Optional<bool> should_suppress,
92 llvm::Optional<bool> should_stop,
93 llvm::Optional<bool> should_notify);
96 // Classes that inherit from UnixSignals can see and modify these
101 std::string m_description;
102 bool m_suppress : 1, m_stop : 1, m_notify : 1;
104 Signal(const char *name, bool default_suppress, bool default_stop,
105 bool default_notify, const char *description, const char *alias);
110 virtual void Reset();
112 typedef std::map<int32_t, Signal> collection;
114 collection m_signals;
116 // This version gets incremented every time something is changing in this
117 // class, including when we call AddSignal from the constructor. So after the
118 // object is constructed m_version is going to be > 0 if it has at least one
119 // signal registered in it.
120 uint64_t m_version = 0;
122 // GDBRemote signals need to be copyable.
123 UnixSignals(const UnixSignals &rhs);
125 const UnixSignals &operator=(const UnixSignals &rhs) = delete;
129 #endif // lldb_UnixSignals_h_