From patchwork Thu Jul 30 15:28:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 7937 Received: (qmail 60656 invoked by alias); 30 Jul 2015 15:28:41 -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 60646 invoked by uid 89); 30 Jul 2015 15:28:41 -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-qg0-f65.google.com Received: from mail-qg0-f65.google.com (HELO mail-qg0-f65.google.com) (209.85.192.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 30 Jul 2015 15:28:39 +0000 Received: by qgeu79 with SMTP id u79so2597001qge.0 for ; Thu, 30 Jul 2015 08:28:36 -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:in-reply-to :references; bh=8dhQXHWuN30pu7AWpD+5v1ZYpBUvheN2Z0W15kPTClE=; b=XkSObFBRrKKkGVlg+rMCKgOG9ZiRklTdLtnIOSbZrSxZsyj1vBuTljC3pvFnsS9xUc PuXK+BTYuN5DcvwYjFweyyuNaGXVTXOOtzmq+9gno8rkMZqNiNc0pgRNx5Nw5K3k44sL 5d1Egj3bbz2uxffR4kl0QTrUOlibjmEDtpSEGaRxWicOCUt+u0xqetaXJPc0H6bEtc/n /qMsPjlT9n3iLCZl0dGEMGI1Gy1KCq7G42DQ4yeeCsAKToLTnEHrD+weKj0xZSRSyTXF IqYZxAiI2tT46BGNW4g5dXh4dYsAB6A8PAhjh5aj8br8/MumFDRmg//g7mJ82wS5Kzxg PTfg== X-Gm-Message-State: ALoCoQk5rniwELRp7yAGUej6XB/m9I0cGqGYIFtpVa5NbAiCUVESBvEW0BcDadWuE6dQAvv829AY X-Received: by 10.140.195.136 with SMTP id q130mr6648774qha.49.1438270116738; Thu, 30 Jul 2015 08:28:36 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by smtp.gmail.com with ESMTPSA id o5sm606647qko.49.2015.07.30.08.28.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Jul 2015 08:28:36 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Unset attach_flag when running a new process Date: Thu, 30 Jul 2015 11:28:30 -0400 Message-Id: <1438270110-23564-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <1438219483-13498-1-git-send-email-patrick@parcs.ath.cx> References: <1438219483-13498-1-git-send-email-patrick@parcs.ath.cx> We currently set attach_flag when attaching to a process, so we should make sure to unset it when forking a new process. Otherwise attach_flag would remain set after forking, if the previous process associated with the inferior was attached to. [ I fixed the extended-gdbserver test failure by using prepare_for_testing instead of using build_executable + gdb_start. The former sets remote exec-file which is what makes the "run" command work as expected under extended-gdbserver. ] gdb/ChangeLog: * gdb/infcmd.c (run_comand_1): Unset attach_flag. gdb/testsuite/ChangeLog: * gdb.base/run-after-attach.exp: New test file. * gdb.base/run-after-attach.c: New test file. --- gdb/infcmd.c | 4 ++ gdb/testsuite/gdb.base/run-after-attach.c | 25 +++++++++ gdb/testsuite/gdb.base/run-after-attach.exp | 80 +++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 gdb/testsuite/gdb.base/run-after-attach.c create mode 100644 gdb/testsuite/gdb.base/run-after-attach.exp diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 4948d27..bf8b94b 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -601,6 +601,10 @@ run_command_1 (char *args, int from_tty, int tbreak_at_main) /* Done with ARGS. */ do_cleanups (args_chain); + /* Unset attach_flag, it may be set if the previous process associated with + the inferior was attached to. */ + current_inferior ()->attach_flag = 0; + /* We call get_inferior_args() because we might need to compute the value now. */ run_target->to_create_inferior (run_target, exec_file, get_inferior_args (), diff --git a/gdb/testsuite/gdb.base/run-after-attach.c b/gdb/testsuite/gdb.base/run-after-attach.c new file mode 100644 index 0000000..2398f00 --- /dev/null +++ b/gdb/testsuite/gdb.base/run-after-attach.c @@ -0,0 +1,25 @@ +/* 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 . */ + +#include + +int +main (void) +{ + sleep (600); + return 0; +} diff --git a/gdb/testsuite/gdb.base/run-after-attach.exp b/gdb/testsuite/gdb.base/run-after-attach.exp new file mode 100644 index 0000000..5e4ef49 --- /dev/null +++ b/gdb/testsuite/gdb.base/run-after-attach.exp @@ -0,0 +1,80 @@ +# Copyright (C) 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 forking a process after a previous process was attached to unsets +# attach_flag. This is done indirectly by inspecting GDB's quit prompt. + +if ![can_spawn_for_attach] { + return 0 +} + +standard_testfile +set executable $testfile + +if [prepare_for_testing $testfile.exp $executable] { + return -1 +} + +set testpid [spawn_wait_for_attach $binfile] + +set test "attach to process" +gdb_test "attach $testpid" "Attaching to program.*" $test + +set test "kill process" +send_gdb "kill\n" +gdb_expect { + -re ".y or n. $" { + send_gdb "y\n" + exp_continue + } + -re "$gdb_prompt $" { + pass $test + } + default { + fail $test + } +} + +set test "restart process" +gdb_test "start" "Starting program.*Temporary breakpoint .*" $test + +set test "attempt kill via quit" +send_gdb "quit\n" +set ok 0 +# The quit prompt should warn about killing the process, not about detaching the +# process, since this process was not attached to. +gdb_expect { + -re "will be killed.*.y or n. $" { + set ok 1 + send_gdb "n\n" + exp_continue + } + -re "will be detached.*.y or n. $" { + send_gdb "n\n" + exp_continue + } + -re "$gdb_prompt $" { + if $ok { + pass $test + } else { + fail $test + } + } + default { + fail $test + } +} + +remote_exec host "kill $testpid"