public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Sergio Durigan Junior <sergiodj@redhat.com>
To: GDB Patches <gdb-patches@sourceware.org>
Cc: Sergio Durigan Junior <sergiodj@redhat.com>
Subject: [PATCH] Always print "Detaching after fork from child..."
Date: Wed, 24 Jan 2018 19:47:00 -0000	[thread overview]
Message-ID: <20180124194714.26222-1-sergiodj@redhat.com> (raw)

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 <unistd.h>

  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  <jan.kratochvil@redhat.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* infrun.c (): Always print 'fork detach' message.

gdb/testsuite/ChangeLog:
2018-01-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* 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 <http://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+#include <unistd.h>
+
+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 <http://www.gnu.org/licenses/>.
+
+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
-- 
2.14.3

             reply	other threads:[~2018-01-24 19:47 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24 19:47 Sergio Durigan Junior [this message]
2018-01-24 20:43 ` Jan Kratochvil
2018-01-24 20:56   ` Sergio Durigan Junior
2018-01-25 15:59     ` Pedro Alves
2018-01-25 20:21       ` Sergio Durigan Junior
2018-01-25 22:39         ` Pedro Alves
2018-01-31 16:57 ` [PATCH v2] Enable 'set print inferior-events' and cleanup attach/detach messages Sergio Durigan Junior
2018-02-01 17:17   ` Pedro Alves
2018-03-06  1:44     ` Sergio Durigan Junior
2018-03-09 21:56 ` [PATCH v3] Enable 'set print inferior-events' and improve detach/fork/kill/exit messages Sergio Durigan Junior
2018-03-20 19:24   ` Sergio Durigan Junior
2018-03-26 10:58   ` Pedro Alves
2018-03-26 11:43     ` Pedro Alves
2018-04-03  0:15       ` Sergio Durigan Junior
2018-04-02 21:51     ` Sergio Durigan Junior
2018-04-05 18:47 ` [PATCH v4] " Sergio Durigan Junior
2018-04-05 21:32   ` Sergio Durigan Junior
2018-04-06 15:39   ` Pedro Alves
2018-04-06 15:56     ` Sergio Durigan Junior
2018-04-06 16:41       ` Pedro Alves
2018-04-10 16:22         ` Sergio Durigan Junior
2018-04-11 18:46 ` [PATCH v5] " Sergio Durigan Junior
2018-04-11 19:05   ` Pedro Alves
2018-04-11 19:08     ` Sergio Durigan Junior
2018-04-16 20:04 ` [PATCH v6] " Sergio Durigan Junior
2018-04-17 15:57   ` Pedro Alves
2018-04-17 20:07     ` Sergio Durigan Junior
2018-04-19 19:54 ` [PATCH v7] " Sergio Durigan Junior
2018-04-24 13:33   ` Pedro Alves
2018-04-24 19:49     ` Sergio Durigan Junior
2018-04-25 17:41       ` [PATCH] Fix new inferior events output (Re: [PATCH v7] Enable 'set print inferior-events' and improve detach/fork/kill/exit messages) Pedro Alves
2018-04-25 17:53         ` Sergio Durigan Junior
2018-04-25 18:07           ` Pedro Alves

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=20180124194714.26222-1-sergiodj@redhat.com \
    --to=sergiodj@redhat.com \
    --cc=gdb-patches@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: link
Be 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).