]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add RAII class for blocking gdb signals
authorTom Tromey <tom@tromey.com>
Sun, 29 Sep 2019 14:50:15 +0000 (08:50 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 1 Oct 2019 02:30:39 +0000 (20:30 -0600)
This adds configury support and an RAII class that can be used to
temporarily block signals that are used by gdb.  (This class is not
used in this patch, but it split out for easier review.)

The idea of this patch is that these signals should only be delivered
to the main thread.  So, when creating a background thread, they are
temporarily blocked; the blocked state is inherited by the new thread.

gdb/ChangeLog
2019-09-30  Tom Tromey  <tom@tromey.com>

* gdbsupport/common.m4 (GDB_AC_COMMON): Check for
pthread_sigmask.
* configure: Rebuild.
* gdbsupport/block-signals.h: New file.

gdb/gdbserver/ChangeLog
2019-09-30  Tom Tromey  <tom@tromey.com>

* configure: Rebuild.

gdb/ChangeLog
gdb/configure
gdb/gdbserver/ChangeLog
gdb/gdbserver/configure
gdb/gdbsupport/block-signals.h [new file with mode: 0644]
gdb/gdbsupport/common.m4

index 2eaea1e1ee5e529f9c607451508fc91d1042e0a9..1d834afb3aa0ef89174b69388e9e1a88ae632e1d 100644 (file)
@@ -1,3 +1,10 @@
+2019-09-30  Tom Tromey  <tom@tromey.com>
+
+       * gdbsupport/common.m4 (GDB_AC_COMMON): Check for
+       pthread_sigmask.
+       * configure: Rebuild.
+       * gdbsupport/block-signals.h: New file.
+
 2019-09-30  Tom Tromey  <tom@tromey.com>
 
        * acinclude.m4: Include ax_pthread.m4.
index 263f301d8eed2d53af8182d51970c3514eda0efc..0235c3e8c12542c20ebe0f2416cbf970f285ff64 100755 (executable)
@@ -2506,6 +2506,73 @@ fi
   as_fn_set_status $ac_retval
 
 } # ac_fn_cxx_try_link
+
+# ac_fn_cxx_check_func LINENO FUNC VAR
+# ------------------------------------
+# Tests whether FUNC exists, setting the cache variable VAR accordingly
+ac_fn_cxx_check_func ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $2 innocuous_$2
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $2 (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $2
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $2 ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$2 || defined __stub___$2
+choke me
+#endif
+
+int
+main ()
+{
+return $2 ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_cxx_check_func
 cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
@@ -14316,6 +14383,21 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_cxx_std_thread" >&5
 $as_echo "$gdb_cv_cxx_std_thread" >&6; }
+
+    # This check must be here, while LIBS includes any necessary
+    # threading library.
+    for ac_func in pthread_sigmask
+do :
+  ac_fn_cxx_check_func "$LINENO" "pthread_sigmask" "ac_cv_func_pthread_sigmask"
+if test "x$ac_cv_func_pthread_sigmask" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_PTHREAD_SIGMASK 1
+_ACEOF
+
+fi
+done
+
+
     LIBS="$save_LIBS"
     CXXFLAGS="$save_CXXFLAGS"
   fi
index 43abb62ac71e5a6b359b063cfce6195f5e86ada6..37bdff12b66750035ce9865e13b4a59d554d801f 100644 (file)
@@ -1,3 +1,7 @@
+2019-09-30  Tom Tromey  <tom@tromey.com>
+
+       * configure: Rebuild.
+
 2019-09-30  Tom Tromey  <tom@tromey.com>
 
        * acinclude.m4: Include ax_pthread.m4.
index aa13ce6aa4b5609894fd62144c38e7e13d0d4fb6..5324399009760b7799d71ed6f619eb14bb348186 100755 (executable)
@@ -1972,6 +1972,119 @@ $as_echo "$ac_res" >&6; }
 
 } # ac_fn_c_check_decl
 
+# ac_fn_cxx_try_link LINENO
+# -------------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded.
+ac_fn_cxx_try_link ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext conftest$ac_exeext
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+        test -z "$ac_cxx_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+        test "$cross_compiling" = yes ||
+        test -x conftest$ac_exeext
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=1
+fi
+  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
+  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
+  # interfere with the next link command; also delete a directory that is
+  # left behind by Apple's compiler.  We do this before executing the actions.
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_cxx_try_link
+
+# ac_fn_cxx_check_func LINENO FUNC VAR
+# ------------------------------------
+# Tests whether FUNC exists, setting the cache variable VAR accordingly
+ac_fn_cxx_check_func ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $2 innocuous_$2
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $2 (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $2
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $2 ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$2 || defined __stub___$2
+choke me
+#endif
+
+int
+main ()
+{
+return $2 ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_cxx_check_func
+
 # ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
 # --------------------------------------------
 # Tries to find the compile-time value of EXPR in a program that includes
@@ -7608,6 +7721,21 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_cxx_std_thread" >&5
 $as_echo "$gdb_cv_cxx_std_thread" >&6; }
+
+    # This check must be here, while LIBS includes any necessary
+    # threading library.
+    for ac_func in pthread_sigmask
+do :
+  ac_fn_cxx_check_func "$LINENO" "pthread_sigmask" "ac_cv_func_pthread_sigmask"
+if test "x$ac_cv_func_pthread_sigmask" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_PTHREAD_SIGMASK 1
+_ACEOF
+
+fi
+done
+
+
     LIBS="$save_LIBS"
     CXXFLAGS="$save_CXXFLAGS"
   fi
diff --git a/gdb/gdbsupport/block-signals.h b/gdb/gdbsupport/block-signals.h
new file mode 100644 (file)
index 0000000..04a53a2
--- /dev/null
@@ -0,0 +1,65 @@
+/* Block signals used by gdb
+
+   Copyright (C) 2019 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDBSUPPORT_BLOCK_SIGNALS_H
+#define GDBSUPPORT_BLOCK_SIGNALS_H
+
+#include <signal.h>
+
+namespace gdb
+{
+
+/* This is an RAII class that temporarily blocks the signals needed by
+   gdb.  This can be used before starting a new thread to ensure that
+   this thread starts with the appropriate signals blocked.  */
+class block_signals
+{
+public:
+  block_signals ()
+  {
+#ifdef HAVE_PTHREAD_SIGMASK
+    sigset_t mask;
+    sigemptyset (&mask);
+    sigaddset (&mask, SIGINT);
+    sigaddset (&mask, SIGCHLD);
+    sigaddset (&mask, SIGALRM);
+    sigaddset (&mask, SIGWINCH);
+    pthread_sigmask (SIG_BLOCK, &mask, &m_old_mask);
+#endif
+  }
+
+  ~block_signals ()
+  {
+#ifdef HAVE_PTHREAD_SIGMASK
+    pthread_sigmask (SIG_SETMASK, &m_old_mask, nullptr);
+#endif
+  }
+
+  DISABLE_COPY_AND_ASSIGN (block_signals);
+
+private:
+
+#ifdef HAVE_PTHREAD_SIGMASK
+  sigset_t m_old_mask;
+#endif
+};
+
+}
+
+#endif /* GDBSUPPORT_BLOCK_SIGNALS_H */
index 0f0e9a866ebb147c2bb71720d275b2f43f87a348..b5f477b076904b233b054baea3c2189d4080da82 100644 (file)
@@ -53,6 +53,11 @@ AC_DEFUN([GDB_AC_COMMON], [
     [[std::thread t(callback);]])],
                                  gdb_cv_cxx_std_thread=yes,
                                  gdb_cv_cxx_std_thread=no)])
+
+    # This check must be here, while LIBS includes any necessary
+    # threading library.
+    AC_CHECK_FUNCS([pthread_sigmask])
+
     LIBS="$save_LIBS"
     CXXFLAGS="$save_CXXFLAGS"
   fi