- Do not hang on exit of a thread group leader (BZ 247354).

- New test for upstream fix of VDSO decoding while attaching to an i386
    process.
- Fixed BZ # 232014 -> 232015.
This commit is contained in:
Jan Kratochvil 2007-07-08 10:45:30 +00:00
parent a0b6775162
commit 5c49e68313
5 changed files with 389 additions and 3 deletions

View File

@ -0,0 +1,110 @@
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ./gdb/testsuite/gdb.base/attach-see-vdso.c 6 Jul 2007 14:14:44 -0000
@@ -0,0 +1,25 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2007 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. */
+
+#include <unistd.h>
+
+int main ()
+{
+ pause ();
+ return 1;
+}
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ./gdb/testsuite/gdb.base/attach-see-vdso.exp 6 Jul 2007 14:14:44 -0000
@@ -0,0 +1,79 @@
+# Copyright 2007
+
+# 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.
+
+# This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+# This test only works on Linux
+if { ![istarget "*-*-linux-gnu*"] } {
+ return 0
+}
+
+set testfile "attach-see-vdso"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
+
+# The kernel VDSO is used for the syscalls returns only on i386 (not x86_64).
+#
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-m32}] != "" } {
+ gdb_suppress_entire_file "Testcase nonthraded compile failed, so all tests in this file will automatically fail."
+}
+
+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.
+
+set testpid [eval exec $binfile &]
+
+# Avoid some race:
+sleep 2
+
+# Start with clean gdb
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+# Never call: gdb_load ${binfile}
+# as the former problem would not reproduce otherwise.
+
+set test "attach"
+gdb_test_multiple "attach $testpid" "$test" {
+ -re "Attaching to process $testpid\r?\n.*$gdb_prompt $" {
+ pass "$test"
+ }
+}
+
+gdb_test "bt" "#0 *0x\[0-9a-f\]* in \[^?\].*" "backtrace decodes VDSO"
+
+# Exit and detach the process.
+
+gdb_exit
+
+# 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}"

View File

@ -0,0 +1,140 @@
2007-07-08 Jan Kratochvil <jan.kratochvil@redhat.com>
* linux-nat.c (linux_lwp_is_zombie): New function.
(wait_lwp): Fix lockup on exit of the thread group leader.
(linux_xfer_partial): Renamed to ...
(linux_xfer_partial_lwp): ... here.
(linux_xfer_partial): New function wrapping LINUX_XFER_PARTIAL_LWP.
--- ./gdb/linux-nat.c 3 Jul 2007 17:01:55 -0000 1.65
+++ ./gdb/linux-nat.c 7 Jul 2007 15:21:57 -0000
@@ -1343,6 +1343,31 @@ linux_handle_extended_wait (struct lwp_i
_("unknown ptrace event %d"), event);
}
+static int
+linux_lwp_is_zombie (long lwp)
+{
+ char buffer[MAXPATHLEN];
+ FILE *procfile;
+ int retval = 0;
+
+ sprintf (buffer, "/proc/%ld/status", lwp);
+ procfile = fopen (buffer, "r");
+ if (procfile == NULL)
+ {
+ warning (_("unable to open /proc file '%s'"), buffer);
+ return 0;
+ }
+ while (fgets (buffer, sizeof (buffer), procfile) != NULL)
+ if (strcmp (buffer, "State:\tZ (zombie)\n") == 0)
+ {
+ retval = 1;
+ break;
+ }
+ fclose (procfile);
+
+ return retval;
+}
+
/* Wait for LP to stop. Returns the wait status, or 0 if the LWP has
exited. */
@@ -1350,16 +1375,31 @@ static int
wait_lwp (struct lwp_info *lp)
{
pid_t pid;
- int status;
+ int status = 0;
int thread_dead = 0;
gdb_assert (!lp->stopped);
gdb_assert (lp->status == 0);
- pid = my_waitpid (GET_LWP (lp->ptid), &status, 0);
- if (pid == -1 && errno == ECHILD)
+ /* Thread group leader may have exited but we would lock up by WAITPID as it
+ waits on all its threads; __WCLONE is not applicable for the leader.
+ The thread leader restrictions is only a performance optimization here.
+ LINUX_NAT_THREAD_ALIVE cannot be used here as it requires a STOPPED
+ process; it gets ESRCH both for the zombie and for running processes. */
+ if (is_lwp (lp->ptid) && GET_PID (lp->ptid) == GET_LWP (lp->ptid)
+ && linux_lwp_is_zombie (GET_LWP (lp->ptid)))
+ {
+ thread_dead = 1;
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog, "WL: Threads leader %s vanished.\n",
+ target_pid_to_str (lp->ptid));
+ }
+
+ if (!thread_dead)
{
- pid = my_waitpid (GET_LWP (lp->ptid), &status, __WCLONE);
+ pid = my_waitpid (GET_LWP (lp->ptid), &status, 0);
+ if (pid == -1 && errno == ECHILD)
+ pid = my_waitpid (GET_LWP (lp->ptid), &status, __WCLONE);
if (pid == -1 && errno == ECHILD)
{
/* The thread has previously exited. We need to delete it
@@ -3144,10 +3159,12 @@ linux_proc_pending_signals (int pid, sig
fclose (procfile);
}
+/* Transfer from the specific LWP currently set by PID of INFERIOR_PTID. */
+
static LONGEST
-linux_xfer_partial (struct target_ops *ops, enum target_object object,
- const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
+linux_xfer_partial_lwp (struct target_ops *ops, enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
{
LONGEST xfer;
@@ -3164,6 +3181,45 @@ linux_xfer_partial (struct target_ops *o
offset, len);
}
+/* nptl_db expects being able to transfer memory just by specifying PID.
+ After the thread group leader exists the Linux kernel turns the task
+ into zombie no longer permitting accesses to its memory.
+ Transfer the memory from an arbitrary LWP_LIST entry in such case. */
+
+static LONGEST
+linux_xfer_partial (struct target_ops *ops, enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
+{
+ LONGEST xfer;
+ struct lwp_info *lp;
+ /* Not using SAVE_INFERIOR_PTID already here for better performance. */
+ struct cleanup *old_chain = NULL;
+ ptid_t inferior_ptid_orig = inferior_ptid;
+
+ errno = 0;
+ xfer = linux_xfer_partial_lwp (ops, object, annex, readbuf, writebuf,
+ offset, len);
+
+ for (lp = lwp_list; xfer == 0 && (errno == EACCES || errno == ESRCH)
+ && lp != NULL; lp = lp->next)
+ {
+ if (!is_lwp (lp->ptid) || ptid_equal (lp->ptid, inferior_ptid_orig))
+ continue;
+
+ if (old_chain == NULL)
+ old_chain = save_inferior_ptid ();
+ inferior_ptid = BUILD_LWP (GET_LWP (lp->ptid), GET_LWP (lp->ptid));
+ errno = 0;
+ xfer = linux_xfer_partial_lwp (ops, object, annex, readbuf, writebuf,
+ offset, len);
+ }
+
+ if (old_chain != NULL)
+ do_cleanups (old_chain);
+ return xfer;
+}
+
/* Create a prototype generic Linux target. The client can override
it with local methods. */

View File

@ -0,0 +1,121 @@
2007-07-07 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.threads/leader-exit.c, gdb.threads/leader-exit.exp: New files.
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ./gdb/testsuite/gdb.threads/leader-exit.c 7 Jul 2007 15:21:57 -0000
@@ -0,0 +1,47 @@
+/* Clean exit of the thread group leader should not break GDB.
+
+ Copyright 2007 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+
+static void *start (void *arg)
+{
+ for (;;)
+ pause ();
+ /* NOTREACHED */
+ assert (0);
+ return arg;
+}
+
+int main (void)
+{
+ pthread_t thread;
+ int i;
+
+ i = pthread_create (&thread, NULL, start, NULL); /* create1 */
+ assert (i == 0);
+
+ pthread_exit (NULL);
+ /* NOTREACHED */
+ assert (0);
+ return 0;
+}
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ./gdb/testsuite/gdb.threads/leader-exit.exp 7 Jul 2007 15:21:57 -0000
@@ -0,0 +1,64 @@
+# Copyright (C) 2007 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.
+
+# Exit of the thread group leader should not break GDB.
+
+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set testfile "leader-exit"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+gdb_run_cmd
+
+proc stop_process { description } {
+ global gdb_prompt
+
+ # 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"}
+ gdb_expect {
+ -re "Program received signal SIGINT.*$gdb_prompt $"
+ {
+ pass $description
+ }
+ timeout
+ {
+ fail "$description (timeout)"
+ }
+ }
+}
+
+# Prevent races.
+sleep 2
+
+stop_process "Threads could be stopped"
+
+gdb_test "info threads" \
+ "\\* 2 Thread \[^\r\n\]* in \[^\r\n\]*pause \\(\\) from \[^\r\n\]*" \
+ "Single thread has been left"

View File

@ -11,7 +11,7 @@ Name: gdb
Version: 6.6
# The release always contains a leading reserved number, start it at 1.
Release: 19%{?dist}
Release: 20%{?dist}
License: GPL
Group: Development/Debuggers
@ -337,8 +337,8 @@ Patch246: gdb-6.6-bz237096-watchthreads-testcasefix.patch
# Notify user of a child forked process being detached (BZ 235197).
Patch247: gdb-6.6-bz234468-fork-detach-info.patch
# Fix `gcore' command for 32bit PPC inferiors on 64bit PPC hosts (BZ 232014).
Patch248: gdb-6.6-bz232014-gcore-ppc-on-ppc64.patch
# Fix `gcore' command for 32bit PPC inferiors on 64bit PPC hosts (BZ 232015).
Patch248: gdb-6.6-bz232015-gcore-ppc-on-ppc64.patch
# New testcase for gcore of 32bit inferiors on 64bit hosts.
Patch249: gdb-6.6-gcore32-test.patch
@ -360,6 +360,13 @@ Patch258: gdb-6.6-bz237572-ppc-atomic-sequence-test.patch
# Link with libreadline provided by the operating system.
Patch261: gdb-6.6-readline-system.patch
# Test kernel VDSO decoding while attaching to an i386 process.
Patch263: gdb-6.3-attach-see-vdso-test.patch
# Do not hang on exit of a thread group leader (BZ 247354).
Patch265: gdb-6.6-bz247354-leader-exit-fix.patch
Patch266: gdb-6.6-bz247354-leader-exit-test.patch
BuildRequires: ncurses-devel glibc-devel gcc make gzip texinfo dejagnu gettext
BuildRequires: flex bison sharutils expat-devel
Requires: readline
@ -511,6 +518,9 @@ rm -f gdb/jv-exp.c gdb/m2-exp.c gdb/objc-exp.c gdb/p-exp.c
%patch258 -p1
%patch260 -p1
%patch261 -p1
%patch263 -p1
%patch265 -p1
%patch266 -p1
# Change the version that gets printed at GDB startup, so it is RedHat
# specific.
@ -663,6 +673,11 @@ fi
# don't include the files in include, they are part of binutils
%changelog
* Sun Jul 8 2007 Jan Kratochvil <jan.kratochvil@redhat.com> - 6.6-20
- Do not hang on exit of a thread group leader (BZ 247354).
- New test for upstream fix of VDSO decoding while attaching to an i386 process.
- Fixed BZ # 232014 -> 232015.
* Thu Jul 5 2007 Jan Kratochvil <jan.kratochvil@redhat.com> - 6.6-19
- Link with libreadline provided by the operating system.