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

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