To simulate a complete restart of an application (GNU C version 4.1.2 (arm-linux-gnueabi)) including static variable initialization I try to setjmp/longjmp to a gcc pre_init hook function on request. The longjmp in fact reaches the .preinit_array function but then on stepping out it crashes with SIGSEGV.
Any idea why this can go wrong? Should this generally possible? Are there alternative ways to roll an Linux application back to its initial state while being under the control of gdbserver?
Added Source:
static jmp_buf reset_simulation_jumpbuf __attribute__ ((section (".noinit")));
int preinit(int argc, char **argv, char **envp)
{
// at this point no static variables shall be initialized
setjmp(reset_simulation_jumpbuf);
}
// gcc standard linker scripts are calling this function before initialization
__attribute__((section(".preinit_array"))) typeof(preinit) *__preinit = preinit;
int main(void)
{
// at this point all static variables are initialized
do_something();
if (reset)
longjmp(reset_simulation_jumpbuf,1);
}