Blame SOURCES/gdb-rhbz1149207-catch-syscall-after-fork.patch

2c2fa1
  NOTE: This patch has been forwardported from RHEL-6.7.
2c2fa1
2c2fa1
URL: <https://sourceware.org/ml/gdb-patches/2013-05/msg00364.html>
2c2fa1
Message-ID: <1368136582.30058.7.camel@soleil>
2c2fa1
2c2fa1
  From: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
2c2fa1
  To: gdb-patches at sourceware dot org
2c2fa1
  Subject: RFA: fix gdb_assert caused by 'catch signal ...' and fork
2c2fa1
  Date: Thu, 09 May 2013 23:56:22 +0200
2c2fa1
2c2fa1
  The attached patch fixes a gdb_assert caused by the combination of catch
2c2fa1
  signal and fork:
2c2fa1
    break-catch-sig.c:152: internal-error: signal_catchpoint_remove_location: Assertion `signal_catch_counts[iter] > 0' failed.
2c2fa1
2c2fa1
  The problem is that the signal_catch_counts is decremented by detach_breakpoints.
2c2fa1
  The fix consists in not detaching breakpoint locations of type bp_loc_other.
2c2fa1
  The patch introduces a new test.
2c2fa1
2c2fa1
Comments by Sergio Durigan Junior:
2c2fa1
2c2fa1
  I addded a specific testcase for this patch, which tests exactly the
2c2fa1
  issue that the customer is facing.  This patch does not solve the
2c2fa1
  whole problem of catching a syscall and forking (for more details,
2c2fa1
  see <https://sourceware.org/bugzilla/show_bug.cgi?id=13457>,
2c2fa1
  specifically comment #3), but it solves the issue reported by the
2c2fa1
  customer.
2c2fa1
2c2fa1
  I also removed the original testcase of this patch, because it
2c2fa1
  relied on "catch signal", which is a command that is not implemented
2c2fa1
  in this version of GDB.
2c2fa1
2c2fa1
commit bd9673a4ded96ea5c108601501c8e59003ea1be6
2c2fa1
Author: Philippe Waroquiers <philippe@sourceware.org>
2c2fa1
Date:   Tue May 21 18:47:05 2013 +0000
2c2fa1
2c2fa1
    Fix internal error caused by interaction between catch signal and fork
2c2fa1
2c2fa1
Index: gdb-7.6.1/gdb/breakpoint.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/breakpoint.c
2c2fa1
+++ gdb-7.6.1/gdb/breakpoint.c
2c2fa1
@@ -3542,6 +3542,15 @@ detach_breakpoints (ptid_t ptid)
2c2fa1
     if (bl->pspace != inf->pspace)
2c2fa1
       continue;
2c2fa1
 
2c2fa1
+    /* This function must physically remove breakpoints locations
2c2fa1
+       from the specified ptid, without modifying the breakpoint
2c2fa1
+       package's state.  Locations of type bp_loc_other are only
2c2fa1
+       maintained at GDB side.  So, there is no need to remove
2c2fa1
+       these bp_loc_other locations.  Moreover, removing these
2c2fa1
+       would modify the breakpoint package's state.  */
2c2fa1
+    if (bl->loc_type == bp_loc_other)
2c2fa1
+      continue;
2c2fa1
+
2c2fa1
     if (bl->inserted)
2c2fa1
       val |= remove_breakpoint_1 (bl, mark_inserted);
2c2fa1
   }
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.base/gdb-rhbz1149207-catch-syscall-fork.c
2c2fa1
===================================================================
2c2fa1
--- /dev/null
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.base/gdb-rhbz1149207-catch-syscall-fork.c
2c2fa1
@@ -0,0 +1,11 @@
2c2fa1
+#include <stdio.h>
2c2fa1
+#include <unistd.h>
2c2fa1
+
2c2fa1
+int
2c2fa1
+main (int argc, char **argv)
2c2fa1
+{
2c2fa1
+  if (fork () == 0)
2c2fa1
+    sleep (1);
2c2fa1
+  chdir (".");
2c2fa1
+  return 0;
2c2fa1
+}
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.base/gdb-rhbz1149207-catch-syscall-fork.exp
2c2fa1
===================================================================
2c2fa1
--- /dev/null
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.base/gdb-rhbz1149207-catch-syscall-fork.exp
2c2fa1
@@ -0,0 +1,58 @@
2c2fa1
+# Copyright 2015 Free Software Foundation, Inc.
2c2fa1
+
2c2fa1
+# This program is free software; you can redistribute it and/or modify
2c2fa1
+# it under the terms of the GNU General Public License as published by
2c2fa1
+# the Free Software Foundation; either version 3 of the License, or
2c2fa1
+# (at your option) any later version.
2c2fa1
+#
2c2fa1
+# This program is distributed in the hope that it will be useful,
2c2fa1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2c2fa1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c2fa1
+# GNU General Public License for more details.
2c2fa1
+#
2c2fa1
+# You should have received a copy of the GNU General Public License
2c2fa1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2c2fa1
+
2c2fa1
+if { [is_remote target] || ![isnative] } then {
2c2fa1
+    continue
2c2fa1
+}
2c2fa1
+
2c2fa1
+set testfile "gdb-rhbz1149207-catch-syscall-fork"
2c2fa1
+set srcfile ${testfile}.c
2c2fa1
+set binfile ${objdir}/${subdir}/${testfile}
2c2fa1
+
2c2fa1
+# Until "catch syscall" is implemented on other targets...
2c2fa1
+if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
2c2fa1
+    continue
2c2fa1
+}
2c2fa1
+
2c2fa1
+# This shall be updated whenever 'catch syscall' is implemented
2c2fa1
+# on some architecture.
2c2fa1
+#if { ![istarget "i\[34567\]86-*-linux*"]
2c2fa1
+if { ![istarget "x86_64-*-linux*"] && ![istarget "i\[34567\]86-*-linux*"]
2c2fa1
+     && ![istarget "powerpc-*-linux*"] && ![istarget "powerpc64-*-linux*"]
2c2fa1
+     && ![istarget "sparc-*-linux*"] && ![istarget "sparc64-*-linux*"] } {
2c2fa1
+     continue
2c2fa1
+}
2c2fa1
+
2c2fa1
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
2c2fa1
+    untested ${testfile}.exp
2c2fa1
+    return -1
2c2fa1
+}
2c2fa1
+
2c2fa1
+gdb_exit
2c2fa1
+gdb_start
2c2fa1
+gdb_reinitialize_dir $srcdir/$subdir
2c2fa1
+gdb_load $binfile
2c2fa1
+
2c2fa1
+if { ![runto_main] } {
2c2fa1
+    return -1
2c2fa1
+}
2c2fa1
+
2c2fa1
+gdb_test "catch syscall chdir" \
2c2fa1
+  "Catchpoint $decimal \\\(syscall (.)?chdir(.)? \\\[$decimal\\\]\\\)" \
2c2fa1
+  "catch syscall chdir"
2c2fa1
+
2c2fa1
+gdb_test "continue" \
2c2fa1
+  "Continuing\.\r\n.*\r\nCatchpoint $decimal \\\(call to syscall .?chdir.?.*" \
2c2fa1
+  "continue from catch syscall after fork"