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]

[PATCH] Fix non executable stack handling when calling functions in the inferior.


When gdb creates a dummy frame to execute a function in the inferior,
the process may generate a SIGSEGV, SIGEMT or SIGILL because the stack
is non executable. If the signal handler set in gdb has option print
or stop enabled for these signals gdb handles this correctly.

However, in the case of noprint and nostop the signal is short-circuited
and the inferior process is sent the signal directly. This causes the
inferior to crash because of gdb.

This patch adds a check for SIGSEGV, SIGEMT or SIGILL so that these
signals are sent to gdb rather than short-circuited in the inferior.
gdb then handles them properly and the inferior process does not crash.

Also added a small testcase to test the issue called catch-gdb-caused-signals.

This applies to Linux only, tested on Linux.

gdb/ChangeLog:
	PR breakpoints/16812
	* linux-nat.c (linux_nat_filter_event): Report SIGILL,SIGSEGV,SIGEMT.

gdb/testsuite/ChangeLog:
	PR breakpoints/16812
	* gdb.base/catch-gdb-caused-signals.c: New file.
	* gdb.base/catch-gdb-caused-signals.exp: New file.
---
 gdb/linux-nat.c                                    |    9 +++-
 gdb/testsuite/gdb.base/catch-gdb-caused-signals.c  |   30 +++++++++++++
 .../gdb.base/catch-gdb-caused-signals.exp          |   46 ++++++++++++++++++++
 3 files changed, 83 insertions(+), 2 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/catch-gdb-caused-signals.c
 create mode 100644 gdb/testsuite/gdb.base/catch-gdb-caused-signals.exp

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 169188a..a0c0e1c 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -3070,9 +3070,14 @@ linux_nat_filter_event (int lwpid, int status)
 	}
 
       /* When using hardware single-step, we need to report every signal.
-	 Otherwise, signals in pass_mask may be short-circuited.  */
+	 Otherwise, signals in pass_mask may be short-circuited
+	 unless these signals are SIGILL, SIGSEGV or SIGEMT.
+	 See handle_inferior_event for more information.  */
       if (!lp->step
-	  && WSTOPSIG (status) && sigismember (&pass_mask, WSTOPSIG (status)))
+	  && WSTOPSIG (status) && sigismember (&pass_mask, WSTOPSIG (status))
+	  && signo != GDB_SIGNAL_ILL
+	  && signo != GDB_SIGNAL_SEGV
+	  && signo != GDB_SIGNAL_EMT)
 	{
 	  linux_resume_one_lwp (lp, lp->step, signo);
 	  if (debug_linux_nat)
diff --git a/gdb/testsuite/gdb.base/catch-gdb-caused-signals.c b/gdb/testsuite/gdb.base/catch-gdb-caused-signals.c
new file mode 100644
index 0000000..ff74944
--- /dev/null
+++ b/gdb/testsuite/gdb.base/catch-gdb-caused-signals.c
@@ -0,0 +1,30 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   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 <http://www.gnu.org/licenses/>.  */
+
+/* This program is intended to be a simple dummy program for gdb to read.  */
+
+#include <unistd.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+  int i = 0;
+  printf("call main");
+  i++; /* set dprintf here */
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/catch-gdb-caused-signals.exp b/gdb/testsuite/gdb.base/catch-gdb-caused-signals.exp
new file mode 100644
index 0000000..9ada37a
--- /dev/null
+++ b/gdb/testsuite/gdb.base/catch-gdb-caused-signals.exp
@@ -0,0 +1,46 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# 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 <http://www.gnu.org/licenses/>.
+
+# Test that checks if we handle a SIGSEGV caused by gdb in the inferior
+# even if we have noprint,nostop options set in handle SIGSEGV
+# See PR breakpoints/16812
+
+standard_testfile
+
+set dp_location [gdb_get_line_number "set dprintf here"]
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
+    return -1
+}
+
+if ![runto_main] {
+    fail "Can't run to main to make the tests"
+    return -1
+}
+
+gdb_test "handle SIGSEGV nostop noprint" \
+    "Signal\[ \t\]+Stop\[ \t\]+Print\[ \t\]+Pass to program\[ \t\]+Description\r\nSIGSEGV\[ \t\]+No\[ \t\]+No\[ \t\]+Yes\[ \t\].*"
+
+gdb_test "call printf(\"test\\n\")" "test.*"
+
+# Clean up the breakpoint state.
+delete_breakpoints
+
+# Also test with dprintf since the original bug was noticed using dprintf.
+gdb_test "dprintf $dp_location,\"testdprintf\\n\"" "Dprintf .*"
+
+gdb_test "continue" "testdprintf.*"
-- 
1.7.9.5


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