URL: Message-ID: <1368136582.30058.7.camel@soleil> From: Philippe Waroquiers To: gdb-patches at sourceware dot org Subject: RFA: fix gdb_assert caused by 'catch signal ...' and fork Date: Thu, 09 May 2013 23:56:22 +0200 The attached patch fixes a gdb_assert caused by the combination of catch signal and fork: break-catch-sig.c:152: internal-error: signal_catchpoint_remove_location: Assertion `signal_catch_counts[iter] > 0' failed. The problem is that the signal_catch_counts is decremented by detach_breakpoints. The fix consists in not detaching breakpoint locations of type bp_loc_other. The patch introduces a new test. Comments by Sergio Durigan Junior: I addded a specific testcase for this patch, which tests exactly the issue that the customer is facing. This patch does not solve the whole problem of catching a syscall and forking (for more details, see , specifically comment #3), but it solves the issue reported by the customer. I also removed the original testcase of this patch, because it relied on "catch signal", which is a command that is not implemented in this version of GDB. commit bd9673a4ded96ea5c108601501c8e59003ea1be6 Author: Philippe Waroquiers Date: Tue May 21 18:47:05 2013 +0000 Fix internal error caused by interaction between catch signal and fork Index: gdb-7.12/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.12/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.c 2016-10-20 21:03:09.584272695 +0200 @@ -0,0 +1,11 @@ +#include +#include + +int +main (int argc, char **argv) +{ + if (fork () == 0) + sleep (1); + chdir ("."); + return 0; +} Index: gdb-7.12/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.12/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.exp 2016-10-20 21:04:13.337771174 +0200 @@ -0,0 +1,58 @@ +# Copyright 2015 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 . + +if { [is_remote target] || ![isnative] } then { + continue +} + +set testfile "gdb-rhbz1149205-catch-syscall-fork" +set srcfile ${testfile}.c +set binfile [standard_output_file ${testfile}] + +# Until "catch syscall" is implemented on other targets... +if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then { + continue +} + +# This shall be updated whenever 'catch syscall' is implemented +# on some architecture. +#if { ![istarget "i\[34567\]86-*-linux*"] +if { ![istarget "x86_64-*-linux*"] && ![istarget "i\[34567\]86-*-linux*"] + && ![istarget "powerpc-*-linux*"] && ![istarget "powerpc64-*-linux*"] + && ![istarget "sparc-*-linux*"] && ![istarget "sparc64-*-linux*"] } { + continue +} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested ${testfile}.exp + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load $binfile + +if { ![runto_main] } { + return -1 +} + +gdb_test "catch syscall chdir" \ + "Catchpoint $decimal \\\(syscall (.)?chdir(.)? \\\[$decimal\\\]\\\)" \ + "catch syscall chdir" + +gdb_test "continue" \ + "Continuing\.\r\n.*\r\nCatchpoint $decimal \\\(call to syscall .?chdir.?.*" \ + "continue from catch syscall after fork"