我可以自定义常见lisp的错误输出格式吗?

时间:2013-09-30 15:59:05

标签: debugging common-lisp sbcl

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

2 个答案:

答案 0 :(得分:2)

请参阅:*backtrace-frame-count*

答案 1 :(得分: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崩溃并打印完整堆栈跟踪的唯一情况是当你使用{{1或者提供顶级参数(sb-ext:disable-debugger)

SBCL(不含sbcl --disable-debugger):

(sb-ext:disable-debugger)

SBCL(* (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] ):

(sb-ext:disable-debugger)

就SBCL手册而言,无法影响SBCL调试器界面的预定义行为,但you can provide your own设置(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

sb-ext:*invoke-debugger-hook*