a8767b3
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
f524ac5
From: Fedora GDB patches <invalid@email.com>
f524ac5
Date: Fri, 27 Oct 2017 21:07:50 +0200
f524ac5
Subject: gdb-rhbz1149205-catch-syscall-after-fork-test.patch
f524ac5
f637971
;; Fix '`catch syscall' doesn't work for parent after `fork' is called'
f637971
;; (Philippe Waroquiers, RH BZ 1149205).
f637971
;;=fedoratest
f637971
Jan Kratochvil 29d49d9
URL: <https://sourceware.org/ml/gdb-patches/2013-05/msg00364.html>
Jan Kratochvil 29d49d9
Message-ID: <1368136582.30058.7.camel@soleil>
Jan Kratochvil 29d49d9
Jan Kratochvil 29d49d9
  From: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
Jan Kratochvil 29d49d9
  To: gdb-patches at sourceware dot org
Jan Kratochvil 29d49d9
  Subject: RFA: fix gdb_assert caused by 'catch signal ...' and fork
Jan Kratochvil 29d49d9
  Date: Thu, 09 May 2013 23:56:22 +0200
Jan Kratochvil 29d49d9
Jan Kratochvil 29d49d9
  The attached patch fixes a gdb_assert caused by the combination of catch
Jan Kratochvil 29d49d9
  signal and fork:
Jan Kratochvil 29d49d9
    break-catch-sig.c:152: internal-error: signal_catchpoint_remove_location: Assertion `signal_catch_counts[iter] > 0' failed.
Jan Kratochvil 29d49d9
Jan Kratochvil 29d49d9
  The problem is that the signal_catch_counts is decremented by detach_breakpoints.
Jan Kratochvil 29d49d9
  The fix consists in not detaching breakpoint locations of type bp_loc_other.
Jan Kratochvil 29d49d9
  The patch introduces a new test.
Jan Kratochvil 29d49d9
Jan Kratochvil 29d49d9
Comments by Sergio Durigan Junior:
Jan Kratochvil 29d49d9
Jan Kratochvil 29d49d9
  I addded a specific testcase for this patch, which tests exactly the
Jan Kratochvil 29d49d9
  issue that the customer is facing.  This patch does not solve the
Jan Kratochvil 29d49d9
  whole problem of catching a syscall and forking (for more details,
Jan Kratochvil 29d49d9
  see <https://sourceware.org/bugzilla/show_bug.cgi?id=13457>,
Jan Kratochvil 29d49d9
  specifically comment #3), but it solves the issue reported by the
Jan Kratochvil 29d49d9
  customer.
Jan Kratochvil 29d49d9
Jan Kratochvil 29d49d9
  I also removed the original testcase of this patch, because it
Jan Kratochvil 29d49d9
  relied on "catch signal", which is a command that is not implemented
Jan Kratochvil 29d49d9
  in this version of GDB.
Jan Kratochvil 29d49d9
Jan Kratochvil 29d49d9
commit bd9673a4ded96ea5c108601501c8e59003ea1be6
Jan Kratochvil 29d49d9
Author: Philippe Waroquiers <philippe@sourceware.org>
Jan Kratochvil 29d49d9
Date:   Tue May 21 18:47:05 2013 +0000
Jan Kratochvil 29d49d9
Jan Kratochvil 29d49d9
    Fix internal error caused by interaction between catch signal and fork
Jan Kratochvil 29d49d9
f637971
diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.c b/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.c
f637971
new file mode 100644
f637971
--- /dev/null
f637971
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.c
Jan Kratochvil 29d49d9
@@ -0,0 +1,11 @@
Jan Kratochvil 29d49d9
+#include <stdio.h>
Jan Kratochvil 29d49d9
+#include <unistd.h>
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+int
Jan Kratochvil 29d49d9
+main (int argc, char **argv)
Jan Kratochvil 29d49d9
+{
Jan Kratochvil 29d49d9
+  if (fork () == 0)
Jan Kratochvil 29d49d9
+    sleep (1);
Jan Kratochvil 29d49d9
+  chdir (".");
Jan Kratochvil 29d49d9
+  return 0;
Jan Kratochvil 29d49d9
+}
f637971
diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.exp b/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.exp
f637971
new file mode 100644
f637971
--- /dev/null
f637971
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.exp
Jan Kratochvil 29d49d9
@@ -0,0 +1,58 @@
Jan Kratochvil 29d49d9
+# Copyright 2015 Free Software Foundation, Inc.
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+# This program is free software; you can redistribute it and/or modify
Jan Kratochvil 29d49d9
+# it under the terms of the GNU General Public License as published by
Jan Kratochvil 29d49d9
+# the Free Software Foundation; either version 3 of the License, or
Jan Kratochvil 29d49d9
+# (at your option) any later version.
Jan Kratochvil 29d49d9
+#
Jan Kratochvil 29d49d9
+# This program is distributed in the hope that it will be useful,
Jan Kratochvil 29d49d9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
Jan Kratochvil 29d49d9
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Jan Kratochvil 29d49d9
+# GNU General Public License for more details.
Jan Kratochvil 29d49d9
+#
Jan Kratochvil 29d49d9
+# You should have received a copy of the GNU General Public License
Jan Kratochvil 29d49d9
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+if { [is_remote target] || ![isnative] } then {
Jan Kratochvil 29d49d9
+    continue
Jan Kratochvil 29d49d9
+}
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+set testfile "gdb-rhbz1149205-catch-syscall-fork"
Jan Kratochvil 29d49d9
+set srcfile ${testfile}.c
Jan Kratochvil 29d49d9
+set binfile [standard_output_file ${testfile}]
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+# Until "catch syscall" is implemented on other targets...
Jan Kratochvil 29d49d9
+if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
Jan Kratochvil 29d49d9
+    continue
Jan Kratochvil 29d49d9
+}
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+# This shall be updated whenever 'catch syscall' is implemented
Jan Kratochvil 29d49d9
+# on some architecture.
Jan Kratochvil 29d49d9
+#if { ![istarget "i\[34567\]86-*-linux*"]
Jan Kratochvil 29d49d9
+if { ![istarget "x86_64-*-linux*"] && ![istarget "i\[34567\]86-*-linux*"]
Jan Kratochvil 29d49d9
+     && ![istarget "powerpc-*-linux*"] && ![istarget "powerpc64-*-linux*"]
Jan Kratochvil 29d49d9
+     && ![istarget "sparc-*-linux*"] && ![istarget "sparc64-*-linux*"] } {
Jan Kratochvil 29d49d9
+     continue
Jan Kratochvil 29d49d9
+}
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
Jan Kratochvil 29d49d9
+    untested ${testfile}.exp
Jan Kratochvil 29d49d9
+    return -1
Jan Kratochvil 29d49d9
+}
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+gdb_exit
Jan Kratochvil 29d49d9
+gdb_start
Jan Kratochvil 29d49d9
+gdb_reinitialize_dir $srcdir/$subdir
Jan Kratochvil 29d49d9
+gdb_load $binfile
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+if { ![runto_main] } {
Jan Kratochvil 29d49d9
+    return -1
Jan Kratochvil 29d49d9
+}
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+gdb_test "catch syscall chdir" \
Jan Kratochvil 29d49d9
+  "Catchpoint $decimal \\\(syscall (.)?chdir(.)? \\\[$decimal\\\]\\\)" \
Jan Kratochvil 29d49d9
+  "catch syscall chdir"
Jan Kratochvil 29d49d9
+
Jan Kratochvil 29d49d9
+gdb_test "continue" \
Jan Kratochvil 29d49d9
+  "Continuing\.\r\n.*\r\nCatchpoint $decimal \\\(call to syscall .?chdir.?.*" \
Jan Kratochvil 29d49d9
+  "continue from catch syscall after fork"