#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
static void f1(int, int, int, int);
static void f2(void);
static jmp_buf jmpbuffer;
static int globval;
int main(void)
{
int autoval;
register int regival;
volatile int volaval;
static int statval;
globval = 1; autoval = 2; regival = 3; volaval = 4; statval = 5;
if (setjmp(jmpbuffer) != 0) {
printf ("after longjmp: \n");
printf ("globval = %d, autoval = %d, regival = %d, volaval = %d, statval = %d\n",
globval, autoval, regival, volaval, statval);
exit (0);
}
globval = 95; autoval = 96; regival = 97; volaval = 98; statval = 99;
f1(autoval, regival, volaval, statval);
exit (0);
}
static void f1(int i, int j, int k, int l)
{
printf ("in f1():\n");
printf ("globval = %d, autoval = %d, regival = %d, volaval = %d, statval = %d\n", globval, i, j, k, l);
f2();
}
static void f2(void)
{
longjmp(jmpbuffer, 1);
}
[root@centos C]# gcc setlongjmp.c -o setlongjmp
[root@centos C]# ./setlongjmp
in f1():
globval = 95, autuval = 96, regival = 97, volaval = 98, statval = 99
after longjmp:
globval = 95, autoval = 96, regival = 97, volaval = 98, statval = 99
[root@centos C]# ./setlongjmp
in f1():
globval = 95, autuval = 96, regival = 97, volaval = 98, statval = 99
after longjmp:
globval = 95, autoval = 2, regival = 3, volaval = 98, statval = 99
8048476: c7 05 3c 99 04 08 01 movl $0x1,0x804993c
804847d: 00 00 00
8048480: c7 45 f4 04 00 00 00 movl $0x4,0xfffffff4(%ebp)
8048487: c7 05 80 98 04 08 05 movl $0x5,0x8049880
80484ef: c7 05 3c 99 04 08 5f movl $0x5f,0x804993c
80484f6: 00 00 00
80484f9: c7 45 f4 62 00 00 00 movl $0x62,0xfffffff4(%ebp)
8048500: c7 05 80 98 04 08 63 movl $0x63,0x8049880
8048519: c7 44 24 14 63 00 00 movl $0x63,0x14(%esp)
8048520: 00
8048521: 89 5c 24 10 mov %ebx,0x10(%esp)
8048525: c7 44 24 0c 61 00 00 movl $0x61,0xc(%esp)
804852c: 00
804852d: c7 44 24 08 60 00 00 movl $0x60,0x8(%esp)
8048534: 00
8048535: a1 3c 99 04 08 mov 0x804993c,%eax
804853a: 89 44 24 04 mov %eax,0x4(%esp)
804853e: c7 04 24 94 86 04 08 movl $0x8048694,(%esp)
8048545: e8 0e fe ff ff call 8048358 <printf@plt>
80484b6: 89 54 24 14 mov %edx,0x14(%esp)
80484ba: 89 44 24 10 mov %eax,0x10(%esp)
80484be: c7 44 24 0c 03 00 00 movl $0x3,0xc(%esp) 80484c5: 00
80484c6: c7 44 24 08 02 00 00 movl $0x2,0x8(%esp) 80484cd: 00
80484ce: a1 3c 99 04 08 mov 0x804993c,%eax
80484d3: 89 44 24 04 mov %eax,0x4(%esp)
80484d7: c7 04 24 4c 86 04 08 movl $0x804864c,(%esp)
80484de: e8 75 fe ff ff call 8048358 <printf@plt>
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |