Note that there are some explanatory texts on larger screens.

plurals
  1. POlibsigsegv and responding to a stack overflow
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>For example, here's some sample output:</p> <pre><code>[# ~]$ ledit ./interpreter -&gt; (use solution) -&gt; (fun 1 2) *** Stack overflow detected *** -&gt; (fun 1 2) Signal -10 [# ~] </code></pre> <p>The initial "<strong>* Stack overflow detected *</strong>" 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.</p> <p>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.</p> <p>Thanks for any help!</p> <p><em>EDIT</em></p> <p>As per caf's suggestion below, we've added a call to sigsegv_leave_handler() like so:</p> <pre><code>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); } </code></pre> <p>However, the output is still the same.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload