[02/16,v2] Refactor follow-fork message printing

Message ID 1408580964-27916-3-git-send-email-donb@codesourcery.com
State New, archived
Headers

Commit Message

Don Breazeal Aug. 21, 2014, 12:29 a.m. UTC
  This patch refactors the code that prints messages related to follow-fork
into functions, and adds a call so that a message is now printed when the
parent process is detached.  Previously in this case the only message was
notification of attaching to the child.  We still do not print any messages
when following the parent and detaching the child (the default).  My 
rationale for this is that from the user's perspective the new child was
never attached.

The messages now distinguish between fork and vfork.

Note that all of these messages are only printed when 'verbose' is set or
when debugging is turned on.

This is preparatory work for follow-fork and detach-on-fork on
extended-remote linux targets.

The test gdb.base/foll-fork.exp was modified to check for the new message.

Tested on x64 Ubuntu Lucid, native only.

Thanks,
--Don

gdb/
2014-08-20  Don Breazeal  <donb@codesourcery.com>

	* gdb/infrun.c (print_fork_attach): New function.
	(print_fork_detach): New function.
	(follow_fork_inferior): Call print_fork_attach and print_fork_detach.
	(handle_vfork_child_exec_or_exit): Ditto.

gdb/testsuite/
2014-08-20  Don Breazeal  <donb@codesourcery.com>

	* gdb.base/foll-fork.exp (test_follow_fork): Add check for new
	detach message.
	(catch_fork_child_follow): Ditto.
	* gdb.base/foll-vfork.exp (vfork_parent_follow_through_step):
	Modify to check for "vfork" instead of "fork".
	(vfork_parent_follow_to_bp): Ditto.
	(vfork_and_exec_child_follow_through_step): Ditto.
	(vfork_and_exec_child_follow_to_main_bp): Ditto, plus add check
	for new detach message.

---
 gdb/infrun.c                          |   94 +++++++++++++++++++-------------
 gdb/testsuite/gdb.base/foll-fork.exp  |   12 +++--
 gdb/testsuite/gdb.base/foll-vfork.exp |    8 ++--
 3 files changed, 68 insertions(+), 46 deletions(-)
  

Comments

Pedro Alves Sept. 26, 2014, 7:52 p.m. UTC | #1
On 08/21/2014 01:29 AM, Don Breazeal wrote:
> This patch refactors the code that prints messages related to follow-fork
> into functions, and adds a call so that a message is now printed when the
> parent process is detached.  Previously in this case the only message was
> notification of attaching to the child.  We still do not print any messages
> when following the parent and detaching the child (the default).  My 
> rationale for this is that from the user's perspective the new child was
> never attached.
> 
> The messages now distinguish between fork and vfork.
> 
> Note that all of these messages are only printed when 'verbose' is set or
> when debugging is turned on.
> 
> This is preparatory work for follow-fork and detach-on-fork on
> extended-remote linux targets.
> 
> The test gdb.base/foll-fork.exp was modified to check for the new message.
> 
> Tested on x64 Ubuntu Lucid, native only.
> 
> Thanks,
> --Don
> 
> gdb/
> 2014-08-20  Don Breazeal  <donb@codesourcery.com>
> 
> 	* gdb/infrun.c (print_fork_attach): New function.
> 	(print_fork_detach): New function.
> 	(follow_fork_inferior): Call print_fork_attach and print_fork_detach.
> 	(handle_vfork_child_exec_or_exit): Ditto.
> 
> gdb/testsuite/
> 2014-08-20  Don Breazeal  <donb@codesourcery.com>
> 
> 	* gdb.base/foll-fork.exp (test_follow_fork): Add check for new
> 	detach message.
> 	(catch_fork_child_follow): Ditto.
> 	* gdb.base/foll-vfork.exp (vfork_parent_follow_through_step):
> 	Modify to check for "vfork" instead of "fork".
> 	(vfork_parent_follow_to_bp): Ditto.
> 	(vfork_and_exec_child_follow_through_step): Ditto.
> 	(vfork_and_exec_child_follow_to_main_bp): Ditto, plus add check
> 	for new detach message.
> 
> ---
>  gdb/infrun.c                          |   94 +++++++++++++++++++-------------
>  gdb/testsuite/gdb.base/foll-fork.exp  |   12 +++--
>  gdb/testsuite/gdb.base/foll-vfork.exp |    8 ++--
>  3 files changed, 68 insertions(+), 46 deletions(-)
> 
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index a51c759..34e9295 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -567,6 +567,49 @@ follow_fork (void)
>    return should_resume;
>  }
>  
> +/* Print details about attaching to a process after a fork call.  */
> +
> +static void
> +print_fork_attach (pid_t child_pid, pid_t parent_pid, int is_vfork)

As this is called for the child only, I think it'd be good to make
that explicit in the name.  E.g., print_attach_fork_child.

> +{
> +  if (info_verbose || debug_infrun)
> +    {
> +      target_terminal_ours ();

We should really be using target_terminal_ours_for_output for
output instead.

> +      fprintf_filtered (gdb_stdlog,
> +			_("Attaching after process %d "
> +			  "%s to child process %d.\n"),
> +			parent_pid, is_vfork?"vfork":"fork", child_pid);

Spaces around "?" and ":":  'is_vfork ? "vfork" : "fork"'


> +    }
> +}
> +
> +/* Print details about detaching from a process after a fork call.  */
> +
> +static void
> +print_fork_detach (pid_t pid, int is_parent, int is_vfork, char *vfork_action)
> +{
> +  if (info_verbose || debug_infrun)
> +    {
> +      target_terminal_ours ();
> +
> +      if (is_parent && is_vfork)
> +	{
> +	  /* Detaching a vfork parent, so print what the child did
> +	     that allows the parent to resume.  */
> +	  gdb_assert (vfork_action != NULL && strlen (vfork_action) > 0);

Write: '*vfork_action != '\0' instead of that strlen.

> +	  fprintf_filtered (gdb_stdlog,
> +			    "Detaching vfork parent process %d after"
> +			    " child %s.\n", pid, vfork_action);

This handling of vfork_action is bad for i18n.  While at it, this is
missing _().  More below.

> +	}
> +      else
> +	{
> +	  fprintf_filtered (gdb_stdlog,
> +			    _("Detaching after %s from %s process %d.\n"),
> +			    is_vfork?"vfork":"fork",
> +			    is_parent?"parent":"child", pid);

Spaces around operators.  "parent" and "child" really shouldn't
be passed as %s, as this will be awkward when translated.  We should
split those out instead, like:

if (is_parent)
  {
     fprintf_filtered (gdb_stdlog,
		       _("Detaching after %s from parent process %d.\n"),
                       is_vfork ? "vfork" : "fork", pid);
  }
else
  {
     fprintf_filtered (gdb_stdlog,
		       _("Detaching after %s from child process %d.\n"),
		       is_vfork ? "vfork" : "fork", pid);
  }

But after unrolling this, is there really any benefit to
print_fork_detach?  It doesn't seem that it'll ever end
up called twice with the same arguments...  Seems like
we may be obfuscating more than clarifying with the patch.

Thanks,
Pedro Alves
  
Don Breazeal Sept. 26, 2014, 8:14 p.m. UTC | #2
On 9/26/2014 12:52 PM, Pedro Alves wrote:
> On 08/21/2014 01:29 AM, Don Breazeal wrote:
>> This patch refactors the code that prints messages related to follow-fork
>> into functions, and adds a call so that a message is now printed when the
>> parent process is detached.  Previously in this case the only message was
>> notification of attaching to the child.  We still do not print any messages
>> when following the parent and detaching the child (the default).  My 
>> rationale for this is that from the user's perspective the new child was
>> never attached.
>>
>> The messages now distinguish between fork and vfork.
>>
>> Note that all of these messages are only printed when 'verbose' is set or
>> when debugging is turned on.
>>
>> This is preparatory work for follow-fork and detach-on-fork on
>> extended-remote linux targets.
>>
>> The test gdb.base/foll-fork.exp was modified to check for the new message.
>>
>> Tested on x64 Ubuntu Lucid, native only.
>>
>> Thanks,
>> --Don
>>
>> gdb/
>> 2014-08-20  Don Breazeal  <donb@codesourcery.com>
>>
>> 	* gdb/infrun.c (print_fork_attach): New function.
>> 	(print_fork_detach): New function.
>> 	(follow_fork_inferior): Call print_fork_attach and print_fork_detach.
>> 	(handle_vfork_child_exec_or_exit): Ditto.
>>
>> gdb/testsuite/
>> 2014-08-20  Don Breazeal  <donb@codesourcery.com>
>>
>> 	* gdb.base/foll-fork.exp (test_follow_fork): Add check for new
>> 	detach message.
>> 	(catch_fork_child_follow): Ditto.
>> 	* gdb.base/foll-vfork.exp (vfork_parent_follow_through_step):
>> 	Modify to check for "vfork" instead of "fork".
>> 	(vfork_parent_follow_to_bp): Ditto.
>> 	(vfork_and_exec_child_follow_through_step): Ditto.
>> 	(vfork_and_exec_child_follow_to_main_bp): Ditto, plus add check
>> 	for new detach message.
>>
>> ---
>>  gdb/infrun.c                          |   94 +++++++++++++++++++-------------
>>  gdb/testsuite/gdb.base/foll-fork.exp  |   12 +++--
>>  gdb/testsuite/gdb.base/foll-vfork.exp |    8 ++--
>>  3 files changed, 68 insertions(+), 46 deletions(-)
>>
>> diff --git a/gdb/infrun.c b/gdb/infrun.c
>> index a51c759..34e9295 100644
>> --- a/gdb/infrun.c
>> +++ b/gdb/infrun.c
>> @@ -567,6 +567,49 @@ follow_fork (void)
>>    return should_resume;
>>  }
>>  
>> +/* Print details about attaching to a process after a fork call.  */
>> +
>> +static void
>> +print_fork_attach (pid_t child_pid, pid_t parent_pid, int is_vfork)
> 
> As this is called for the child only, I think it'd be good to make
> that explicit in the name.  E.g., print_attach_fork_child.
> 
>> +{
>> +  if (info_verbose || debug_infrun)
>> +    {
>> +      target_terminal_ours ();
> 
> We should really be using target_terminal_ours_for_output for
> output instead.
> 
>> +      fprintf_filtered (gdb_stdlog,
>> +			_("Attaching after process %d "
>> +			  "%s to child process %d.\n"),
>> +			parent_pid, is_vfork?"vfork":"fork", child_pid);
> 
> Spaces around "?" and ":":  'is_vfork ? "vfork" : "fork"'
> 
> 
>> +    }
>> +}
>> +
>> +/* Print details about detaching from a process after a fork call.  */
>> +
>> +static void
>> +print_fork_detach (pid_t pid, int is_parent, int is_vfork, char *vfork_action)
>> +{
>> +  if (info_verbose || debug_infrun)
>> +    {
>> +      target_terminal_ours ();
>> +
>> +      if (is_parent && is_vfork)
>> +	{
>> +	  /* Detaching a vfork parent, so print what the child did
>> +	     that allows the parent to resume.  */
>> +	  gdb_assert (vfork_action != NULL && strlen (vfork_action) > 0);
> 
> Write: '*vfork_action != '\0' instead of that strlen.
> 
>> +	  fprintf_filtered (gdb_stdlog,
>> +			    "Detaching vfork parent process %d after"
>> +			    " child %s.\n", pid, vfork_action);
> 
> This handling of vfork_action is bad for i18n.  While at it, this is
> missing _().  More below.
> 
>> +	}
>> +      else
>> +	{
>> +	  fprintf_filtered (gdb_stdlog,
>> +			    _("Detaching after %s from %s process %d.\n"),
>> +			    is_vfork?"vfork":"fork",
>> +			    is_parent?"parent":"child", pid);
> 
> Spaces around operators.  "parent" and "child" really shouldn't
> be passed as %s, as this will be awkward when translated.  We should
> split those out instead, like:
> 
> if (is_parent)
>   {
>      fprintf_filtered (gdb_stdlog,
> 		       _("Detaching after %s from parent process %d.\n"),
>                        is_vfork ? "vfork" : "fork", pid);
>   }
> else
>   {
>      fprintf_filtered (gdb_stdlog,
> 		       _("Detaching after %s from child process %d.\n"),
> 		       is_vfork ? "vfork" : "fork", pid);
>   }

Just so I understand (and don't repeat the error), is the problem here
that "parent" and "child" are (a) strings that would need to be
translated, and (b) not in the printf format string?

> 
> But after unrolling this, is there really any benefit to
> print_fork_detach?  It doesn't seem that it'll ever end
> up called twice with the same arguments...  Seems like
> we may be obfuscating more than clarifying with the patch.

My experience of reading and understanding the code was improved by
moving the blocks of printing code out of follow-fork.  So for me, it
would be desirable even with a print function for each permutation of
the messages.  But it's just a personal preference, so if you'd rather
just drop the whole patch, that's OK with me.  Let me know and I'll
either make the requested changes above, or re-work my local branch to
drop this patch.

Thanks for the review,
--Don

> 
> Thanks,
> Pedro Alves
>
  
Pedro Alves Oct. 15, 2014, 4:08 p.m. UTC | #3
On 09/26/2014 09:14 PM, Breazeal, Don wrote:
> On 9/26/2014 12:52 PM, Pedro Alves wrote:
>> On 08/21/2014 01:29 AM, Don Breazeal wrote:
>>> This patch refactors the code that prints messages related to follow-fork
>>> into functions, and adds a call so that a message is now printed when the
>>> parent process is detached.  Previously in this case the only message was
>>> notification of attaching to the child.  We still do not print any messages
>>> when following the parent and detaching the child (the default).  My 
>>> rationale for this is that from the user's perspective the new child was
>>> never attached.
>>>
>>> The messages now distinguish between fork and vfork.
>>>
>>> Note that all of these messages are only printed when 'verbose' is set or
>>> when debugging is turned on.
>>>
>>> This is preparatory work for follow-fork and detach-on-fork on
>>> extended-remote linux targets.
>>>
>>> The test gdb.base/foll-fork.exp was modified to check for the new message.
>>>
>>> Tested on x64 Ubuntu Lucid, native only.
>>>
>>> Thanks,
>>> --Don
>>>
>>> gdb/
>>> 2014-08-20  Don Breazeal  <donb@codesourcery.com>
>>>
>>> 	* gdb/infrun.c (print_fork_attach): New function.
>>> 	(print_fork_detach): New function.
>>> 	(follow_fork_inferior): Call print_fork_attach and print_fork_detach.
>>> 	(handle_vfork_child_exec_or_exit): Ditto.
>>>
>>> gdb/testsuite/
>>> 2014-08-20  Don Breazeal  <donb@codesourcery.com>
>>>
>>> 	* gdb.base/foll-fork.exp (test_follow_fork): Add check for new
>>> 	detach message.
>>> 	(catch_fork_child_follow): Ditto.
>>> 	* gdb.base/foll-vfork.exp (vfork_parent_follow_through_step):
>>> 	Modify to check for "vfork" instead of "fork".
>>> 	(vfork_parent_follow_to_bp): Ditto.
>>> 	(vfork_and_exec_child_follow_through_step): Ditto.
>>> 	(vfork_and_exec_child_follow_to_main_bp): Ditto, plus add check
>>> 	for new detach message.
>>>
>>> ---
>>>  gdb/infrun.c                          |   94 +++++++++++++++++++-------------
>>>  gdb/testsuite/gdb.base/foll-fork.exp  |   12 +++--
>>>  gdb/testsuite/gdb.base/foll-vfork.exp |    8 ++--
>>>  3 files changed, 68 insertions(+), 46 deletions(-)
>>>
>>> diff --git a/gdb/infrun.c b/gdb/infrun.c
>>> index a51c759..34e9295 100644
>>> --- a/gdb/infrun.c
>>> +++ b/gdb/infrun.c
>>> @@ -567,6 +567,49 @@ follow_fork (void)
>>>    return should_resume;
>>>  }
>>>  
>>> +/* Print details about attaching to a process after a fork call.  */
>>> +
>>> +static void
>>> +print_fork_attach (pid_t child_pid, pid_t parent_pid, int is_vfork)
>>
>> As this is called for the child only, I think it'd be good to make
>> that explicit in the name.  E.g., print_attach_fork_child.
>>
>>> +{
>>> +  if (info_verbose || debug_infrun)
>>> +    {
>>> +      target_terminal_ours ();
>>
>> We should really be using target_terminal_ours_for_output for
>> output instead.
>>
>>> +      fprintf_filtered (gdb_stdlog,
>>> +			_("Attaching after process %d "
>>> +			  "%s to child process %d.\n"),
>>> +			parent_pid, is_vfork?"vfork":"fork", child_pid);
>>
>> Spaces around "?" and ":":  'is_vfork ? "vfork" : "fork"'
>>
>>
>>> +    }
>>> +}
>>> +
>>> +/* Print details about detaching from a process after a fork call.  */
>>> +
>>> +static void
>>> +print_fork_detach (pid_t pid, int is_parent, int is_vfork, char *vfork_action)
>>> +{
>>> +  if (info_verbose || debug_infrun)
>>> +    {
>>> +      target_terminal_ours ();
>>> +
>>> +      if (is_parent && is_vfork)
>>> +	{
>>> +	  /* Detaching a vfork parent, so print what the child did
>>> +	     that allows the parent to resume.  */
>>> +	  gdb_assert (vfork_action != NULL && strlen (vfork_action) > 0);
>>
>> Write: '*vfork_action != '\0' instead of that strlen.
>>
>>> +	  fprintf_filtered (gdb_stdlog,
>>> +			    "Detaching vfork parent process %d after"
>>> +			    " child %s.\n", pid, vfork_action);
>>
>> This handling of vfork_action is bad for i18n.  While at it, this is
>> missing _().  More below.
>>
>>> +	}
>>> +      else
>>> +	{
>>> +	  fprintf_filtered (gdb_stdlog,
>>> +			    _("Detaching after %s from %s process %d.\n"),
>>> +			    is_vfork?"vfork":"fork",
>>> +			    is_parent?"parent":"child", pid);
>>
>> Spaces around operators.  "parent" and "child" really shouldn't
>> be passed as %s, as this will be awkward when translated.  We should
>> split those out instead, like:
>>
>> if (is_parent)
>>   {
>>      fprintf_filtered (gdb_stdlog,
>> 		       _("Detaching after %s from parent process %d.\n"),
>>                        is_vfork ? "vfork" : "fork", pid);
>>   }
>> else
>>   {
>>      fprintf_filtered (gdb_stdlog,
>> 		       _("Detaching after %s from child process %d.\n"),
>> 		       is_vfork ? "vfork" : "fork", pid);
>>   }
> 
> Just so I understand (and don't repeat the error), is the problem here
> that "parent" and "child" are (a) strings that would need to be
> translated, and (b) not in the printf format string?

Sorry, I saw wrongness in more places, and then picked the worst
example.  Still, there's no reason to assume that:

 1 - the best translation would put the child/parent word in the
     same position.
 2 - the translation for "parent" and "child" would be the same
     in all occurrences.

But a worse example is here:

+	  fprintf_filtered (gdb_stdlog,
+			    "Detaching vfork parent process %d after"
+			    " child %s.\n", pid, vfork_action);

vfork_action is either "exec" or "exit".  Here, when I try to figure
out how I'd translate this to Portuguese, I'd probably want
to translate the two sentences differently: I'd probably want to
translate "child exit" naturally (maybe "depois de o processo
filho terminar"), while "child exec" can't be translated so
directly: it'd probably need an auxiliary verb, something
like "depois do o processo filho chamar exec".
Where ".. chamar exec" means "... _called/calling_ exec".

> My experience of reading and understanding the code was improved by
> moving the blocks of printing code out of follow-fork.  So for me, it
> would be desirable even with a print function for each permutation of
> the messages.  But it's just a personal preference, so if you'd rather
> just drop the whole patch, that's OK with me.  Let me know and I'll
> either make the requested changes above, or re-work my local branch to
> drop this patch.

Sorry, I still don't think you're new patch (sent as follow up) is
an improvement...  Having to explain the "Hardcoded 1's" in a
comment is a red sign to me.  :-/

Could you do a patch that just adds the missing output, and fixes
fork/vfork without moving the printing code to a separate function?
For the fork vs vfork issue, doing ' is_vfork ? "vfork" : "fork" ' is
fine.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/infrun.c b/gdb/infrun.c
index a51c759..34e9295 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -567,6 +567,49 @@  follow_fork (void)
   return should_resume;
 }
 
+/* Print details about attaching to a process after a fork call.  */
+
+static void
+print_fork_attach (pid_t child_pid, pid_t parent_pid, int is_vfork)
+{
+  if (info_verbose || debug_infrun)
+    {
+      target_terminal_ours ();
+      fprintf_filtered (gdb_stdlog,
+			_("Attaching after process %d "
+			  "%s to child process %d.\n"),
+			parent_pid, is_vfork?"vfork":"fork", child_pid);
+    }
+}
+
+/* Print details about detaching from a process after a fork call.  */
+
+static void
+print_fork_detach (pid_t pid, int is_parent, int is_vfork, char *vfork_action)
+{
+  if (info_verbose || debug_infrun)
+    {
+      target_terminal_ours ();
+
+      if (is_parent && is_vfork)
+	{
+	  /* Detaching a vfork parent, so print what the child did
+	     that allows the parent to resume.  */
+	  gdb_assert (vfork_action != NULL && strlen (vfork_action) > 0);
+	  fprintf_filtered (gdb_stdlog,
+			    "Detaching vfork parent process %d after"
+			    " child %s.\n", pid, vfork_action);
+	}
+      else
+	{
+	  fprintf_filtered (gdb_stdlog,
+			    _("Detaching after %s from %s process %d.\n"),
+			    is_vfork?"vfork":"fork",
+			    is_parent?"parent":"child", pid);
+	}
+    }
+}
+
 /* Handle changes to the inferior list based on the type of fork,
    which process is being followed, and whether the other process
    should be detached.  */
@@ -623,14 +666,7 @@  holding the child stopped.  Try \"set detach-on-fork\" or \
 	      remove_breakpoints_pid (ptid_get_pid (inferior_ptid));
 	    }
 
-	  if (info_verbose || debug_infrun)
-	    {
-	      target_terminal_ours ();
-	      fprintf_filtered (gdb_stdlog,
-				"Detaching after fork from "
-				"child process %d.\n",
-				child_pid);
-	    }
+	  print_fork_detach (child_pid, follow_child, has_vforked, "");
 	}
       else
 	{
@@ -711,20 +747,7 @@  holding the child stopped.  Try \"set detach-on-fork\" or \
       struct inferior *parent_inf, *child_inf;
       struct program_space *parent_pspace;
 
-      if (info_verbose || debug_infrun)
-	{
-	  target_terminal_ours ();
-	  if (has_vforked)
-	    fprintf_filtered (gdb_stdlog,
-			      _("Attaching after process %d "
-				"vfork to child process %d.\n"),
-			      parent_pid, child_pid);
-	  else
-	    fprintf_filtered (gdb_stdlog,
-			      _("Attaching after process %d "
-				"fork to child process %d.\n"),
-			      parent_pid, child_pid);
-	}
+      print_fork_attach (child_pid, parent_pid, has_vforked);
 
       /* Add the new inferior first, so that the target_detach below
 	 doesn't unpush the target.  */
@@ -760,7 +783,10 @@  holding the child stopped.  Try \"set detach-on-fork\" or \
 	  parent_inf->waiting_for_vfork_done = 0;
 	}
       else if (detach_fork)
-	target_detach (NULL, 0);
+	{
+	  print_fork_detach (parent_pid, follow_child, has_vforked, "");
+	  target_detach (NULL, 0);
+	}
 
       /* Note that the detach above makes PARENT_INF dangling.  */
 
@@ -927,21 +953,13 @@  handle_vfork_child_exec_or_exit (int exec)
 	  inf->aspace = NULL;
 	  inf->pspace = NULL;
 
-	  if (debug_infrun || info_verbose)
-	    {
-	      target_terminal_ours ();
-
-	      if (exec)
-		fprintf_filtered (gdb_stdlog,
-				  "Detaching vfork parent process "
-				  "%d after child exec.\n",
-				  inf->vfork_parent->pid);
-	      else
-		fprintf_filtered (gdb_stdlog,
-				  "Detaching vfork parent process "
-				  "%d after child exit.\n",
-				  inf->vfork_parent->pid);
-	    }
+	  /* Print verbose/debug info message.  Hardcoded 1's designate
+	     that we are detaching a parent and that it is after a vfork,
+	     respectively.  */
+	  if (exec)
+	    print_fork_detach (inf->vfork_parent->pid, 1, 1, "exec");
+	  else
+	    print_fork_detach (inf->vfork_parent->pid, 1, 1, "exit");
 
 	  target_detach (NULL, 0);
 
diff --git a/gdb/testsuite/gdb.base/foll-fork.exp b/gdb/testsuite/gdb.base/foll-fork.exp
index ad8b750..06ba1b5 100644
--- a/gdb/testsuite/gdb.base/foll-fork.exp
+++ b/gdb/testsuite/gdb.base/foll-fork.exp
@@ -115,7 +115,11 @@  proc test_follow_fork { who detach cmd } {
 	# Set up the output we expect to see after we run.
 	set expected_re ""
 	if {$who == "child"} {
-	    set expected_re "Attaching after.* fork to.*set breakpoint here.*"
+	    set expected_re "Attaching after.* fork to.*"
+	    if {$detach == "on"} {
+	        append expected_re "Detaching after fork from .*"
+	    }
+	    append expected_re "set breakpoint here.*"
 	} elseif {$who == "parent" && $detach == "on"} {
 	    set expected_re "Detaching after fork from .*set breakpoint here.*"
 	} else {
@@ -218,9 +222,9 @@  proc catch_fork_child_follow {} {
 	"Temporary breakpoint.*, line $bp_after_fork.*" \
 	"set follow-fork child, tbreak"
 
-    gdb_test "continue" \
-	"Attaching after.* fork to.* at .*$bp_after_fork.*" \
-	"set follow-fork child, hit tbreak"
+    set expected_re "Attaching after.* fork to.*Detaching after fork from"
+    append expected_re " .* at .*$bp_after_fork.*"
+    gdb_test "continue" $expected_re "set follow-fork child, hit tbreak"
 
     # The parent has been detached; allow time for any output it might
     # generate to arrive, so that output doesn't get confused with
diff --git a/gdb/testsuite/gdb.base/foll-vfork.exp b/gdb/testsuite/gdb.base/foll-vfork.exp
index fe3663c..968db13 100644
--- a/gdb/testsuite/gdb.base/foll-vfork.exp
+++ b/gdb/testsuite/gdb.base/foll-vfork.exp
@@ -121,7 +121,7 @@  proc vfork_parent_follow_through_step {} {
 
    set test "step"
    gdb_test_multiple "next" $test {
-       -re "Detaching after fork from.*if \\(pid == 0\\).*$gdb_prompt " {
+       -re "Detaching after vfork from.*if \\(pid == 0\\).*$gdb_prompt " {
 	   pass $test
        }
    }
@@ -146,7 +146,7 @@  proc vfork_parent_follow_to_bp {} {
 
    set test "continue to bp"
    gdb_test_multiple "continue" $test {
-       -re ".*Detaching after fork from child process.*Breakpoint.*${bp_location}.*$gdb_prompt " {
+       -re ".*Detaching after vfork from child process.*Breakpoint.*${bp_location}.*$gdb_prompt " {
 	   pass $test
        }
    }
@@ -195,7 +195,7 @@  proc vfork_and_exec_child_follow_to_main_bp {} {
 
    set test "continue to bp"
    gdb_test_multiple "continue" $test {
-      -re "Attaching after.* vfork to.*xecuting new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " {
+      -re "Attaching after.* vfork to.*Detaching vfork parent.*xecuting new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " {
 	  pass $test
       }
    }
@@ -239,7 +239,7 @@  proc vfork_and_exec_child_follow_through_step {} {
        #
        set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
        gdb_test_multiple "next" $test {
-	   -re "Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " {
+	   -re "Attaching after vfork to.*Executing new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " {
 	       pass "$test"
 	   }
        }