This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Workaround for 10970, 12702, avoid calling waitpid


On Tue, 17 May 2011 20:19:20 +0200, Doug Evans wrote:
> A proper fix seems much more invasive,

Which proper fix do you mean?  I guess __WNOTHREAD should be enough but it
does not work, it may be a kernel Bug.  Filed for evaluation:
	ptrace: __WNOTHREAD does not work
	https://bugzilla.redhat.com/show_bug.cgi?id=705583

If it is a kernel Bug another issue is how it could be made backward compatible
with existing kernels and whether such fix should be in FSF GDB.  Wouldn't a
non-racy backward fix be possible using blocked SIGCHLD, sigsuspend and
WNOHANG?

BTW the Fedora patch also changed linux_xfer_partial:
/* 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.  */

which no longer seems to be needed, I guess due to Pedro's fix proving:
2008-07-10 85fdbde9dfc62928a36ece6c53a42b59e28b31e7 Non-stop linux native.
  /* Access an lwp we know is stopped.  */
  info->proc_handle.ptid = ptid;
while the fix by me was written before - 2007-07-07.


> and this works well enough for a large number of cases.

Providing fixed testcase but it does not work as it already exploits the race
in the fix.


> I'll be checking it in tomorrow if there are no objections.

I am against checking in racy code which can be hopefully fixed properly.


Thanks,
Jan


testsuite/
2011-05-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.threads/leader-exit.c: New file.
	* gdb.threads/leader-exit.exp: New file.

--- /dev/null
+++ b/gdb/testsuite/gdb.threads/leader-exit.c
@@ -0,0 +1,49 @@
+/* Clean exit of the thread group leader should not break GDB.
+
+   Copyright 2007, 2011 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 <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+
+static volatile pthread_t main_thread;
+
+static void *
+start (void *arg)
+{
+  int i;
+
+  i = pthread_join (main_thread, NULL);
+  assert (i == 0);
+
+  return arg;	/* break-here */
+}
+
+int
+main (void)
+{
+  pthread_t thread;
+  int i;
+
+  main_thread = pthread_self ();
+
+  i = pthread_create (&thread, NULL, start, NULL);
+  assert (i == 0);
+
+  pthread_exit (NULL);
+  /* NOTREACHED */
+  return 0;
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/leader-exit.exp
@@ -0,0 +1,38 @@
+# Copyright (C) 2007, 2011 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/>.
+
+# Exit of the thread group leader should not break GDB.
+
+set testfile "leader-exit"
+set srcfile ${testfile}.c
+set executable ${testfile}
+set binfile ${objdir}/${subdir}/${executable}
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    return -1
+}
+
+clean_restart ${executable}
+
+if ![runto_main] {
+    return -1
+}
+
+gdb_breakpoint [gdb_get_line_number "break-here"]
+gdb_continue_to_breakpoint "break-here" ".* break-here .*"
+
+gdb_test "info threads" \
+	 "\r\n\[ \t\]*Id\[ \t\]+Target\[ \t\]+Id\[ \t\]+Frame\[ \t\]*\r\n\\* 2 *Thread \[^\r\n\]* at \[^\r\n\]*" \
+	 "Single thread has been left"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]