Commit | Line | Data |
---|---|---|
21987b9c TT |
1 | /* Block signals used by gdb |
2 | ||
b811d2c2 | 3 | Copyright (C) 2019-2020 Free Software Foundation, Inc. |
21987b9c TT |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #ifndef GDBSUPPORT_BLOCK_SIGNALS_H | |
21 | #define GDBSUPPORT_BLOCK_SIGNALS_H | |
22 | ||
23 | #include <signal.h> | |
24 | ||
25 | #include "gdbsupport/gdb-sigmask.h" | |
26 | ||
27 | namespace gdb | |
28 | { | |
29 | ||
30 | /* This is an RAII class that temporarily blocks the signals needed by | |
31 | gdb. This can be used before starting a new thread to ensure that | |
32 | this thread starts with the appropriate signals blocked. */ | |
33 | class block_signals | |
34 | { | |
35 | public: | |
36 | block_signals () | |
37 | { | |
38 | #ifdef HAVE_SIGPROCMASK | |
39 | sigset_t mask; | |
40 | sigemptyset (&mask); | |
41 | sigaddset (&mask, SIGINT); | |
42 | sigaddset (&mask, SIGCHLD); | |
43 | sigaddset (&mask, SIGALRM); | |
44 | sigaddset (&mask, SIGWINCH); | |
45 | gdb_sigmask (SIG_BLOCK, &mask, &m_old_mask); | |
46 | #endif | |
47 | } | |
48 | ||
49 | ~block_signals () | |
50 | { | |
51 | #ifdef HAVE_SIGPROCMASK | |
52 | gdb_sigmask (SIG_SETMASK, &m_old_mask, nullptr); | |
53 | #endif | |
54 | } | |
55 | ||
56 | DISABLE_COPY_AND_ASSIGN (block_signals); | |
57 | ||
58 | private: | |
59 | ||
60 | #ifdef HAVE_SIGPROCMASK | |
61 | sigset_t m_old_mask; | |
62 | #endif | |
63 | }; | |
64 | ||
65 | } | |
66 | ||
67 | #endif /* GDBSUPPORT_BLOCK_SIGNALS_H */ |