public inbox for gdb-prs@sourceware.org help / color / mirror / Atom feed
From: "xdje42 at gmail dot com" <sourceware-bugzilla@sourceware.org> To: gdb-prs@sourceware.org Subject: [Bug python/17314] Any thread created by Python must block SIGCHLD Date: Sun, 31 Aug 2014 02:40:00 -0000 [thread overview] Message-ID: <bug-17314-4717-s4qPvVdasu@http.sourceware.org/bugzilla/> (raw) In-Reply-To: <bug-17314-4717@http.sourceware.org/bugzilla/> https://sourceware.org/bugzilla/show_bug.cgi?id=17314 Doug Evans <xdje42 at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |xdje42 at gmail dot com --- Comment #1 from Doug Evans <xdje42 at gmail dot com> --- Setting aside the configure.ac changes, here's a prototype patch to forward SIGCHLD to gdb's thread. diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 1e8991d..af0cfe2 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -24,9 +24,9 @@ #include "nat/linux-nat.h" #include "nat/linux-waitpid.h" #include "gdb_wait.h" -#ifdef HAVE_TKILL_SYSCALL -#include <unistd.h> -#include <sys/syscall.h> +#if defined (HAVE_TKILL_SYSCALL) || defined (HAVE_GETTID_SYSCALL) +#include <unistd.h> /* for syscall */ +#include <sys/syscall.h> /* for syscall numbers */ #endif #include <sys/ptrace.h> #include "linux-nat.h" @@ -171,6 +171,11 @@ blocked. */ #define O_LARGEFILE 0 #endif +#ifdef HAVE_GETTID_SYSCALL +/* The thread id (result of gettid) for gdb. */ +static pid_t gdb_tid; +#endif + /* The single-threaded native GNU/Linux target_ops. We save a pointer for the use of the multi-threaded target. */ static struct target_ops *linux_ops; @@ -4664,6 +4673,41 @@ sigchld_handler (int signo) { int old_errno = errno; +#ifdef HAVE_GETTID_SYSCALL + /* If the user starts other threads (e.g. via python) and if the user + doesn't remember to block SIGCHLD in those threads, then that thread + may receive the SIGCHLD instead of GDB. This is bad because gdb will + then hang in sigsuspend waiting for the SIGCHLD. PRs 17247, 17314. + If we get a SIGCHLD in a different thread, forward the SIGCHLD onto + GDB's thread (if we can). */ + { + pid_t this_tid = syscall (__NR_gettid); + + /* IWBN to print an error message here if gettid fails. + However, it shouldn't ever fail, and if it does it's possible we'll + flood the terminal with failure messages. Since we're in async code + it's harder to clip the output after a certain number of failures, + so instead just punt. */ +#ifdef HAVE_TKILL_SYSCALL + if (this_tid > 0 && this_tid != gdb_tid) + { + if (debug_linux_nat) + { + static const char forwarding_msg[] + = "sigchld: forwarding signal to gdb's thread\n"; + + ui_file_write_async_safe (gdb_stdlog, forwarding_msg, + strlen (forwarding_msg)); + } + + kill_lwp (gdb_tid, SIGCHLD); + errno = old_errno; + return; + } +#endif + } +#endif + if (debug_linux_nat) ui_file_write_async_safe (gdb_stdlog, "sigchld\n", sizeof ("sigchld\n") - 1); @@ -5013,6 +5057,12 @@ extern initialize_file_ftype _initialize_linux_nat; void _initialize_linux_nat (void) { +#ifdef HAVE_GETTID_SYSCALL + /* Remember gdb's thread id so that we can perform a sanity check in + sigchld_handler. */ + gdb_tid = syscall (__NR_gettid); +#endif + add_setshow_zuinteger_cmd ("lin-lwp", class_maintenance, &debug_linux_nat, _("\ Set debugging of GNU/Linux lwp module."), _("\ -- You are receiving this mail because: You are on the CC list for the bug.
next prev parent reply other threads:[~2014-08-31 2:40 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-08-26 20:37 [Bug python/17314] New: " dje at google dot com 2014-08-31 2:40 ` xdje42 at gmail dot com [this message] 2014-09-13 22:55 ` [Bug python/17314] " cvs-commit at gcc dot gnu.org 2022-06-12 16:42 ` tromey at sourceware dot org 2023-03-07 18:38 ` tromey at sourceware dot org 2023-07-31 16:03 ` tromey at sourceware dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-17314-4717-s4qPvVdasu@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=gdb-prs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).