From patchwork Fri Jul 24 18:33:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 7840 Received: (qmail 56984 invoked by alias); 24 Jul 2015 18:33:59 -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 56972 invoked by uid 89); 24 Jul 2015 18:33:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qk0-f176.google.com Received: from mail-qk0-f176.google.com (HELO mail-qk0-f176.google.com) (209.85.220.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 24 Jul 2015 18:33:57 +0000 Received: by qkfc129 with SMTP id c129so19615730qkf.1 for ; Fri, 24 Jul 2015 11:33:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=G2wZRmmzIQPJmPY/KNsZbDzK6tU6WlnqC4+Tt1lWWbw=; b=dbTAR+MKMbeerZ39zxi/CcQNG1d5CRWsfYTtjTo7FPh4kKJg3DNOfH0K8mNRQQOLDb dGnC/xvksaFr1XBnGl0yNK0aWon7Hx3fAflTDj8YglytM+ICan4oq5qw9sI7Kivs+VKg Ypd76RGeQnW9I+axHv4Gze3hV5+TQXaTFnpE14FjR0c+/BF8VQueqHVHue8c0JBlcO3o GcO9Cjs7/dJ5TCCxUm/fjmRmd6s7EYTvBt3az2XomVPlOn3B53JsxPenAiZ421ny0xEU 7F6humwTxLKovJzBJV77Ixn0jQ4Nb6xpmEV0IvHq6FlNrH1+pF63hD8YbbwKUoOXkues odnA== X-Gm-Message-State: ALoCoQkPTZ6oerUfh6jIlfqTrW+sml3Rug8LeBc1/4zglL/L+94y5Nw/ptil36MkNZ2DPikf2KS+ X-Received: by 10.55.31.65 with SMTP id f62mr21868779qkf.73.1437762835068; Fri, 24 Jul 2015 11:33:55 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by smtp.gmail.com with ESMTPSA id o5sm4452769qko.49.2015.07.24.11.33.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Jul 2015 11:33:54 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Have SIGTERM promptly quit GDB even when the dummy target is active Date: Fri, 24 Jul 2015 14:33:49 -0400 Message-Id: <1437762829-5214-1-git-send-email-patrick@parcs.ath.cx> GDB currently does not promptly quit after receiving a SIGTERM while no proper target is active. This is because in handle_sigterm we currently look at target_can_async_p to determine whether to asynchronously quit GDB using an async signal handler or to asynchronously quit using the quit flag. However, target_can_async_p is always false under the dummy target, so under this target we always use the quit flag and not the async signal handler to signal that GDB should quit. So GDB won't quit until a code path that checks the quit flag is executed. To fix this issue, this patch makes the SIGTERM handler no longer inspect target_can_async_p, and instead makes the handler unconditionally set the quit flag _and_ mark the corresponding async signal handler, so that if the target is async (or if it's the dummy target) then we will likely quit through the async signal handler, and if it's not async then we will likely quit through the quit flag. This redundant approach is similar to how we handle SIGINT. gdb/ChangeLog: * event-top.c (handle_sigterm): Don't inspect target_can_async_p. Always set the quit flag and always mark the async signal handler. gdb/testsuite/ChangeLog: * gdb.base/gdb-sigterm-2.exp: New test. --- gdb/event-top.c | 13 ++++-------- gdb/testsuite/gdb.base/gdb-sigterm-2.exp | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 gdb/testsuite/gdb.base/gdb-sigterm-2.exp diff --git a/gdb/event-top.c b/gdb/event-top.c index e9cc2d7..1762e3b 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -876,15 +876,10 @@ handle_sigterm (int sig) { signal (sig, handle_sigterm); - /* Call quit_force in a signal safe way. - quit_force itself is not signal safe. */ - if (target_can_async_p ()) - mark_async_signal_handler (async_sigterm_token); - else - { - sync_quit_force_run = 1; - set_quit_flag (); - } + sync_quit_force_run = 1; + set_quit_flag (); + + mark_async_signal_handler (async_sigterm_token); } /* Do the quit. All the checks have been done by the caller. */ diff --git a/gdb/testsuite/gdb.base/gdb-sigterm-2.exp b/gdb/testsuite/gdb.base/gdb-sigterm-2.exp new file mode 100644 index 0000000..73313aa --- /dev/null +++ b/gdb/testsuite/gdb.base/gdb-sigterm-2.exp @@ -0,0 +1,35 @@ +# This testcase is part of GDB, the GNU debugger. +# +# Copyright 2015 Free Software Foundation, Inc. +# +# 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 . + +# Check that GDB promptly quits after receiving a SIGTERM while no proper +# target is active. + +gdb_start + +set gdb_pid [exp_pid -i [board_info host fileid]] +remote_exec host "kill -TERM $gdb_pid" + +set test "expect eof" + +gdb_expect 5 { + eof { + pass $test + } + timeout { + fail $test + } +}