18dffb485Schristos /* Block signals used by gdb 28dffb485Schristos 3*5ba1f45fSchristos Copyright (C) 2019-2024 Free Software Foundation, Inc. 48dffb485Schristos 58dffb485Schristos This file is part of GDB. 68dffb485Schristos 78dffb485Schristos This program is free software; you can redistribute it and/or modify 88dffb485Schristos it under the terms of the GNU General Public License as published by 98dffb485Schristos the Free Software Foundation; either version 3 of the License, or 108dffb485Schristos (at your option) any later version. 118dffb485Schristos 128dffb485Schristos This program is distributed in the hope that it will be useful, 138dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 148dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 158dffb485Schristos GNU General Public License for more details. 168dffb485Schristos 178dffb485Schristos You should have received a copy of the GNU General Public License 188dffb485Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 198dffb485Schristos 208dffb485Schristos #ifndef GDBSUPPORT_BLOCK_SIGNALS_H 218dffb485Schristos #define GDBSUPPORT_BLOCK_SIGNALS_H 228dffb485Schristos 238dffb485Schristos #include <signal.h> 248dffb485Schristos 258dffb485Schristos #include "gdbsupport/gdb-sigmask.h" 268dffb485Schristos 278dffb485Schristos namespace gdb 288dffb485Schristos { 298dffb485Schristos 308dffb485Schristos /* This is an RAII class that temporarily blocks the signals needed by 318dffb485Schristos gdb. This can be used before starting a new thread to ensure that 328dffb485Schristos this thread starts with the appropriate signals blocked. */ 338dffb485Schristos class block_signals 348dffb485Schristos { 358dffb485Schristos public: 368dffb485Schristos block_signals () 378dffb485Schristos { 388dffb485Schristos #ifdef HAVE_SIGPROCMASK 398dffb485Schristos sigset_t mask; 408dffb485Schristos sigemptyset (&mask); 418dffb485Schristos sigaddset (&mask, SIGINT); 428dffb485Schristos sigaddset (&mask, SIGCHLD); 438dffb485Schristos sigaddset (&mask, SIGALRM); 448dffb485Schristos sigaddset (&mask, SIGWINCH); 454b169a6bSchristos sigaddset (&mask, SIGTERM); 468dffb485Schristos gdb_sigmask (SIG_BLOCK, &mask, &m_old_mask); 478dffb485Schristos #endif 488dffb485Schristos } 498dffb485Schristos 508dffb485Schristos ~block_signals () 518dffb485Schristos { 528dffb485Schristos #ifdef HAVE_SIGPROCMASK 538dffb485Schristos gdb_sigmask (SIG_SETMASK, &m_old_mask, nullptr); 548dffb485Schristos #endif 558dffb485Schristos } 568dffb485Schristos 578dffb485Schristos DISABLE_COPY_AND_ASSIGN (block_signals); 588dffb485Schristos 598dffb485Schristos private: 608dffb485Schristos 618dffb485Schristos #ifdef HAVE_SIGPROCMASK 628dffb485Schristos sigset_t m_old_mask; 638dffb485Schristos #endif 648dffb485Schristos }; 658dffb485Schristos 668dffb485Schristos } 678dffb485Schristos 688dffb485Schristos #endif /* GDBSUPPORT_BLOCK_SIGNALS_H */ 69