Stack from the middle of the stack

I am studying the gdb debugger, and one question I cannot answer is: new function calls lead to additional stack frames allocated for them, and the call stack grows down; the stack stack is freed and returned to unused memory. Is it possible that the frame in the middle of the stack will be deleted and returned to memory? can go to a statement or a longjmp function to make this happen?

Many thanks.

+4
source share
1 answer

No, the frame in the middle cannot be deleted, because the call stack is a stack. Only the stack pointer pointing to the top of the stack is supported (and, optionally, the frame pointer pointing to the beginning of the last frame). Since the frame is “deleted” (return from the function), only these pointers move and the next highlighted frame overwrites it.

This thread (and several others) explains why longjmp cannot break this behavior. In short, setjmp retains the position of the frame, but if the frame itself was overwritten, this fails. And goto cannot go to another function.

+3
source

Source: https://habr.com/ru/post/1531449/


All Articles