Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 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 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 9 | #ifndef LLDB_TARGET_UNIXSIGNALS_H |
| 10 | #define LLDB_TARGET_UNIXSIGNALS_H |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 11 | |
| 12 | #include <map> |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
| 16 | #include "lldb/Utility/ConstString.h" |
| 17 | #include "lldb/lldb-private.h" |
| 18 | #include "llvm/ADT/Optional.h" |
| 19 | |
| 20 | namespace lldb_private { |
| 21 | |
| 22 | class UnixSignals { |
| 23 | public: |
| 24 | static lldb::UnixSignalsSP Create(const ArchSpec &arch); |
| 25 | static lldb::UnixSignalsSP CreateForHost(); |
| 26 | |
| 27 | // Constructors and Destructors |
| 28 | UnixSignals(); |
| 29 | |
| 30 | virtual ~UnixSignals(); |
| 31 | |
| 32 | const char *GetSignalAsCString(int32_t signo) const; |
| 33 | |
| 34 | bool SignalIsValid(int32_t signo) const; |
| 35 | |
| 36 | int32_t GetSignalNumberFromName(const char *name) const; |
| 37 | |
| 38 | const char *GetSignalInfo(int32_t signo, bool &should_suppress, |
| 39 | bool &should_stop, bool &should_notify) const; |
| 40 | |
| 41 | bool GetShouldSuppress(int32_t signo) const; |
| 42 | |
| 43 | bool SetShouldSuppress(int32_t signo, bool value); |
| 44 | |
| 45 | bool SetShouldSuppress(const char *signal_name, bool value); |
| 46 | |
| 47 | bool GetShouldStop(int32_t signo) const; |
| 48 | |
| 49 | bool SetShouldStop(int32_t signo, bool value); |
| 50 | bool SetShouldStop(const char *signal_name, bool value); |
| 51 | |
| 52 | bool GetShouldNotify(int32_t signo) const; |
| 53 | |
| 54 | bool SetShouldNotify(int32_t signo, bool value); |
| 55 | |
| 56 | bool SetShouldNotify(const char *signal_name, bool value); |
| 57 | |
| 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; |
| 62 | |
| 63 | int32_t GetNextSignalNumber(int32_t current_signal) const; |
| 64 | |
| 65 | int32_t GetNumSignals() const; |
| 66 | |
| 67 | int32_t GetSignalAtIndex(int32_t index) const; |
| 68 | |
| 69 | ConstString GetShortName(ConstString name) const; |
| 70 | |
| 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. |
| 76 | |
| 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); |
| 80 | |
| 81 | void RemoveSignal(int signo); |
| 82 | |
| 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; |
| 86 | |
| 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); |
| 94 | |
| 95 | protected: |
| 96 | // Classes that inherit from UnixSignals can see and modify these |
| 97 | |
| 98 | struct Signal { |
| 99 | ConstString m_name; |
| 100 | ConstString m_alias; |
| 101 | std::string m_description; |
| 102 | bool m_suppress : 1, m_stop : 1, m_notify : 1; |
| 103 | |
| 104 | Signal(const char *name, bool default_suppress, bool default_stop, |
| 105 | bool default_notify, const char *description, const char *alias); |
| 106 | |
| 107 | ~Signal() {} |
| 108 | }; |
| 109 | |
| 110 | virtual void Reset(); |
| 111 | |
| 112 | typedef std::map<int32_t, Signal> collection; |
| 113 | |
| 114 | collection m_signals; |
| 115 | |
| 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; |
| 121 | |
| 122 | // GDBRemote signals need to be copyable. |
| 123 | UnixSignals(const UnixSignals &rhs); |
| 124 | |
| 125 | const UnixSignals &operator=(const UnixSignals &rhs) = delete; |
| 126 | }; |
| 127 | |
| 128 | } // Namespace lldb |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 129 | #endif // LLDB_TARGET_UNIXSIGNALS_H |