سؤال

I'm learning gdb debugger and one question I cannot answer is: new function calls result in additional stack frames allocated for them and call stack grows downward; stack frame is deallocated and returned to unused memory. is it possible that a frame in the middle of the stack be deleted and returned to memory? can go to statement or longjmp function make this happen?

Many thanks.

هل كانت مفيدة؟

المحلول

No, frame in the middle can not be deleted, because call stack is a stack. Only a stack pointer pointing to top of a stack (and optionally frame pointer that points to beginning of last frame) are maintained. As frame is "deleted" (return from function), only these pointers are moved and next allocated frame will overwrite this.

This thread (and few others) explains why longjmp can't violate this behavior. In short, setjmp stores frame position, but if frame itself has been overwritten, this fails. And goto can't jump to a different function.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top