From patchwork Wed Jan 24 19:47:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 25500 Received: (qmail 14855 invoked by alias); 24 Jan 2018 19:47:28 -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 14846 invoked by uid 89); 24 Jan 2018 19:47:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=detaching, 46114 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 24 Jan 2018 19:47:26 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 030FF81DF4 for ; Wed, 24 Jan 2018 19:47:25 +0000 (UTC) Received: from psique.yyz.redhat.com (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD5965D720; Wed, 24 Jan 2018 19:47:20 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Sergio Durigan Junior Subject: [PATCH] Always print "Detaching after fork from child..." Date: Wed, 24 Jan 2018 14:47:14 -0500 Message-Id: <20180124194714.26222-1-sergiodj@redhat.com> X-IsSubscribed: yes I'd like to propose another patch that we carry on Fedora GDB. It's a simple patch, whose purpose is to always print the "Detaching after fork from child %s." message after a fork/vfork happens. Currently the user can see this message on upstream GDB when she enables "debug infrun" or sets verbosity to "on". The first version of this patch was posted by Jan Kratochvil here: https://www.sourceware.org/ml/gdb-patches/2007-12/msg00087.html But after a reply from Daniel Jacobowitz nothing else happened, until 6c95b8df7fe, which actually introduced the messages as part of a bigger patch by Pedro. I guess the point here is that informing the user that a fork happened is a good thing, and shouldn't be something done only when "debug inferior" or "verbose" are on. I remember a few occasions when, while debugging something using Fedora's GDB, I saw this message and was able to better track the problem. Last, but not least, this patch is being carried with Fedora GDB because of an actual complaint: https://bugzilla.redhat.com/show_bug.cgi?id=235197 Below you can see what changes on the output. With a simple test program: #include int main (int argc, char *argv[]) { fork (); return 0; } Here's the current output, without the patch: (gdb) r Starting program: /tmp/a.out [Inferior 1 (process 3151) exited normally] And here's the output with the patch: (gdb) r Starting program: /tmp/a.out Detaching after fork from child process 24905. [Inferior 1 (process 24901) exited normally] I've had to adapt gdb.base/catch-syscall.exp's usage of "gdb_continue_to_end", but other than that there are no regressions introduced by this change. gdb/ChangeLog: 2018-01-24 Jan Kratochvil Sergio Durigan Junior * infrun.c (): Always print 'fork detach' message. gdb/testsuite/ChangeLog: 2018-01-24 Jan Kratochvil Sergio Durigan Junior * gdb.base/catch-syscall.exp (check_for_program_end): Adjust "gdb_continue_to_end". (test_catch_syscall_with_wrong_args): Likewise. * gdb.base/fork-detach-info.c: New file. * gdb.base/fork-detach-info.exp: New file. --- gdb/infrun.c | 17 ++++++------- gdb/testsuite/gdb.base/catch-syscall.exp | 4 ++-- gdb/testsuite/gdb.base/fork-detach-info.c | 37 +++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/fork-detach-info.exp | 27 +++++++++++++++++++++ 4 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 gdb/testsuite/gdb.base/fork-detach-info.c create mode 100644 gdb/testsuite/gdb.base/fork-detach-info.exp diff --git a/gdb/infrun.c b/gdb/infrun.c index 45fe36a717..cca6e22bb4 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -461,17 +461,14 @@ holding the child stopped. Try \"set detach-on-fork\" or \ remove_breakpoints_pid (ptid_get_pid (inferior_ptid)); } - if (info_verbose || debug_infrun) - { - /* Ensure that we have a process ptid. */ - ptid_t process_ptid = pid_to_ptid (ptid_get_pid (child_ptid)); + /* Ensure that we have a process ptid. */ + ptid_t process_ptid = pid_to_ptid (ptid_get_pid (child_ptid)); - target_terminal::ours_for_output (); - fprintf_filtered (gdb_stdlog, - _("Detaching after %s from child %s.\n"), - has_vforked ? "vfork" : "fork", - target_pid_to_str (process_ptid)); - } + target_terminal::ours_for_output (); + fprintf_filtered (gdb_stdlog, + _("Detaching after %s from child %s.\n"), + has_vforked ? "vfork" : "fork", + target_pid_to_str (process_ptid)); } else { diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp index 2a8bf27e5c..20fa041155 100644 --- a/gdb/testsuite/gdb.base/catch-syscall.exp +++ b/gdb/testsuite/gdb.base/catch-syscall.exp @@ -179,7 +179,7 @@ proc check_for_program_end {} { # Deleting the catchpoints delete_breakpoints - gdb_continue_to_end + gdb_continue_to_end "" continue 1 } proc test_catch_syscall_without_args {} { @@ -250,7 +250,7 @@ proc test_catch_syscall_with_wrong_args {} { # If it doesn't, everything is right (since we don't have # a syscall named "mlock" in it). Otherwise, this is a failure. set thistest "catch syscall with unused syscall ($syscall_name)" - gdb_continue_to_end $thistest + gdb_continue_to_end $thistest continue 1 } } diff --git a/gdb/testsuite/gdb.base/fork-detach-info.c b/gdb/testsuite/gdb.base/fork-detach-info.c new file mode 100644 index 0000000000..182a363dcc --- /dev/null +++ b/gdb/testsuite/gdb.base/fork-detach-info.c @@ -0,0 +1,37 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2007-2018 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 +#include + +int +main (int argc, char *argv[]) +{ + pid_t child; + + child = fork (); + switch (child) + { + case -1: + abort (); + case 0: + default: + break; + } + + return 0; +} diff --git a/gdb/testsuite/gdb.base/fork-detach-info.exp b/gdb/testsuite/gdb.base/fork-detach-info.exp new file mode 100644 index 0000000000..b58c4ba6bf --- /dev/null +++ b/gdb/testsuite/gdb.base/fork-detach-info.exp @@ -0,0 +1,27 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2007-2018 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 . + +standard_testfile + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { + return -1 +} + +set test "print detach message after fork" +gdb_test "r" \ + "Detaching after fork from child process $decimal\.\r\n\\\[Inferior $decimal \\(process $decimal\\) exited normally\\\]" \ + $test