The following code summarizes the problem that I have at the moment. My current thread of execution is as follows, and I am starting up in GCC 4.3.
jmp_buf a_buf; jmp_buf b_buf; void b_helper() { printf("entering b_helper"); if(setjmp(b_buf) == 0) { printf("longjmping to a_buf"); longjmp(a_buf, 1); } printf("returning from b_helper"); return; //segfaults right here } void b() { b_helper(); } void a() { printf("setjmping a_buf"); if(setjmp(a_buf) == 0) { printf("calling b"); b(); } printf("longjmping to b_buf"); longjmp(b_buf, 1); } int main() { a(); }
The above thread of execution creates segfault immediately after returning to b_helper. It is almost as if only the stack stack of the b_helper stack was installed, and the stacks below it are erased.
Can anyone explain why this is happening? I guess this is a GCC optimization that erases unused stack frames or something like that.
Thank.
c ++ gcc segmentation-fault g ++
jameszhao00 Sep 04 '09 at 23:22 2009-09-04 23:22
source share