From patchwork Tue Oct 1 20:12:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 34773 Received: (qmail 41560 invoked by alias); 1 Oct 2019 20:12:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 41549 invoked by uid 89); 1 Oct 2019 20:12:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=Inter X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.49.218) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Oct 2019 20:12:37 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 77AA0366A for ; Tue, 1 Oct 2019 15:12:34 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id FOVeiTLFZ3Qi0FOVei25xX; Tue, 01 Oct 2019 15:12:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ACvD290qjMeMr47D5BAakhhC4uP7vtn0J5DAnQ4dpaM=; b=UR1fPsqKT+amHOKtHmgB0GhTs3 j2CoDEr9iOf85ODRLlgA5A/NuLM7e5lFn3AqnE94ZXCIkcupSLCL5YH+Z5+Dx3LKAFKAMzS1O21i4 m2CRyR7J2vUomAwYvTbcoyqUf; Received: from 75-166-72-156.hlrn.qwest.net ([75.166.72.156]:47310 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1iFOVd-0023p5-Pu; Tue, 01 Oct 2019 14:12:33 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v4 04/11] Add RAII class for blocking gdb signals Date: Tue, 1 Oct 2019 14:12:20 -0600 Message-Id: <20191001201227.8519-5-tom@tromey.com> In-Reply-To: <20191001201227.8519-1-tom@tromey.com> References: <20191001201227.8519-1-tom@tromey.com> 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-10-01 Tom Tromey * gdbsupport/common.m4 (GDB_AC_COMMON): Check for pthread_sigmask. * configure: Rebuild. * gdbsupport/block-signals.h: New file. gdb/gdbserver/ChangeLog 2019-10-01 Tom Tromey * configure: Rebuild. --- gdb/ChangeLog | 7 ++ gdb/configure | 82 +++++++++++++++++++++ gdb/gdbserver/ChangeLog | 4 ++ gdb/gdbserver/configure | 128 +++++++++++++++++++++++++++++++++ gdb/gdbsupport/block-signals.h | 65 +++++++++++++++++ gdb/gdbsupport/common.m4 | 5 ++ 6 files changed, 291 insertions(+) create mode 100644 gdb/gdbsupport/block-signals.h diff --git a/gdb/configure b/gdb/configure index 263f301d8ee..0235c3e8c12 100755 --- a/gdb/configure +++ b/gdb/configure @@ -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 declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#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 diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure index aa13ce6aa4b..53243990097 100755 --- a/gdb/gdbserver/configure +++ b/gdb/gdbserver/configure @@ -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 declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#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 index 00000000000..04a53a2ec14 --- /dev/null +++ b/gdb/gdbsupport/block-signals.h @@ -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 . */ + +#ifndef GDBSUPPORT_BLOCK_SIGNALS_H +#define GDBSUPPORT_BLOCK_SIGNALS_H + +#include + +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 */ diff --git a/gdb/gdbsupport/common.m4 b/gdb/gdbsupport/common.m4 index 0f0e9a866eb..b5f477b0769 100644 --- a/gdb/gdbsupport/common.m4 +++ b/gdb/gdbsupport/common.m4 @@ -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