Pergunta

I'm using SBCL. When something goes wrong in my program, SBCL will print a long list of back trace informations. This is annoying sometimes, and I have to scroll back and back to find out what the error message was. Can I customize the error outputs(e.g., shorten the back trace list)?

Foi útil?

Solução 2

I did some experimenting with sbcl:

(defun crash-big-stack (&optional (c 20))
       (if (= c 0)
           (error "crash boooooom")
                       (another-crash (- c 1))))

(defun another-crash (&optional c)
       (crash-big-stack c))

1) I am using SBCL 1.0.57.0 which wont give any stacktrace if not asked (using slime though will result in a stacktrace), the only scenario where sbcl crashes and prints the complete stacktrace is when you either use (sb-ext:disable-debugger) or provide the toplevel argument sbcl --disable-debugger

SBCL (without (sb-ext:disable-debugger)):

* (crash-big-stack)

debugger invoked on a SIMPLE-ERROR in thread
#<THREAD "main thread" RUNNING {1002978CA3}>:
  crash boooooom

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

(CRASH-BIG-STACK 0)
0]

SBCL (with (sb-ext:disable-debugger)):

(crash-big-stack)
unhandled SIMPLE-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING
                                    {1002978CA3}>:
  crash boooooom

0: (SB-DEBUG::MAP-BACKTRACE
    #<CLOSURE (LAMBDA # :IN BACKTRACE) {100465352B}>
    :START
    0
    :COUNT
    128)
1: (BACKTRACE 128 #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDERR* {1000169AE3}>)
2: (SB-DEBUG::DEBUGGER-DISABLED-HOOK
    #<SIMPLE-ERROR "crash boooooom" {1004651C23}>
    #<unavailable argument>)
3: (SB-DEBUG::RUN-HOOK
    *INVOKE-DEBUGGER-HOOK*
    #<SIMPLE-ERROR "crash boooooom" {1004651C23}>)
4: (INVOKE-DEBUGGER #<SIMPLE-ERROR "crash boooooom" {1004651C23}>)
5: (ERROR "crash boooooom")
6: (CRASH-BIG-STACK 0)
7: (SB-INT:SIMPLE-EVAL-IN-LEXENV (CRASH-BIG-STACK) #<NULL-LEXENV>)
8: (EVAL (CRASH-BIG-STACK))
9: (INTERACTIVE-EVAL (CRASH-BIG-STACK) :EVAL NIL)
10: (SB-IMPL::REPL-FUN NIL)
11: ((LAMBDA () :IN SB-IMPL::TOPLEVEL-REPL))
12: (SB-IMPL::%WITH-REBOUND-IO-SYNTAX
     #<CLOSURE (LAMBDA # :IN SB-IMPL::TOPLEVEL-REPL) {100450355B}>)
13: (SB-IMPL::TOPLEVEL-REPL NIL)
14: (SB-IMPL::TOPLEVEL-INIT)
15: ((FLET #:WITHOUT-INTERRUPTS-BODY-236911 :IN SAVE-LISP-AND-DIE))
16: ((LABELS SB-IMPL::RESTART-LISP :IN SAVE-LISP-AND-DIE))

unhandled condition in --disable-debugger mode, quitting

As far as the SBCL manual goes, there is no way to influence the predefined behavior of the SBCL debugger interface, but you can provide your own by setting sb-ext:*invoke-debugger-hook*

* (defun crash-big-stack (&optional (c 20))
       (if (= c 0)
           (error "crash boooooom")
           (let ((waste (another-crash (- c 1))))
         (+ waste 42))))

CRASH-BIG-STACK
* (defun another-crash (&optional c)
       (crash-big-stack c))

ANOTHER-CRASH
* (setf sb-ext:*invoke-debugger-hook* #'(lambda(&rest args) (sb-ext:exit)))

#<FUNCTION (LAMBDA (&REST ARGS)) {10045CEF1B}>
* (crash-big-stack)
~:

Outras dicas

See: *backtrace-frame-count*.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top