[Ecls-list] The dreaded embedded debugger

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Tue Feb 22 21:30:35 UTC 2011


Ok, you have the following problems:

1) If you do not start a toplevel there will not be any active restarts.
This is logical: it is your program's responsibility to set them up! So if
you want a function to be able to use ABORT then define an evaluating
function that sets the restart up.

2) You are using cl_eval(...) which does not set up those restarts. ECL
ships with a function, si_safe_eval (ext:safe-eval) which performs
evaluation in a safe way, with a handler for errors that returns a default
value.

3) It is recommended generally to have a catch-all region around your C
code. This sets up a point that protects from unwanted QUIT statements and
sets up a point to jump to in case of stack overflows, memory exhaustion,
etc See http://ecls.sourceforge.net/new-manual/re37.html

4) Instead of c_string_to_object() you might want to use
ecl_read_from_string_safe(s,v) where "v" is the value returned in case of
error condition.

The program, in one possible shape

#include <ecl/ecl.h>

#define READCL(expr) (c_string_to_object(# expr))

int main(int argc, char **argv)
{
       cl_object x;

       cl_boot(1, &argv[0]);

       CL_CATCH_ALL_BEGIN(ecl_process_env()) {

       x = c_string_to_object("(format t \"Hello~%\")");
       cl_print(1,x);
       x = si_safe_eval(3, x, Cnil, Cnil);
       cl_print(1,x);

       // Forces program to halt, reading from stdin
       x = c_string_to_object("(vvvvformat t \"Hello~%\")");
       cl_print(1,x);
       x = si_safe_eval(3, x, Cnil, Cnil);
       cl_print(1,x);

       } CL_CATCH_ALL_END;

       cl_shutdown();
}

The output is fine (notice lack of error messages!)

(FORMAT T "Hello~%") Hello

NIL
(VVVVFORMAT T "Hello~%")
VVVVFORMAT
NIL

-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20110222/b2546d29/attachment.html>


More information about the ecl-devel mailing list