We are attempting to test student code, and in an effort to automate the process, we'd like to detect if a student's code overflows the stack.
I've met with some success using the libsigsegv library and its corresponding stackoverflow_install_handler. It works brilliantly, until the student's code blows the stack twice.
For example, here's some sample output:
[# ~]$ ledit ./interpreter
-> (use solution)
-> (fun 1 2)
*** Stack overflow detected ***
-> (fun 1 2)
Signal -10
[# ~]
The initial "* Stack overflow detected *" is the desirable output. After blowing the stack for the second time, all I get is an unhelpful "Signal -10" and the program stops execution. I'd like to see the stack overflow detected message again, and let the code continue execution.
In my stack overflow handler, I'm just printing the overflow detection message to stderr and long jumping back to an "awaiting input state" in the interpreter.
Thanks for any help!
EDIT
As per caf's suggestion below, we've added a call to sigsegv_leave_handler() like so:
static void continuation(void *arg1, void *arg2, void *arg3) {
(void)(arg1);
(void)(arg2);
(void)(arg3);
siglongjmp(errorjmp, 1);
}
static void handler(int emergency, stackoverflow_context_t context) {
(void)emergency;
(void)context;
fprintf(stderr, "\n*** Stack overflow detected ***\n");
fflush(stderr);
sigsegv_leave_handler(continuation, NULL, NULL, NULL);
}
However, the output is still the same.