Blob Blame History Raw
Index: rhel-7.8/gdb-7.6.1/gdb/inf-ttrace.c
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/inf-ttrace.c
+++ rhel-7.8/gdb-7.6.1/gdb/inf-ttrace.c
@@ -459,10 +459,14 @@ inf_ttrace_follow_fork (struct target_op
       copy_terminal_info (inf, parent_inf);
       detach_breakpoints (ptid_build (pid, lwpid, 0));
 
-      target_terminal_ours ();
-      fprintf_unfiltered (gdb_stdlog,
-			  _("Attaching after fork to child process %ld.\n"),
-			  (long)fpid);
+      if (print_inferior_events)
+	{
+	  target_terminal_ours ();
+	  fprintf_unfiltered (gdb_stdlog,
+			      _("[Attaching after %s fork to child %s]\n"),
+			      target_pid_to_str (pid_to_ptid (pid)),
+			      target_pid_to_str (pid_to_ptid (fid)));
+	}
     }
   else
     {
@@ -473,10 +477,13 @@ inf_ttrace_follow_fork (struct target_op
       if (tts.tts_event == TTEVT_VFORK)
 	detach_breakpoints (ptid_build (fpid, flwpid, 0));
 
-      target_terminal_ours ();
-      fprintf_unfiltered (gdb_stdlog,
-			  _("Detaching after fork from child process %ld.\n"),
-			  (long)fpid);
+      if (print_inferior_events)
+	{
+	  target_terminal_ours ();
+	  fprintf_unfiltered (gdb_stdlog,
+			      _("[Detaching after fork from child %s]\n"),
+			      target_pid_to_str (pid_to_ptid (fpid)));
+	}
     }
 
   if (tts.tts_event == TTEVT_VFORK)
Index: rhel-7.8/gdb-7.6.1/gdb/infcmd.c
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/infcmd.c
+++ rhel-7.8/gdb-7.6.1/gdb/infcmd.c
@@ -2326,6 +2326,9 @@ vector_info (char *args, int from_tty)
 static void
 kill_command (char *arg, int from_tty)
 {
+  const char *pid_str;
+  int infnum, pid;
+
   /* FIXME:  This should not really be inferior_ptid (or target_has_execution).
      It should be a distinct flag that indicates that a target is active, cuz
      some targets don't have processes!  */
@@ -2334,8 +2337,19 @@ kill_command (char *arg, int from_tty)
     error (_("The program is not being run."));
   if (!query (_("Kill the program being debugged? ")))
     error (_("Not confirmed."));
+
+  pid = current_inferior ()->pid;
+  /* Save the pid as a string before killing the inferior, since that
+     may unpush the current target, and we need the string after.  */
+  pid_str = target_pid_to_str (pid_to_ptid (pid));
+  infnum = current_inferior ()->num;
+
   target_kill ();
 
+  if (print_inferior_events)
+    printf_unfiltered (_("[Inferior %d (%s) killed]\n"),
+		       infnum, pid_str);
+
   /* If we still have other inferiors to debug, then don't mess with
      with their threads.  */
   if (!have_inferiors ())
Index: rhel-7.8/gdb-7.6.1/gdb/inferior.c
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/inferior.c
+++ rhel-7.8/gdb-7.6.1/gdb/inferior.c
@@ -46,9 +46,8 @@ DEFINE_REGISTRY (inferior, REGISTRY_ACCE
 struct inferior *inferior_list = NULL;
 static int highest_inferior_num;
 
-/* Print notices on inferior events (attach, detach, etc.), set with
-   `set print inferior-events'.  */
-static int print_inferior_events = 0;
+/* See inferior.h.  */
+int print_inferior_events = 1;
 
 /* The Current Inferior.  */
 static struct inferior *current_inferior_ = NULL;
@@ -157,7 +156,9 @@ add_inferior (int pid)
   struct inferior *inf = add_inferior_silent (pid);
 
   if (print_inferior_events)
-    printf_unfiltered (_("[New inferior %d]\n"), pid);
+    printf_unfiltered (_("[New inferior %d (%s)]\n"), 
+		       inf->num,
+		       target_pid_to_str (pid_to_ptid (pid)));
 
   return inf;
 }
@@ -286,9 +287,6 @@ exit_inferior (int pid)
   struct inferior *inf = find_inferior_pid (pid);
 
   exit_inferior_1 (inf, 0);
-
-  if (print_inferior_events)
-    printf_unfiltered (_("[Inferior %d exited]\n"), pid);
 }
 
 void
@@ -315,7 +313,9 @@ detach_inferior (int pid)
   exit_inferior_1 (inf, 1);
 
   if (print_inferior_events)
-    printf_unfiltered (_("[Inferior %d detached]\n"), pid);
+    printf_unfiltered (_("[Inferior %d (%s) detached]\n"),
+		       inf->num,
+		       target_pid_to_str (pid_to_ptid (pid)));
 }
 
 void
@@ -991,7 +991,7 @@ initialize_inferiors (void)
      can only allocate an inferior when all those modules have done
      that.  Do this after initialize_progspace, due to the
      current_program_space reference.  */
-  current_inferior_ = add_inferior (0);
+  current_inferior_ = add_inferior_silent (0);
   current_inferior_->pspace = current_program_space;
   current_inferior_->aspace = current_program_space->aspace;
   /* The architecture will be initialized shortly, by
Index: rhel-7.8/gdb-7.6.1/gdb/inferior.h
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/inferior.h
+++ rhel-7.8/gdb-7.6.1/gdb/inferior.h
@@ -277,6 +277,10 @@ extern enum stop_stack_kind stop_stack_d
 
 extern int stopped_by_random_signal;
 
+/* Print notices on inferior events (attach, detach, etc.), set with
+   `set print inferior-events'.  */
+extern int print_inferior_events;
+
 /* STEP_OVER_ALL means step over all subroutine calls.
    STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions.
    STEP_OVER_NONE means don't step over any subroutine calls.  */
Index: rhel-7.8/gdb-7.6.1/gdb/infrun.c
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/infrun.c
+++ rhel-7.8/gdb-7.6.1/gdb/infrun.c
@@ -718,20 +718,21 @@ handle_vfork_child_exec_or_exit (int exe
 	  inf->aspace = NULL;
 	  inf->pspace = NULL;
 
-	  if (debug_infrun || info_verbose)
+	  if (print_inferior_events)
 	    {
+	      const char *pidstr
+		= target_pid_to_str (pid_to_ptid (inf->vfork_parent->pid));
+
 	      target_terminal_ours ();
 
 	      if (exec)
 		fprintf_filtered (gdb_stdlog,
-				  "Detaching vfork parent process "
-				  "%d after child exec.\n",
-				  inf->vfork_parent->pid);
+				  "[Detaching vfork parent %s "
+				  "after child exec]\n", pidstr);
 	      else
 		fprintf_filtered (gdb_stdlog,
-				  "Detaching vfork parent process "
-				  "%d after child exit.\n",
-				  inf->vfork_parent->pid);
+				  "[Detaching vfork parent %s "
+				  "after child exit]\n", pidstr);
 	    }
 
 	  target_detach (NULL, 0);
@@ -3260,7 +3261,7 @@ handle_inferior_event (struct execution_
       ecs->event_thread = find_thread_ptid (ecs->ptid);
       /* If it's a new thread, add it to the thread database.  */
       if (ecs->event_thread == NULL)
-	ecs->event_thread = add_thread (ecs->ptid);
+	ecs->event_thread = add_thread (ecs->ptid); /* !!keiths: _silent? */
     }
 
   /* Dependent on valid ECS->EVENT_THREAD.  */
Index: rhel-7.8/gdb-7.6.1/gdb/linux-nat.c
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/linux-nat.c
+++ rhel-7.8/gdb-7.6.1/gdb/linux-nat.c
@@ -688,13 +688,13 @@ holding the child stopped.  Try \"set de
 	      remove_breakpoints_pid (GET_PID (inferior_ptid));
 	    }
 
-	  if (info_verbose || debug_linux_nat)
+	  if (print_inferior_events)
 	    {
 	      target_terminal_ours ();
 	      fprintf_filtered (gdb_stdlog,
-				"Detaching after fork from "
-				"child process %d.\n",
-				child_pid);
+				"[Detaching after %s from child %s]\n",
+				has_vforked ? "vfork" : "fork",
+				target_pid_to_str (pid_to_ptid (child_pid)));
 	    }
 
 	  old_chain = save_inferior_ptid ();
@@ -729,7 +729,7 @@ holding the child stopped.  Try \"set de
 	  save_current_program_space ();
 
 	  inferior_ptid = ptid_build (child_pid, child_pid, 0);
-	  add_thread (inferior_ptid);
+	  add_thread_silent (inferior_ptid);
 	  child_lp = add_lwp (inferior_ptid);
 	  child_lp->stopped = 1;
 	  child_lp->last_resume_kind = resume_stop;
@@ -865,19 +865,19 @@ holding the child stopped.  Try \"set de
       struct lwp_info *child_lp;
       struct program_space *parent_pspace;
 
-      if (info_verbose || debug_linux_nat)
+      if (print_inferior_events)
 	{
+	  const char *parent_pidstr
+	    = target_pid_to_str (pid_to_ptid (parent_pid));
+	  const char *child_pidstr
+	    = target_pid_to_str (pid_to_ptid (child_pid));
+
 	  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);
+	  fprintf_filtered (gdb_stdlog,
+			    _("[Attaching after %s %s to child %s]\n"),
+			    parent_pidstr,
+			    has_vforked ? "vfork" : "fork",
+			    child_pidstr);
 	}
 
       /* Add the new inferior first, so that the target_detach below
@@ -914,7 +914,21 @@ holding the child stopped.  Try \"set de
 	  parent_inf->waiting_for_vfork_done = 0;
 	}
       else if (detach_fork)
-	target_detach (NULL, 0);
+	{
+	  if (print_inferior_events)
+            {
+              /* Ensure that we have a process ptid.  */
+              ptid_t process_ptid = pid_to_ptid (parent_pid);
+
+              target_terminal_ours ();
+              fprintf_filtered (gdb_stdlog,
+                                _("[Detaching after fork from "
+                                  "parent %s]\n"),
+                                target_pid_to_str (process_ptid));
+            }
+
+	  target_detach (NULL, 0);
+	}
 
       /* Note that the detach above makes PARENT_INF dangling.  */
 
@@ -923,7 +937,7 @@ holding the child stopped.  Try \"set de
 	 informing the solib layer about this new process.  */
 
       inferior_ptid = ptid_build (child_pid, child_pid, 0);
-      add_thread (inferior_ptid);
+      add_thread_silent (inferior_ptid);
       child_lp = add_lwp (inferior_ptid);
       child_lp->stopped = 1;
       child_lp->last_resume_kind = resume_stop;
Index: rhel-7.8/gdb-7.6.1/gdb/remote.c
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/remote.c
+++ rhel-7.8/gdb-7.6.1/gdb/remote.c
@@ -4437,7 +4437,17 @@ remote_detach_1 (char *args, int from_tt
   if (from_tty && !extended)
     puts_filtered (_("Ending remote debugging.\n"));
 
-  target_mourn_inferior ();
+  {
+    /* Save the pid as a string before mourning, since that will
+       unpush the remote target, and we need the string after.  */
+    const char *infpid = target_pid_to_str (pid_to_ptid (pid));
+    struct inferior *inf = find_inferior_pid (pid);
+
+    target_mourn_inferior ();
+    if (print_inferior_events)
+      printf_unfiltered (_("[Inferior %d (%s) detached]\n"),
+			 inf->num, infpid);
+  }
 }
 
 static void
Index: rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/attach.exp
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/testsuite/gdb.base/attach.exp
+++ rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/attach.exp
@@ -70,6 +70,7 @@ proc do_attach_tests {} {
     global objdir
     global subdir
     global timeout
+    global decimal
     
     # Start the program running and then wait for a bit, to be sure
     # that it can be attached to.
@@ -203,7 +204,7 @@ proc do_attach_tests {} {
     # Detach the process.
    
     gdb_test "detach" \
-	"Detaching from program: .*$escapedbinfile, process $testpid" \
+	"Detaching from program: .*$escapedbinfile, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]" \
 	"attach1 detach"
 
     # Wait a bit for gdb to finish detaching
Index: rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/catch-syscall.exp
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/testsuite/gdb.base/catch-syscall.exp
+++ rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/catch-syscall.exp
@@ -164,7 +164,7 @@ proc check_for_program_end {} {
     # Deleting the catchpoints
     delete_breakpoints
 
-    gdb_continue_to_end
+    gdb_continue_to_end "" continue 1
 
 }
 
@@ -228,7 +228,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
 }
 
 proc test_catch_syscall_restarting_inferior {} {
Index: rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/foll-fork.exp
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/testsuite/gdb.base/foll-fork.exp
+++ rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/foll-fork.exp
@@ -64,7 +64,7 @@ proc default_fork_parent_follow {} {
 	"default show parent follow, no catchpoints"
 
     gdb_test "next 2" \
-	"Detaching after fork from.*" \
+	"\\\[Detaching after fork from.*" \
 	"default parent follow, no catchpoints"
 
     # The child has been detached; allow time for any output it might
@@ -83,7 +83,7 @@ proc explicit_fork_parent_follow {} {
 	"Debugger response to a program call of fork or vfork is \"parent\"." \
 	"explicit show parent follow, no catchpoints"
 
-    gdb_test "next 2" "Detaching after fork from.*" \
+    gdb_test "next 2" "\\\[Detaching after fork from.*" \
 	"explicit parent follow, no catchpoints"
 
     # The child has been detached; allow time for any output it might
@@ -102,7 +102,7 @@ proc explicit_fork_child_follow {} {
 	"Debugger response to a program call of fork or vfork is \"child\"." \
 	"explicit show child follow, no catchpoints"
 
-    gdb_test "next 2" "Attaching after.* fork to.*" \
+    gdb_test "next 2" "\\\[Attaching after.* fork to.*" \
 	"explicit child follow, no catchpoints"
 
     # The child has been detached; allow time for any output it might
@@ -152,7 +152,7 @@ proc catch_fork_child_follow {} {
 	"set follow-fork child, tbreak"
 
     gdb_test "continue" \
-	"Attaching after.* fork to.* at .*$bp_after_fork.*" \
+	"\\\[Attaching after.* fork to.* at .*$bp_after_fork.*" \
 	"set follow-fork child, hit tbreak"
 
     # The parent has been detached; allow time for any output it might
@@ -239,7 +239,7 @@ proc tcatch_fork_parent_follow {} {
 	"set follow-fork parent, tbreak"
 
     gdb_test "continue" \
-	"Detaching after fork from.* at .*$bp_after_fork.*" \
+	"\\\[Detaching after fork from.* at .*$bp_after_fork.*" \
 	"set follow-fork parent, hit tbreak"
 
     # The child has been detached; allow time for any output it might
@@ -338,10 +338,6 @@ gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
 
-# The "Detaching..." and "Attaching..." messages may be hidden by
-# default.
-gdb_test_no_output "set verbose"
-
 # This is a test of gdb's ability to follow the parent, child or both
 # parent and child of a Unix fork() system call.
 #
Index: rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/foll-vfork.exp
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/testsuite/gdb.base/foll-vfork.exp
+++ rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/foll-vfork.exp
@@ -73,10 +73,6 @@ proc setup_gdb {} {
 
     clean_restart $testfile
 
-    # The "Detaching..." and "Attaching..." messages may be hidden by
-    # default.
-    gdb_test_no_output "set verbose"
-
     if ![runto_main] {
 	return -code return
     }
@@ -117,7 +113,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
        }
    }
@@ -142,7 +138,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
        }
    }
@@ -167,7 +163,7 @@ proc vfork_child_follow_to_exit {} {
 	  # PR gdb/14766
 	  fail "$test"
       }
-      -re "Attaching after.* vfork to.*Detaching vfork parent .* after child exit.*$gdb_prompt " {
+       -re "\\\[Attaching after.* vfork to.*\\\[Detaching vfork parent .* after child exit.*$gdb_prompt " {
 	  pass $test
       }
    }
@@ -191,7 +187,8 @@ proc vfork_and_exec_child_follow_to_main
 
    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
       }
    }
@@ -235,7 +232,7 @@ proc vfork_and_exec_child_follow_through
        #
        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 fork to.*Executing new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " {
 	       pass "$test"
 	   }
        }
@@ -244,7 +241,7 @@ proc vfork_and_exec_child_follow_through
        # before it execs.  Thus, "next" lands on the next line after
        # the vfork.
        gdb_test_multiple "next" $test {
-	   -re "Attaching after .* vfork to child.*if \\(pid == 0\\).*$gdb_prompt " {
+	   -re "\\\[Attaching after .* vfork to child.*if \\(pid == 0\\).*$gdb_prompt " {
 	       pass "$test"
 	   }
        }
@@ -398,7 +395,7 @@ proc vfork_relations_in_info_inferiors {
 
    set test "step over vfork"
    gdb_test_multiple "next" $test {
-       -re "Attaching after .* vfork to child.*if \\(pid == 0\\).*$gdb_prompt " {
+       -re "\\\[Attaching after .* vfork to child.*if \\(pid == 0\\).*$gdb_prompt " {
 	   pass "$test"
        }
    }
Index: rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/fork-print-inferior-events.c
===================================================================
--- /dev/null
+++ rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/fork-print-inferior-events.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;
+}
Index: rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/fork-print-inferior-events.exp
===================================================================
--- /dev/null
+++ rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/fork-print-inferior-events.exp
@@ -0,0 +1,96 @@
+# 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/>.
+
+# Test that the event messages printed when using 'set print
+# inferior-events [on,off]', 'set follow-fork-mode [child,parent]' and
+# 'set detach-on-fork [on,off]' are the correct ones.
+
+# This test relies on "run", so it cannot run on target remote stubs.
+if { [use_gdb_stub] } {
+    untested "not supported on target remote stubs"
+    return
+}
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } {
+    return -1
+}
+
+# RHEL7 GDB lacks the unified remote/native fork handling code,
+# so we don't get event notifications for remote targets.
+# Skip the "on" case of print inferior-events.
+set using_remote 0
+if {[target_info gdb_protocol] == "extended-remote"} {
+    set using_remote 1
+}
+
+# This is the expected output for each of the test combinations
+# below.  The order here is important:
+#
+#    inferior-events: on;  follow-fork: child;  detach-on-fork: on
+#    inferior-events: on;  follow-fork: child;  detach-on-fork: off
+#    inferior-events: on;  follow-fork: parent; detach-on-fork: on
+#    inferior-events: on;  follow-fork: parent; detach-on-fork: off
+#    inferior-events: off; follow-fork: child;  detach-on-fork: on
+#    inferior-events: off; follow-fork: child;  detach-on-fork: off
+#    inferior-events: off; follow-fork: parent; detach-on-fork: on
+#    inferior-events: off; follow-fork: parent; detach-on-fork: off
+
+set reading_re "(Reading.*from remote target\\.\\.\\.\r\n)*"
+set exited_normally_re "${reading_re}\\\[Inferior $decimal \\(.*\\) exited normally\\\]"
+# gdbserver produces a slightly different message when attaching after
+# a fork, so we have to tweak the regexp to accomodate that.
+set attach_child_re "${reading_re}\\\[Attaching after .* fork to child .*\\\]\r\n"
+set detach_child_re "${reading_re}\\\[Detaching after fork from child .*\\\]\r\n"
+set detach_parent_re "${reading_re}\\\[Detaching after fork from parent .*\\\]\r\n"
+set new_inf_re "${reading_re}\\\[New inferior $decimal \\(.*\\)\\\]\r\n"
+set inf_detached_re "${reading_re}\\\[Inferior $decimal \\(.*\\) detached\\\]\r\n"
+
+set expected_output [list \
+                        "${attach_child_re}${new_inf_re}${detach_parent_re}${inf_detached_re}" \
+                        "${attach_child_re}${new_inf_re}" \
+                        "${detach_child_re}" \
+                        "${new_inf_re}" \
+                        "" \
+                        "" \
+                        "" \
+                        "" \
+                       ]
+
+set i 0
+
+foreach_with_prefix print_inferior_events { "on" "off" } {
+    foreach_with_prefix follow_fork_mode { "child" "parent" } {
+       foreach_with_prefix detach_on_fork { "on" "off" } {
+           clean_restart $binfile
+           gdb_test_no_output "set print inferior-events $print_inferior_events"
+           gdb_test_no_output "set follow-fork-mode $follow_fork_mode"
+           gdb_test_no_output "set detach-on-fork $detach_on_fork"
+
+           set output [lindex $expected_output $i]
+           # Always add the "Starting program..." string so that we
+           # match exactly the lines we want.
+           set output "Starting program: $binfile\\s*\r\n${output}${exited_normally_re}"
+           set i [expr $i + 1]
+	   if {$using_remote && $print_inferior_events == "on"} {
+	       continue
+	   }
+	   gdb_test "run" $output
+       }
+    }
+}
Index: rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/kill-after-signal.exp
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/testsuite/gdb.base/kill-after-signal.exp
+++ rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/kill-after-signal.exp
@@ -37,4 +37,8 @@ if ![runto_main] {
 
 gdb_test "continue" "Program received signal SIGUSR1, .*"
 gdb_test "stepi" "\r\nhandler .*"
-gdb_test "kill" "^y" "kill" "Kill the program being debugged\\? \\(y or n\\) $" "y"
+gdb_test_multiple "kill" "kill" {
+    -re "Kill the program being debugged\\? \\(y or n\\) $" {
+       gdb_test "y" "\\\[Inferior $decimal \\(.*\\) killed\\\]" "kill"
+    }
+}
Index: rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/solib-overlap.exp
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/testsuite/gdb.base/solib-overlap.exp
+++ rhel-7.8/gdb-7.6.1/gdb/testsuite/gdb.base/solib-overlap.exp
@@ -127,7 +127,7 @@ foreach prelink_lib1 {0x40000000 0x50000
 
     # Detach the process.
 
-    gdb_test "detach" "Detaching from program: .*$escapedbinfile, process $testpid"
+    gdb_test "detach" "Detaching from program: .*$escapedbinfile, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
 
     # Wait a bit for gdb to finish detaching
 
Index: rhel-7.8/gdb-7.6.1/gdb/testsuite/lib/gdb.exp
===================================================================
--- rhel-7.8.orig/gdb-7.6.1/gdb/testsuite/lib/gdb.exp
+++ rhel-7.8/gdb-7.6.1/gdb/testsuite/lib/gdb.exp
@@ -1738,6 +1738,27 @@ proc with_test_prefix { prefix body } {
   }
 }
 
+# Wrapper for foreach that calls with_test_prefix on each iteration,
+# including the iterator's name and current value in the prefix.
+
+proc foreach_with_prefix {var list body} {
+    upvar 1 $var myvar
+    foreach myvar $list {
+        with_test_prefix "$var=$myvar" {
+            set code [catch {uplevel 1 $body} result]
+        }
+
+        if {$code == 1} {
+            global errorInfo errorCode
+            return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
+        } elseif {$code == 3} {
+            break
+        } elseif {$code == 2} {
+            return -code $code $result
+        }
+    }
+}
+
 # Return 1 if _Complex types are supported, otherwise, return 0.
 
 proc support_complex_tests {} {
@@ -2354,6 +2375,26 @@ proc skip_unwinder_tests {} {
     return $ok
 }
 
+# Return the effective value of use_gdb_stub.
+#
+# If the use_gdb_stub global has been set (it is set when the gdb process is
+# spawned), return that.  Otherwise, return the value of the use_gdb_stub
+# property from the board file.
+#
+# This is the preferred way of checking use_gdb_stub, since it allows to check
+# the value before the gdb has been spawned and it will return the correct value
+# even when it was overriden by the test.
+
+proc use_gdb_stub {} {
+  global use_gdb_stub
+
+  if [info exists use_gdb_stub] {
+     return $use_gdb_stub
+  }
+
+  return [target_info exists use_gdb_stub]
+}
+
 set compiler_info		"unknown"
 set gcc_compiled		0
 set hp_cc_compiler		0