aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/longjmp.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2008-05-04 19:43:31 +0000
committerPedro Alves <palves@redhat.com>2008-05-04 19:43:31 +0000
commit9dd789d04055fc8240190e113562934e0c020c38 (patch)
tree8afb6be7108b623600224ec0f511b8c1b5eb3840 /gdb/testsuite/gdb.base/longjmp.c
parent611c83ae477b587e7d93636cc6c241d063bb799b (diff)
downloadgdb-9dd789d04055fc8240190e113562934e0c020c38.zip
gdb-9dd789d04055fc8240190e113562934e0c020c38.tar.gz
gdb-9dd789d04055fc8240190e113562934e0c020c38.tar.bz2
* gdb.base/longjmp.c, gdb.base/longjmp.exp: New files.
Diffstat (limited to 'gdb/testsuite/gdb.base/longjmp.c')
-rw-r--r--gdb/testsuite/gdb.base/longjmp.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/longjmp.c b/gdb/testsuite/gdb.base/longjmp.c
new file mode 100644
index 0000000..4d69d6d
--- /dev/null
+++ b/gdb/testsuite/gdb.base/longjmp.c
@@ -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;
+}