1

我正在使用 SBCL。当我的程序出现问题时,SBCL 将打印一长串回溯信息。有时这很烦人,我必须来回滚动以找出错误消息是什么。我可以自定义错误输出(例如,缩短回溯列表)吗?

4

2 回答 2

2

见:*backtrace-frame-count*

于 2013-10-01T09:59:56.513 回答
1

我用 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)我正在使用 SBCL 1.0.57.0,如果没有被询问,它不会给出任何堆栈跟踪(虽然使用 slime 会导致堆栈跟踪),sbcl 崩溃并打印完整堆栈跟踪的唯一情况是当您使用(sb-ext:disable-debugger)或提供顶级参数时sbcl --disable-debugger

SBCL(无(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(带(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

就 SBCL 手册而言,没有办法影响 SBCL 调试器接口的预定义行为,但您可以通过设置提供自己的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)
~:
于 2013-10-01T09:41:18.920 回答