[Larceny-users] recursive lists and C-c problems

David Rush kumoyuki at gmail.com
Mon Dec 8 16:06:02 EST 2008


2008/12/8 Marco Maggi <marco.maggi-ipsu at poste.it>
> "will at ---" wrote:
> >Marco Maggi wrote:
>
> >> After hitting C-c, I see that the debugger is here
> >> and I can exit it with "q". And I am left with a prompt?
> >
> >Yes.  It isn't a very useful prompt, since nothing is
> >in scope, but it's a prompt.
>
> Nothing is in scope until I issue "(import (rnrs))",
> then I do what I want with escalated privileges.

As I said earlier, if you're running setuid, you should have
*thoroughly* debugged your code. Then you will not hit the prompt.

> It would suffice to have a command line switch that
> makes the process exit whenever an exception is not
> blocked.

How about installing your own error-handler that just exits the
program? There's a really simple API for this. You could minimally
just use the code:

     (error-handler (lambda _ (exit)))

and get your result. Which is not very helpful because is you haven't
debugged sufficiently that you are still getting errors which
terminate the program, you generally would like to know what went
wrong. Hence the following code (which is part of my Larceny standard
prelude):

    (require 'inspect-cont)
    (define (batch/last-chance-handler puts)
     (lambda e
       (define (display-line s)
         (puts (with-output-to-string
                 (lambda() (write s)))))

       (display-line `(lastchance error handler ,e))

       (let* ((error-text
               (call-with-output-string (lambda (p) (decode-error e p))))
              (stacktrace (current-continuation-structure))
              (inspector (make-continuation-inspector stacktrace))

              (summarize-frame
               (lambda (count inspector . prefix)
                 (let* ((frame (inspector 'get))
                        (code  (frame 'code))
                        (class (code 'class))
                        (expr  (code 'expression))
                        (proc  (code 'procedure)))
                   (display-line
                    `(frame , at prefix ,class
                            ,@(case class
                                ((system-procedure) '())
                                ((interpreted-primitive) (procedure-name proc))
                                ((interpreted-expression) expr)
                                ((compiled-procedure) (procedure-name proc))
                                (else '())))
                    ))))

              (backtrace
               (lambda (count inspector)
                 (let loop ((c (inspector 'clone)))
                   (let ((f (c 'get)))
                     (if (f 'same? (inspector 'get))
                         (summarize-frame 0 c "=> ")
                         (summarize-frame 0 c "   ")))
                   (if (c 'down)
                       (loop c))
                   )))
              )
         (display-line `(decoded error ,error-text))
         (backtrace 0 inspector)
         (exit 0)
         )))

    (define (install-lastchance puts)
      (error-handler (batch/last-chance-handler puts))

To use this fragment, call:

    (install-lastchance puts-function)

where puts-function takes a string and does something appropriate with it.

david
--
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt



More information about the Larceny-users mailing list