1 //===-- UnixSignals.h -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef lldb_UnixSignals_h_
11 #define lldb_UnixSignals_h_
12 
13 // C Includes
14 // C++ Includes
15 #include <string>
16 #include <map>
17 
18 // Other libraries and framework includes
19 // Project includes
20 #include "lldb/lldb-private.h"
21 #include "lldb/Core/ConstString.h"
22 
23 namespace lldb_private
24 {
25 
26 class UnixSignals
27 {
28 public:
29     //------------------------------------------------------------------
30     // Constructors and Destructors
31     //------------------------------------------------------------------
32     UnixSignals();
33 
34     virtual
35     ~UnixSignals();
36 
37     const char *
38     GetSignalAsCString (int32_t signo) const;
39 
40     bool
41     SignalIsValid (int32_t signo) const;
42 
43     int32_t
44     GetSignalNumberFromName (const char *name) const;
45 
46     const char *
47     GetSignalInfo (int32_t signo,
48                    bool &should_suppress,
49                    bool &should_stop,
50                    bool &should_notify) const;
51 
52     bool
53     GetShouldSuppress (int32_t signo) const;
54 
55     bool
56     SetShouldSuppress (int32_t signo,
57                        bool value);
58 
59     bool
60     SetShouldSuppress (const char *signal_name,
61                        bool value);
62 
63     bool
64     GetShouldStop (int32_t signo) const;
65 
66     bool
67     SetShouldStop (int32_t signo,
68                    bool value);
69     bool
70     SetShouldStop (const char *signal_name,
71                    bool value);
72 
73     bool
74     GetShouldNotify (int32_t signo) const;
75 
76     bool
77     SetShouldNotify (int32_t signo, bool value);
78 
79     bool
80     SetShouldNotify (const char *signal_name,
81                      bool value);
82 
83     // These provide an iterator through the signals available on this system.
84     // Call GetFirstSignalNumber to get the first entry, then iterate on GetNextSignalNumber
85     // till you get back LLDB_INVALID_SIGNAL_NUMBER.
86     int32_t
87     GetFirstSignalNumber () const;
88 
89     int32_t
90     GetNextSignalNumber (int32_t current_signal) const;
91 
92     // We assume that the elements of this object are constant once it is constructed,
93     // since a process should never need to add or remove symbols as it runs.  So don't
94     // call these functions anywhere but the constructor of your subclass of UnixSignals or in
95     // your Process Plugin's GetUnixSignals method before you return the UnixSignal object.
96 
97     void
98     AddSignal (int signo,
99                const char *name,
100                const char *short_name,
101                bool default_suppress,
102                bool default_stop,
103                bool default_notify,
104                const char *description);
105 
106     void
107     RemoveSignal (int signo);
108 
109 protected:
110     //------------------------------------------------------------------
111     // Classes that inherit from UnixSignals can see and modify these
112     //------------------------------------------------------------------
113 
114     struct Signal
115     {
116         ConstString m_name;
117         ConstString m_short_name;
118         std::string m_description;
119         bool m_suppress:1,
120              m_stop:1,
121              m_notify:1;
122 
123         Signal (const char *name,
124                 const char *short_name,
125                 bool default_suppress,
126                 bool default_stop,
127                 bool default_notify,
128                 const char *description);
129 
~SignalSignal130         ~Signal () {}
131     };
132 
133     void
134     Reset ();
135 
136     typedef std::map <int32_t, Signal> collection;
137 
138     collection m_signals;
139 
140     DISALLOW_COPY_AND_ASSIGN (UnixSignals);
141 };
142 
143 } // Namespace lldb
144 #endif  // lldb_UnixSignals_h_
145