From patchwork Mon Aug 17 13:01:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 8237 Received: (qmail 65776 invoked by alias); 17 Aug 2015 13:01:45 -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 65759 invoked by uid 89); 17 Aug 2015 13:01:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_05, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qg0-f46.google.com Received: from mail-qg0-f46.google.com (HELO mail-qg0-f46.google.com) (209.85.192.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 17 Aug 2015 13:01:42 +0000 Received: by qgeg42 with SMTP id g42so93251287qge.1 for ; Mon, 17 Aug 2015 06:01:39 -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=k0RmkbUZNonrPQlCwXJssp1IO6RD7+0VGhVYD/NJiKI=; b=KAIrxDmXlgEXntf9GnAiZxTkt7R3GHX1/46a0yhYlt+u+85bs/fL4blYR9/r/i5FbJ e8sNIfoHTNe9u3n0xzSo0fKvzGddIRhgLC56HHmWJZ3GS524sVFvVEpiPcbAhZvCe3Q+ CLb6pEWXN6orGRxIFFkMqIE9qnnbcRGBGray7AIuWaWvXpSae/hmJNKoYsVFrXv3itHn prIfDiY/wwTIsBoYKbror+as2cKzyxFTMuq0aleaOa9FeiYRcxDBK9b/oK+vlhj07QoE m1wecADDbfslMGmz0JFCat7Y5VAidxrlrqlG6uxvOR0/prvn07uT2eOgarUOe3Dan1nB nGFg== X-Gm-Message-State: ALoCoQkjgocrJSGf4BRrpKW9+WntLFYZIZr7GbtWjRhewRWgUTeMZdCnJCIarkR0oCGBUHxyP8DD X-Received: by 10.140.238.85 with SMTP id j82mr2306303qhc.77.1439816499759; Mon, 17 Aug 2015 06:01:39 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by smtp.gmail.com with ESMTPSA id z128sm1844165qhd.43.2015.08.17.06.01.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Aug 2015 06:01:39 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Unset attach_flag when running a new process Date: Mon, 17 Aug 2015 09:01:33 -0400 Message-Id: <1439816493-17559-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: References: 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. gdb/ChangeLog: * target.c (target_pre_inferior): 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/target.c | 4 ++ gdb/testsuite/gdb.base/run-after-attach.c | 25 +++++++++++ gdb/testsuite/gdb.base/run-after-attach.exp | 65 +++++++++++++++++++++++++++++ 3 files changed, 94 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/target.c b/gdb/target.c index e41a338..96e7df7 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2138,6 +2138,10 @@ target_pre_inferior (int from_tty) target_clear_description (); } + /* attach_flag may be set if the previous process associated with + the inferior was attached to. */ + current_inferior ()->attach_flag = 0; + agent_capability_invalidate (); } 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..8de7ac6 --- /dev/null +++ b/gdb/testsuite/gdb.base/run-after-attach.exp @@ -0,0 +1,65 @@ +# 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 test_spawn_id [spawn_wait_for_attach $binfile] +set test_pid [spawn_id_get_pid $test_spawn_id] + +set test "attach to process" +gdb_test "attach $test_pid" "Attaching to program.*" $test + +set test "kill process" +gdb_test "kill" "" $test \ + "Kill the program being debugged.*y or n. $" "y" + +set test "restart process" +gdb_test "start" "Starting program.*Temporary breakpoint .*" $test + +set test "attempt kill via quit" +# The quit prompt should warn about killing the process, not about detaching the +# process, since this process was not attached to. +set ok 0 +gdb_test_multiple "quit" $test { + -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 $" { + gdb_assert $ok $test + } + default { + fail $test + } +} + +kill_wait_spawned_process $test_spawn_id