setjmp() is supposed to save registers including "return address" and "stack pointer" into "jmp_buf". When I compile (both gcc and clang) and debug the following program under x86_64 with glibc, I cannot understand what is in the "jmp_buf" and where "return address" and "stack pointer" are located in the "jmp_buf".
#include <stdio.h>
#include <setjmp.h>
int main()
{
int i;
jmp_buf env;
i = setjmp(env);
printf("i = %d\n", i);
if (i != 0) return;
longjmp(env, 2);
printf("Does this line get printed?\n");
}
When the program stops at a breakpoint before "printf("i = %d\n", i);", I tried gdb functionality: "p/x env"; however I cannot find the "return RIP" and "previous RSP" in this structure (env) which contains __jmpbuf and __saved_mask. Anyone knows how exactly these two functions work and what exactly they save under x86_64 with glibc (I use ubuntu 14.04)?