rpms/gdb/devel gdb-orphanripper.c, NONE, 1.1 gdb-6.5-attach-stop.patch, 1.1, 1.2 gdb.spec, 1.208, 1.209

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Tue Dec 12 22:16:23 UTC 2006


Author: jkratoch

Update of /cvs/dist/rpms/gdb/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv22174

Modified Files:
	gdb-6.5-attach-stop.patch gdb.spec 
Added Files:
	gdb-orphanripper.c 
Log Message:
* Tue Dec 12 2006 Jan Kratochvil <jan.kratochvil at redhat.com> - 6.5-19
- Fix attachment also to a threaded stopped process (BZ 219118).
- Cleanup any leftover testsuite processes as it may stuck mock(1) builds.
- Resolves: rhbz#219118



--- NEW FILE gdb-orphanripper.c ---
/*
 * Copyright 2006 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Reap any leftover children possibly holding file descriptors.
 * 2006-12-12  Jan Kratochvil  <jan.kratochvil at redhat.com>
 */


#define _XOPEN_SOURCE 1
#define _XOPEN_SOURCE_EXTENDED 1
#define _BSD_SOURCE 1

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>


static const char *progname;

static int spawn (char **argv, pid_t *child_pointer)
{
	pid_t child, child_got;
	int status;

	switch (child = fork ()) {
	case -1:
		perror ("fork(2)");
		exit (EXIT_FAILURE);
	case 0:
		/* Do not setpgrp(2) in the parent process as the process-group
		   is shared for the whole sh(1) pipeline we could be a part
		   of.  The process-group is set according to PID of the first
		   command in the pipeline.
		   We would rip even vi(1) in the case of:
		   	./orphanripper sh -c 'sleep 1&' | vi -
		   */
		/* Do not setpgrp(2) as our pty would not be ours and we would
		   get `SIGSTOP' later, particularly after spawning gdb(1).  */
		if (getpid() != setsid ()) {
			perror ("setsid");
			exit (EXIT_FAILURE);
		}
		execvp (argv[1], argv + 1);
		perror ("execvp(2)");
		exit (EXIT_FAILURE);
	default:
		break;
	}
	if (child != (child_got = waitpid (child, &status, 0))) {
		fprintf (stderr, "waitpid(%d)=%d: %m\n", (int) child,
			 (int) child_got);
		exit (EXIT_FAILURE);
	}
	if (!WIFEXITED (status)) {
		fprintf (stderr, "waitpid(2): !WIFEXITED(%d)\n", status);
		exit (EXIT_FAILURE);
	}

	if (child_pointer)
		*child_pointer = child;
	return WEXITSTATUS (status);
}

/* Detected commandline may look weird due to a race:
   Original command:
   	./orphanripper sh -c 'sleep 1&' &
   Correct output:
   	[1] 29610
   	./orphanripper: Killed -9 orphan PID 29612 (PGID 29611): sleep 1
   Raced output (sh(1) child still did not update its argv[]):
   	[1] 29613
   	./orphanripper: Killed -9 orphan PID 29615 (PGID 29614): sh -c sleep 1&
   We could delay a bit before ripping the children.  */
static const char *read_cmdline (pid_t pid)
{
	char cmdline_fname[32];
	static char cmdline[LINE_MAX];
	int fd;
	ssize_t got;
	char *s;

	if (snprintf (cmdline_fname, sizeof (cmdline_fname), "/proc/%d/cmdline",
		  (int) pid) < 0)
		return NULL;
	fd = open (cmdline_fname, O_RDONLY);
	if (fd == -1) {
		fprintf (stderr, "%s: open (\"%s\"): %m\n", progname,
			 cmdline_fname);
		return NULL;
	}
	got = read (fd, cmdline, sizeof (cmdline) - 1);
	if (got == -1)
		fprintf (stderr, "%s: read (\"%s\"): %m\n", progname,
			 cmdline_fname);
	if (close (fd))
		fprintf (stderr, "%s: close (\"%s\"): %m\n", progname,
			 cmdline_fname);
	if (got < 0)
		return NULL;
	/* Convert '\0' argument delimiters to spaces.  */
	for (s = cmdline; s < cmdline + got; s++)
		if (!*s)
			*s = ' ';
	/* Trim the trailing spaces (typically single '\0'->' ').  */
	while (s > cmdline && isspace (s[-1]))
		s--;
	*s = 0;
	return cmdline;
}

static void rip_pid (pid_t pid, pid_t pgid_child)
{
	pid_t pgid_pids;
	const char *cmdline;

	/* Don't shoot ourselves.  */
	if (pid == getpid())
		return;
	pgid_pids = getpgid (pid);
	/* Ignore errors (permissions? untested).  */
	if (pgid_pids == -1)
		return;
	/* Not a process of ours.  */
	if (pgid_pids != pgid_child)
		return;

	cmdline = read_cmdline (pid);
	if (!cmdline)
		cmdline = "<error>";
	fprintf (stderr, "%s: Killed -9 orphan PID %d (PGID %d): %s\n",
	         progname, (int) pid, (int) pgid_pids, cmdline);
	if (kill (pid, SIGKILL)) {
		fprintf (stderr, "%s: kill (%d, SIGKILL): %m\n", progname,
			 (int) pid);
		return;
	}
	/* Do not waitpid(2) as it cannot be our direct descendant and it gets
	   cleaned up by init(8).  */
#if 0
	pid_t pid_got;
	if (pid != (pid_got = waitpid (pid, NULL, 0))) {
		fprintf (stderr, "%s: waitpid (%d) != %d: %m\n", progname,
			 (int) pid, (int) pid_got);
		return;
	}
#endif
}

static void rip (pid_t pgid_child)
{
	DIR *dir;
	struct dirent *dirent;

	dir = opendir ("/proc");
	if (!dir) {
		perror ("opendir (\"/proc\")");
		exit (EXIT_FAILURE);
	}
	while ((errno = 0, dirent = readdir (dir))) {
		const char *cs;

		/* FIXME: POSIX portability.  */
		if (dirent->d_type != DT_DIR)
			continue;
		/* Check /^\d+$/:  */
		for (cs = dirent->d_name; *cs; cs++)
			if (!isdigit (*cs))
				break;
		if (cs == dirent->d_name || *cs)
			continue;
		rip_pid (atoi (dirent->d_name), pgid_child);
	}
	if (errno) {
		perror ("readdir (\"/proc\")");
		exit (EXIT_FAILURE);
	}
	if (closedir (dir)) {
		perror ("closedir (\"/proc\")");
		exit (EXIT_FAILURE);
	}

}

int main (int argc, char **argv)
{
	int rc;
	pid_t child;

	if (argc < 2
	    || !strcmp (argv[1], "-h")
	    || !strcmp (argv[1], "--help")) {
		fputs("Syntax: orphanripper <execvp(3) commandline>\n", stdout);
		exit (EXIT_FAILURE);
	}
	progname = argv[0];
	rc = spawn (argv, &child);
	rip (child);
	return rc;
}

gdb-6.5-attach-stop.patch:
 linux-nat.c                       |   27 ++--
 testsuite/gdb.base/attachstop.c   |   51 ++++++++
 testsuite/gdb.base/attachstop.exp |  234 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 303 insertions(+), 9 deletions(-)

Index: gdb-6.5-attach-stop.patch
===================================================================
RCS file: /cvs/dist/rpms/gdb/devel/gdb-6.5-attach-stop.patch,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- gdb-6.5-attach-stop.patch	21 Sep 2006 13:07:53 -0000	1.1
+++ gdb-6.5-attach-stop.patch	12 Dec 2006 22:16:21 -0000	1.2
@@ -1,41 +1,57 @@
-sleep 1h& pid=$!; kill -STOP $pid; gdb sleep $pid
-	->
-Attaching to program: /bin/sleep, process 20768
-../../gdb/linux-nat.c:1057: internal-error: linux_nat_attach: Assertion `pid == GET_PID (inferior_ptid) && WIFSTOPPED (status) && WSTOPSIG (status) == SIGSTOP' failed.
+https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=209521
+https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=219118
+http://sources.redhat.com/ml/gdb-patches/2006-09/msg00092.html
 
 Specific to Red Hat kernels, kernel.org kernels lockup on gdb "attach".
 
 
-2006-09-17  Jan Kratochvil  <jan.kratochvil at redhat.com>
+2006-12-11  Jan Kratochvil  <jan.kratochvil at redhat.com>
 
 	* gdb-6.5/gdb/linux-nat.c (linux_nat_attach): Handle already stopped
-	processes.
+	processes, compiled either in a nonthreaded or a threaded mode.
 
-2006-09-17  Jeff Johnston  <jjohnstn at redhat.com>
+2006-12-11  Jeff Johnston  <jjohnstn at redhat.com>
 	    Jan Kratochvil  <jan.kratochvil at redhat.com>
 
 	* gdb.base/attachstop.exp, gdb.base/attachstop.c: New files,
-	test attaching to already stopped processes.
+	test attaching to already stopped processes, compiled either in
+	a nonthreaded or a threaded mode.
 
 
-Index: gdb-6.5/gdb/linux-nat.c
-===================================================================
-RCS file: /cvs/src/src/gdb/linux-nat.c,v
-retrieving revision 1.50
-diff -u -p -r1.50 linux-nat.c
---- gdb-6.5-orig/gdb/linux-nat.c	16 Sep 2006 09:48:12 -0000	1.50
-+++ gdb-6.5/gdb/linux-nat.c	17 Sep 2006 21:50:32 -0000
-@@ -1022,13 +1022,16 @@ linux_nat_attach (char *args, int from_t
+diff -u -ruNp gdb-6.5-orig/gdb/linux-nat.c gdb-6.5/gdb/linux-nat.c
+--- gdb-6.5-orig/gdb/linux-nat.c	2006-12-12 00:30:18.000000000 +0100
++++ gdb-6.5/gdb/linux-nat.c	2006-12-11 23:42:23.000000000 +0100
+@@ -567,7 +567,9 @@ linux_handle_extended_wait (int pid, int
+ 	  else if (ret != new_pid)
+ 	    internal_error (__FILE__, __LINE__,
+ 			    _("wait returned unexpected PID %d"), ret);
+-	  else if (!WIFSTOPPED (status) || WSTOPSIG (status) != SIGSTOP)
++	  /* In some cases we get 0 for the `SIGSTOP' signal.  */
++	  else if (!WIFSTOPPED (status) ||
++		   (WSTOPSIG (status) != SIGSTOP && WSTOPSIG (status) != 0))
+ 	    internal_error (__FILE__, __LINE__,
+ 			    _("wait returned unexpected status 0x%x"), status);
+ 	}
+@@ -1007,8 +1009,9 @@ lin_lwp_attach_lwp (ptid_t ptid, int ver
+ 	  lp->cloned = 1;
+ 	}
+ 
++      /* In some cases we get 0 for the `SIGSTOP' signal.  */
+       gdb_assert (pid == GET_LWP (ptid)
+-		  && WIFSTOPPED (status) && WSTOPSIG (status));
++		  && WIFSTOPPED (status));
+ 
+       target_post_attach (pid);
+ 
+@@ -1062,13 +1065,14 @@ linux_nat_attach (char *args, int from_t
        lp->cloned = 1;
      }
  
 -  gdb_assert (pid == GET_PID (inferior_ptid)
 -	      && WIFSTOPPED (status) && WSTOPSIG (status) == SIGSTOP);
-+  /* Do not check `WSTOPSIG (status) == SIGSTOP' as the status may be
-+     arbitrary - depending on the signal that stopped the processes.
-+     If the process was running we get SIGSTOP, if it was already stopped
-+     by SIGSTOP we get 0.  The value gets used for `PTRACE_CONT'.  */
-+  gdb_assert (pid == GET_PID (inferior_ptid) && WIFSTOPPED (status));
++  /* In some cases we get 0 for the `SIGSTOP' signal.  */
++  gdb_assert (pid == GET_PID (inferior_ptid) && WIFSTOPPED (status)
++              && (WSTOPSIG (status) == SIGSTOP || WSTOPSIG (status) == 0));
  
    lp->stopped = 1;
  
@@ -46,13 +62,44 @@
    lp->resumed = 1;
    if (debug_linux_nat)
      {
-Index: gdb-6.5/gdb/testsuite/gdb.base/attachstop.c
-===================================================================
-RCS file: gdb-6.5/gdb/testsuite/gdb.base/attachstop.c
-diff -N gdb-6.5/gdb/testsuite/gdb.base/attachstop.c
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ gdb-6.5/gdb/testsuite/gdb.base/attachstop.c	17 Sep 2006 21:50:32 -0000
-@@ -0,0 +1,29 @@
+@@ -1509,7 +1513,8 @@ stop_wait_callback (struct lwp_info *lp,
+ 	  return stop_wait_callback (lp, flush_mask);
+ 	}
+ 
+-      if (WSTOPSIG (status) != SIGSTOP)
++      /* In some cases we get 0 for the `SIGSTOP' signal.  */
++      if (WSTOPSIG (status) != SIGSTOP && WSTOPSIG (status) != 0)
+ 	{
+ 	  if (WSTOPSIG (status) == SIGTRAP)
+ 	    {
+@@ -2093,8 +2098,10 @@ retry:
+ 	      if (options & __WCLONE)
+ 		lp->cloned = 1;
+ 
++	      /* In some cases we get 0 for the `SIGSTOP' signal.  */
+ 	      gdb_assert (WIFSTOPPED (status)
+-			  && WSTOPSIG (status) == SIGSTOP);
++			  && (WSTOPSIG (status) == SIGSTOP
++			      || WSTOPSIG (status) == 0));
+ 	      lp->signalled = 1;
+ 
+ 	      if (!in_thread_list (inferior_ptid))
+@@ -2195,8 +2202,10 @@ retry:
+ 	  /* Make sure we don't report a SIGSTOP that we sent
+ 	     ourselves in an attempt to stop an LWP, unless we
+ 	     intentionally want to see the SIGSTOP.  */
++	  /* In some cases we get 0 for the `SIGSTOP' signal.  */
+ 	  if (lp->signalled && !intentional_stop
+-	      && WIFSTOPPED (status) && WSTOPSIG (status) == SIGSTOP)
++	      && WIFSTOPPED (status) && (WSTOPSIG (status) == SIGSTOP
++					 || WSTOPSIG (status) == 0))
+ 	    {
+ 	      if (debug_linux_nat)
+ 		fprintf_unfiltered (gdb_stdlog,
+diff -u -ruNp gdb-6.5-orig/gdb/testsuite/gdb.base/attachstop.c gdb-6.5/gdb/testsuite/gdb.base/attachstop.c
+--- gdb-6.5-orig/gdb/testsuite/gdb.base/attachstop.c	1970-01-01 01:00:00.000000000 +0100
++++ gdb-6.5/gdb/testsuite/gdb.base/attachstop.c	2006-12-11 23:58:22.000000000 +0100
+@@ -0,0 +1,51 @@
 +/* This testcase is part of GDB, the GNU debugger.
 +
 +   Copyright 2005 Free Software Foundation, Inc.
@@ -74,21 +121,40 @@
 +/* This program is intended to be started outside of gdb, then
 +   manually stopped via a signal.  */
 +
++#include <stddef.h>
 +#include <unistd.h>
++#ifdef USE_THREADS
++#include <pthread.h>
++#endif
 +
-+int main ()
++static void *func (void *arg)
 +{
 +  sleep (10000);  /* Ridiculous time, but we will eventually kill it.  */
 +  sleep (10000);  /* Second sleep.  */
++  return NULL;
++}
++
++int main ()
++{
++
++#ifndef USE_THREADS
++
++  func (NULL);
++
++#else
++
++  pthread_t th;
++  pthread_create (&th, NULL, func, NULL);
++  pthread_join (th, NULL);
++
++#endif
++
 +  return 0;
 +}
-Index: gdb-6.5/gdb/testsuite/gdb.base/attachstop.exp
-===================================================================
-RCS file: gdb-6.5/gdb/testsuite/gdb.base/attachstop.exp
-diff -N gdb-6.5/gdb/testsuite/gdb.base/attachstop.exp
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ gdb-6.5/gdb/testsuite/gdb.base/attachstop.exp	17 Sep 2006 21:50:32 -0000
-@@ -0,0 +1,198 @@
+diff -u -ruNp gdb-6.5-orig/gdb/testsuite/gdb.base/attachstop.exp gdb-6.5/gdb/testsuite/gdb.base/attachstop.exp
+--- gdb-6.5-orig/gdb/testsuite/gdb.base/attachstop.exp	1970-01-01 01:00:00.000000000 +0100
++++ gdb-6.5/gdb/testsuite/gdb.base/attachstop.exp	2006-12-12 00:26:39.000000000 +0100
+@@ -0,0 +1,234 @@
 +# Copyright 2005-2006
 +
 +# This program is free software; you can redistribute it and/or modify
@@ -132,158 +198,194 @@
 +#
 +#log_user 1
 +
-+# build the test case
-+#
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
-+    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
-+}
++proc corefunc { threadtype } {
++    global srcfile
++    global binfile
++    global escapedbinfile
++    global srcdir
++    global subdir
++    global gdb_prompt
 +
-+if [get_compiler_info ${binfile}] {
-+    return -1
-+}
++    if [get_compiler_info ${binfile}] {
++	return -1
++    }
 +
-+# Start the program running and then wait for a bit, to be sure
-+# that it can be attached to.
++    # Start the program running and then wait for a bit, to be sure
++    # that it can be attached to.
 +
-+set testpid [eval exec $binfile &]
-+exec sleep 2
-+   
-+# Stop the program 
-+remote_exec build "kill -s STOP ${testpid}"
-+
-+# Start with clean gdb
-+gdb_exit
-+gdb_start
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
-+
-+# Verify that we can attach to the process by first giving its
-+# executable name via the file command, and using attach with the
-+# process ID.
-+
-+set test "set file, before attach1 to stopped process"
-+gdb_test_multiple "file $binfile" "$test" {
-+   -re "Load new symbol table from.*y or n. $" {
-+        gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
-+		"$test (re-read)"
++    set testpid [eval exec $binfile &]
++    exec sleep 2
++       
++    # Stop the program 
++    remote_exec build "kill -s STOP ${testpid}"
++
++    # Start with clean gdb
++    gdb_exit
++    gdb_start
++    gdb_reinitialize_dir $srcdir/$subdir
++    gdb_load ${binfile}
++
++    # Verify that we can attach to the process by first giving its
++    # executable name via the file command, and using attach with the
++    # process ID.
++
++    set test "$threadtype: set file, before attach1 to stopped process"
++    gdb_test_multiple "file $binfile" "$test" {
++       -re "Load new symbol table from.*y or n. $" {
++	    gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
++		    "$test (re-read)"
++	}
++	-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
++	    pass "$test"
++	}
 +    }
-+    -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
-+        pass "$test"
++
++    set test "$threadtype: attach1 to stopped, after setting file"
++    gdb_test_multiple "attach $testpid" "$test" {
++	-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
++	    pass "$test"
++	}
 +    }
-+}
 +
-+set test "attach1 to stopped, after setting file"
-+gdb_test_multiple "attach $testpid" "$test" {
-+    -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
-+        pass "$test"
++    if {[string equal $threadtype threaded]} {
++	gdb_test "thread apply all bt" ".*sleep.*clone.*" "$threadtype: attach1 to stopped bt"
++    } else {
++	gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach1 to stopped bt"
 +    }
-+}
 +
-+gdb_test "bt" ".*sleep.*main.*" "attach1 to stopped bt"
++    # Exit and detach the process.
++       
++    gdb_exit
++
++    set fileid [open /proc/${testpid}/status r];
++    gets $fileid line1;
++    gets $fileid line2;
++    close $fileid;
 +
-+# Exit and detach the process.
-+   
-+gdb_exit
-+
-+set fileid [open /proc/${testpid}/status r];
-+gets $fileid line1;
-+gets $fileid line2;
-+close $fileid;
-+
-+set test "attach1, exit leaves process stopped"
-+if {[string match "*(stopped)*" $line2]} {
-+  pass $test
-+} else {
-+  fail $test
-+}
++    set test "$threadtype: attach1, exit leaves process stopped"
++    if {[string match "*(stopped)*" $line2]} {
++      pass $test
++    } else {
++      fail $test
++    }
 +
-+# At this point, the process should still be stopped
++    # At this point, the process should still be stopped
 +
-+gdb_start
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
-+
-+# Verify that we can attach to the process just by giving the
-+# process ID.
-+   
-+set test "attach2 to stopped, after setting file"
-+gdb_test_multiple "attach $testpid" "$test" {
-+    -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
-+        pass "$test"
++    gdb_start
++    gdb_reinitialize_dir $srcdir/$subdir
++    gdb_load ${binfile}
++
++    # Verify that we can attach to the process just by giving the
++    # process ID.
++       
++    set test "$threadtype: attach2 to stopped, after setting file"
++    gdb_test_multiple "attach $testpid" "$test" {
++	-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
++	    pass "$test"
++	}
 +    }
-+}
-+
-+gdb_test "bt" ".*sleep.*main.*" "attach2 to stopped bt"
-+gdb_breakpoint [gdb_get_line_number "Second sleep"]
-+set test "attach2 continue"
-+send_gdb "continue\n"
-+gdb_expect {
-+  -re "Continuing"
-+    { pass "continue ($test)" }
-+  timeout
-+    { fail "continue ($test) (timeout)" }
-+}
 +
-+# For this to work we must be sure to consume the "Continuing."
-+# message first, or GDB's signal handler may not be in place.
-+after 1000 {send_gdb "\003"}
-+set test "attach2 stop unbreakable interrupt"
-+gdb_expect 4 {
-+  -re "Program received signal SIGINT.*$gdb_prompt $"
-+    {
-+      fail "$test (broke into)"
-+    }
-+  -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
-+    {
-+      fail "$test (broke into)"
++    if {[string equal $threadtype threaded]} {
++	gdb_test "thread apply all bt" ".*sleep.*clone.*" "$threadtype: attach2 to stopped bt"
++    } else {
++	gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach2 to stopped bt"
 +    }
-+  timeout
-+    {
-+      pass $test
++    gdb_breakpoint [gdb_get_line_number "$threadtype: Second sleep"]
++    set test "$threadtype: attach2 continue"
++    send_gdb "continue\n"
++    gdb_expect {
++      -re "Continuing"
++	{ pass "continue ($test)" }
++      timeout
++	{ fail "continue ($test) (timeout)" }
 +    }
-+}
 +
-+# Continue the program 
-+remote_exec build "kill -s CONT ${testpid}"
++    # For this to work we must be sure to consume the "Continuing."
++    # message first, or GDB's signal handler may not be in place.
++    after 1000 {send_gdb "\003"}
++    set test "$threadtype: attach2 stop unbreakable interrupt"
++    gdb_expect 4 {
++      -re "Program received signal SIGINT.*$gdb_prompt $"
++	{
++	  fail "$test (broke into)"
++	}
++      -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
++	{
++	  fail "$test (broke into)"
++	}
++      timeout
++	{
++	  pass $test
++	}
++    }
 +
-+# Already sent before: after 1000 {send_gdb "\003"}
-+set test "attach2 stop by interrupt"
-+gdb_expect {
-+  -re "Program received signal SIGINT.*$gdb_prompt $"
-+    {
-+      pass $test
++    # Continue the program 
++    remote_exec build "kill -s CONT ${testpid}"
++
++    if {[string equal $threadtype threaded]} {
++	# Isn't a bug? kernel-xen-2.6.18-1.2767.el5.i686
++        set signal_expect "SIGCONT"
++    } else {
++    	set signal_expect "SIGINT"
 +    }
-+  -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
-+    {
-+      pass $test
++    # Already sent before: after 1000 {send_gdb "\003"}
++    set test "$threadtype: attach2 stop by interrupt"
++    gdb_expect {
++      -re "Program received signal $signal_expect,.*$gdb_prompt $"
++	{
++	  pass $test
++	}
++      -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
++	{
++	  pass $test
++	}
++      timeout
++	{
++	  fail "$test (timeout)"
++	}
 +    }
-+  timeout
-+    {
-+      fail "$test (timeout)"
++
++    gdb_exit
++
++    # Avoid some race:
++    exec sleep 2
++
++    # At this point, the process should be sleeping
++
++    set fileid2 [open /proc/${testpid}/status r];
++    gets $fileid2 line1;
++    gets $fileid2 line2;
++    close $fileid2;
++
++    set test "$threadtype: attach2, exit leaves process sleeping"
++    if {[string match "*(sleeping)*" $line2]} {
++      pass $test
++    } else {
++      fail $test
 +    }
++
++    # Make sure we don't leave a process around to confuse
++    # the next test run (and prevent the compile by keeping
++    # the text file busy), in case the "set should_exit" didn't
++    # work.
++       
++    remote_exec build "kill -9 ${testpid}"
 +}
 +
-+gdb_exit
++# build the test case first without threads
++#
++if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
++    gdb_suppress_entire_file "Testcase nonthraded compile failed, so all tests in this file will automatically fail."
++}
 +
-+# At this point, the process should be sleeping
++corefunc nonthreaded
 +
-+set fileid2 [open /proc/${testpid}/status r];
-+gets $fileid2 line1;
-+gets $fileid2 line2;
-+close $fileid2;
-+
-+set test "attach2, exit leaves process sleeping"
-+if {[string match "*(sleeping)*" $line2]} {
-+  pass $test
-+} else {
-+  fail $test
++# build the test case first without threads
++#
++if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DUSE_THREADS}] != "" } {
++    gdb_suppress_entire_file "Testcase threaded compile failed, so all tests in this file will automatically fail."
 +}
 +
-+# Make sure we don't leave a process around to confuse
-+# the next test run (and prevent the compile by keeping
-+# the text file busy), in case the "set should_exit" didn't
-+# work.
-+   
-+remote_exec build "kill -9 ${testpid}"
++corefunc threaded
 +
 +return 0


Index: gdb.spec
===================================================================
RCS file: /cvs/dist/rpms/gdb/devel/gdb.spec,v
retrieving revision 1.208
retrieving revision 1.209
diff -u -r1.208 -r1.209
--- gdb.spec	25 Nov 2006 19:11:24 -0000	1.208
+++ gdb.spec	12 Dec 2006 22:16:21 -0000	1.209
@@ -11,7 +11,7 @@
 Version: 6.5
 
 # The release always contains a leading reserved number, start it at 0.
-Release: 18%{?dist}
+Release: 19%{?dist}
 
 License: GPL
 Group: Development/Debuggers
@@ -47,6 +47,9 @@
 Patch3: gdb-6.3-rh-testlibunwind-20041202.patch
 Patch4: gdb-6.3-rh-testlibunwind1fix-20041202.patch
 
+# Cleanup any leftover testsuite processes as it may stuck mock(1) builds.
+Source2: gdb-orphanripper.c
+
 
 # ------------------------------------------
 
@@ -253,6 +256,7 @@
 Patch192: gdb-6.5-bz206813-cplusplus-symbol-null.patch
 
 # Fix attach to stopped process, supersede `gdb-6.3-attach-stop-20051011.patch'.
+# Fix attachment also to a threaded stopped process (BZ 219118).
 Patch193: gdb-6.5-attach-stop.patch
 
 # Support TLS symbols (+`errno' suggestion if no pthread is found) (BZ 185337).
@@ -499,10 +503,11 @@
 %ifarch %{ix86} x86_64 s390x s390 ppc ia64 ppc64
 echo ====================TESTING=========================
 cd gdb/testsuite
+gcc -o ./orphanripper %{SOURCE2} -Wall
 # Need to use a single --ignore option, second use overrides first.
 # "chng-syms.exp" for possibly avoiding Linux kernel crash - Bug 207002.
 # "threadcrash.exp" is incompatible on ia64 with old kernels.
-make -k check RUNTESTFLAGS='--ignore "bigcore.exp chng-syms.exp checkpoint.exp threadcrash.exp"' || :
+./orphanripper make -k check RUNTESTFLAGS='--ignore "bigcore.exp chng-syms.exp checkpoint.exp threadcrash.exp"' || :
 for t in sum log; do
   ln gdb.$t gdb-%{_target_platform}.$t || :
 done
@@ -586,6 +591,10 @@
 # don't include the files in include, they are part of binutils
 
 %changelog
+* Tue Dec 12 2006 Jan Kratochvil <jan.kratochvil at redhat.com> - 6.5-19
+- Fix attachment also to a threaded stopped process (BZ 219118).
+- Cleanup any leftover testsuite processes as it may stuck mock(1) builds.
+
 * Sat Nov 25 2006 Jan Kratochvil <jan.kratochvil at redhat.com> - 6.5-18
 - Fix readline history for input mode commands like `command' (BZ 215816).
 




More information about the fedora-cvs-commits mailing list