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]

2/5 - add basic longjmp testing to the testsuite


This is adds basic longjmp testing to the testsuite.

Tested on x86_64-unknown-linux-gnu and x86-pc-linux-gnu,
with the whole series applied (to get over the glibc pointer mangling
jmp_bufs), and on i686-pc-cygwin.


-- 
Pedro Alves
2008-04-07  Pedro Alves  <pedro@codesourcery.com>

	* testsuite/gdb.base/longjmp.c, testsuite/gdb.base/longjmp.exp:
	New files.

---
 gdb/testsuite/gdb.base/longjmp.c   |   81 +++++++++++++++++++++++
 gdb/testsuite/gdb.base/longjmp.exp |  130 +++++++++++++++++++++++++++++++++++++
 2 files changed, 211 insertions(+)

Index: src/gdb/testsuite/gdb.base/longjmp.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.base/longjmp.c	2008-04-05 23:52:10.000000000 +0100
@@ -0,0 +1,81 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2008 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/>.
+*/
+
+#include <setjmp.h>
+
+jmp_buf env;
+
+volatile int longjmps = 0;
+volatile int resumes = 0;
+
+int
+call_longjmp (jmp_buf *buf)
+{
+  longjmps++;
+  longjmp (*buf, 1);
+}
+
+void
+hidden_longjmp (void)
+{
+  if (setjmp (env) == 0) /* longjmp caught */
+    {
+      call_longjmp (&env);
+    }
+  else
+    resumes++;
+}
+
+int
+main ()
+{
+  volatile int i = 0;
+
+  /* Pattern 1 - simple longjmp.  */
+  if (setjmp (env) == 0) /* patt1 */
+    {
+      longjmps++;
+      longjmp (env, 1);
+    }
+  else
+    {
+      resumes++;
+    }
+
+  i = 1; /* miss_step_1 */
+
+
+  /* Pattern 2 - longjmp from an inner function.  */
+  if (setjmp (env) == 0) /* patt2 */
+    {
+      call_longjmp (&env);
+    }
+  else
+    {
+      resumes++;
+    }
+
+  i = 2; /* miss_step_2 */
+
+  /* Pattern 3 - setjmp/longjmp inside stepped-over function.  */
+  hidden_longjmp (); /* patt3 */
+
+  i = 3; /* patt_end3.  */
+
+  return 0;
+}
Index: src/gdb/testsuite/gdb.base/longjmp.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.base/longjmp.exp	2008-04-05 23:50:53.000000000 +0100
@@ -0,0 +1,130 @@
+# Copyright 2008 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 support for stepping over longjmp.
+#
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile "longjmp"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
+     untested longjmp.exp
+     return -1
+}
+
+if [get_compiler_info ${binfile}] {
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+if ![runto_main] then {
+   fail "Can't run to main"
+   return 0
+}
+
+set bp_miss_step_1 [gdb_get_line_number "miss_step_1"]
+set bp_miss_step_2 [gdb_get_line_number "miss_step_2"]
+
+set bp_start_test_1 [gdb_get_line_number "patt1"]
+set bp_start_test_2 [gdb_get_line_number "patt2"]
+set bp_start_test_3 [gdb_get_line_number "patt3"]
+
+#
+# Pattern 1 - simple longjmp.
+#
+
+delete_breakpoints
+
+gdb_test "break $bp_start_test_1" \
+    "Breakpoint.*at.* file .*$srcfile, line.*$bp_start_test_1.*" \
+    "breakpoint at pattern 1 start"
+gdb_test "continue" "patt1.*" "continue to breakpoint at pattern 1 start"
+
+# set safe-net break
+gdb_test "break $bp_miss_step_1" \
+    "Breakpoint.*at.* file .*$srcfile, line.*$bp_miss_step_1.*" \
+    "breakpoint at miss_step_1"
+
+gdb_test "next" "longjmps\\+\\+;.*" "next over setjmp (1)"
+gdb_test "next" "longjmp \\(env, 1\\);.*" "next to longjmp (1)"
+
+set msg "next over longjmp(1)"
+gdb_test_multiple "next" $msg {
+    -re ".*patt1.*" {
+	pass $msg
+	gdb_test "next" "resumes\\+\\+.*" "next into else block (1)"
+	gdb_test "next" "miss_step_1.*" "next into safety net (1)"
+    }
+    -re "miss_step_1.*" {
+	fail $msg
+    }
+}
+
+#
+# Pattern 2 - longjmp from an inner function.
+#
+
+delete_breakpoints
+
+gdb_test "break $bp_start_test_2" \
+    "Breakpoint.*at.* file .*$srcfile, line.*$bp_start_test_2.*" \
+    "breakpoint at pattern 2 start"
+gdb_test "continue" "patt2.*" "continue to breakpoint at pattern 2 start"
+
+# set safe-net break
+gdb_test "break $bp_miss_step_2" \
+    "Breakpoint.*at.* file .*$srcfile, line.*$bp_miss_step_2.*" \
+    "breakpoint at miss_step_2"
+
+gdb_test "next" "call_longjmp.*" "next over setjmp (2)"
+
+set msg "next over call_longjmp (2)"
+gdb_test_multiple "next" $msg {
+    -re ".*patt2.*" {
+	pass $msg
+
+	gdb_test "next" "resumes\\+\\+.*" "next into else block (2)"
+	gdb_test "next" "miss_step_2.*" "next into safety next (2)"
+    }
+    -re "miss_step_2.*" {
+	fail $msg
+    }
+}
+
+#
+# Pattern 3 - setjmp/longjmp inside stepped-over function.
+#
+
+delete_breakpoints
+
+gdb_test "break $bp_start_test_3" \
+    "Breakpoint.*at.* file .*$srcfile, line.*$bp_start_test_3.*" \
+    "breakpoint at pattern 3 start"
+gdb_test "continue" "patt3.*" "continue to breakpoint at pattern 3 start"
+
+gdb_test "next" "longjmp caught.*" "next over patt3"

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