akl*_*klt 2 lisp sbcl common-lisp unhandled-exception
我是一个lisp noob尝试使用sbcl v1.0.50学习lisp.
我正在编写一个简单的记录器并遇到一个我不理解的内存故障,但这似乎与我编译脚本的方式有关.我把它归结为以下内容:
=== logger.lisp ===
(defparameter *log-stream* (open "/tmp/global-log"
:direction :output
:if-does-not-exist :create
:if-exists :append))
Run Code Online (Sandbox Code Playgroud)
=== main.lisp ===
(load "logger.lisp")
(defun main ()
(format *log-stream* "Hello world~%"))
Run Code Online (Sandbox Code Playgroud)
== == compile.lisp
#! /usr/bin/sbcl --script
(load "main.lisp")
(save-lisp-and-die "program" :toplevel #'main :executable t)
Run Code Online (Sandbox Code Playgroud)
当我编译并运行程序时,它会崩溃:
> ./compile.lisp
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into foo:
writing 6352 bytes from the read-only space at 0x20000000
writing 4064 bytes from the static space at 0x20100000
writing 43057152 bytes from the dynamic space at 0x1000000000
> ./program
CORRUPTION WARNING in SBCL pid 21860(tid 140737353914112):
Memory fault at f6977000 (pc=0x1000036365, sp=0x7ffff6b7f8d0)
The integrity of this image is possibly compromised.
Continuing with fingers crossed.
unhandled SB-SYS:MEMORY-FAULT-ERROR in thread #<SB-THREAD:THREAD
"initial thread" RUNNING
{10029118D1}>:
Unhandled memory fault at #x7FFFF6977000.
0: (SB-DEBUG::MAP-BACKTRACE
#<CLOSURE (LAMBDA #) {100291A3C9}>
:START
0
:COUNT
128)
1: (BACKTRACE 128 #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDERR* {100001CEB1}>)
2: (SB-DEBUG::DEBUGGER-DISABLED-HOOK
#<SB-SYS:MEMORY-FAULT-ERROR {10029180E1}>
#<unavailable argument>)
3: (SB-DEBUG::RUN-HOOK
*INVOKE-DEBUGGER-HOOK*
#<SB-SYS:MEMORY-FAULT-ERROR {10029180E1}>)
4: (INVOKE-DEBUGGER #<SB-SYS:MEMORY-FAULT-ERROR {10029180E1}>)
5: (ERROR SB-SYS:MEMORY-FAULT-ERROR :ADDRESS 140737330507776)
6: (SB-SYS:MEMORY-FAULT-ERROR)
7: ("foreign function: #x4174A0")
8: ("foreign function: #x417580")
9: (SB-IMPL::OUTPUT-BYTES/UTF-8
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>
"AAAA"
NIL
0
4)
10: (SB-IMPL::FD-SOUT
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>
"AAAA"
0
4)
11: (SB-IMPL::%WRITE-STRING
"AAAA"
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>
0
NIL)
12: ((LAMBDA (STREAM &OPTIONAL &REST SB-FORMAT::ARGS))
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>)
13: (FORMAT
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>
#<FUNCTION (LAMBDA #) {100002F6C9}>)
14: ((FLET #:WITHOUT-INTERRUPTS-BODY-[RESTART-LISP]30))
15: ((LABELS SB-IMPL::RESTART-LISP))
unhandled condition in --disable-debugger mode, quitting
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一段时间来了解发生了什么,但是嗯.帮助将不胜感激!
安德斯
您打开一个流然后转储图像.
然后启动转储的图像并尝试写入流.
您不能指望流在程序运行之间保持打开状态,或者在启动映像时以某种方式自动打开.
如果启动图像,请打开流然后写入该图像.
另请参见宏WITH-OPEN-FILE.
您可能还想在SBCL邮件列表上讨论这个问题.SBCL应该提供更好的错误报告.
通常,您需要了解转储图像的工作方式以及限制条件.通常不能:
和更多...