koji-kojiro / cl-repl

A full-featured repl implementation designed to work with Roswell
GNU General Public License v3.0
153 stars 22 forks source link

Memory Fault When Attempting to Evaluate Any Expression #44

Closed Noammac closed 4 years ago

Noammac commented 5 years ago

Command line:

cl-repl 0.6.4 on Roswell 19.1.10.96, SBCL 1.4.13
(C) 2017-2018 TANI Kojiro <kojiro0531@gmail.com>

CL-USER> (defun hello-world () (format t "Hello, world"))CORRUPTION WARNING in SBCL pid 7904(tid 0x7feb30ce1240):
Memory fault at (nil) (pc=0x7feb304fbc81, sp=0x7feb30766810)
The integrity of this image is possibly compromised.
Continuing with fingers crossed.
Unhandled memory fault at #x0.
 [Condition of type MEMORY-FAULT-ERROR]

Restarts:
 0: [*ABORT] Deduce debugger level.
 1: [*EXIT] Exit CL-REPL.
 2: [*RETRY] Try evaluating again.

Backtrace:
 0: (SB-SYS:MEMORY-FAULT-ERROR #<unused argument> #.(SB-SYS:INT-SAP #X00000000))
 1: ("foreign function: call_into_lisp")
 --more--

Usage:
  Ctrl+r: select restart. Ctrl+t: show backtrace.

[1]CL-USER> 

Traceback:

0: (SB-SYS:MEMORY-FAULT-ERROR #<unused argument> #.(SB-SYS:INT-SAP #X00000000))
 1: ("foreign function: call_into_lisp")
 2: ("foreign function: funcall2")
 3: ("foreign function: handle_trap")
 4: ("foreign function: #x418D9F")
 5: (CL-REPL::READ-INPUT)
 6: (CL-REPL::READ-EVAL-PRINT :LEVEL 0)
 7: (CL-REPL::REPL)
 8: ((LAMBDA (CONIUM::HOOK CONIUM::FUN) :IN "/home/noammac/.roswell/lisp/quicklisp/dists/quicklisp/s
oftware/conium-20180831-git/sbcl.lisp") #<FUNCTION CL-REPL::DEBUGGER> #<FUNCTION CL-REPL::REPL>)
 9: (CL-REPL:MAIN NIL :SHOW-LOGO NIL)
10: (SB-INT:SIMPLE-EVAL-IN-LEXENV (APPLY (QUOTE ROS.SCRIPT.ROS-REPL.3724301531::MAIN) ROSWELL:*ARGV*
) #<NULL-LEXENV>)
11: (SB-INT:SIMPLE-EVAL-IN-LEXENV (ROSWELL:QUIT (APPLY (QUOTE ROS.SCRIPT.ROS-REPL.3724301531::MAIN) 
ROSWELL:*ARGV*)) #<NULL-LEXENV>)
12: (EVAL-TLF (ROSWELL:QUIT (APPLY (QUOTE ROS.SCRIPT.ROS-REPL.3724301531::MAIN) ROSWELL:*ARGV*)) NIL
 NIL)
13: ((LABELS SB-FASL::EVAL-FORM :IN SB-INT:LOAD-AS-SOURCE) (ROSWELL:QUIT (APPLY (QUOTE ROS.SCRIPT.RO
S-REPL.3724301531::MAIN) ROSWELL:*ARGV*)) NIL)
 0: (SB-SYS:MEMORY-FAULT-ERROR #<unused argument> #.(SB-SYS:INT-SAP #X00000000))
 1: ("foreign function: call_into_lisp")
 2: ("foreign function: funcall2")
 3: ("foreign function: handle_trap")
 4: ("foreign function: #x418D9F")
 5: (CL-REPL::READ-INPUT)
T T :EXTERNAL-FORMAT :DEFAULT)
/ros-repl" {10029B7163}>)
20: (ROSWELL:SCRIPT "/home/noammac/.roswell/bin/ros-repl")
IL)))
mmac/.roswell/bin/ros-repl") (:QUIT NIL)))) #<NULL-LEXENV>)
pl") (:QUIT NIL)))))
-repl\")(:quit ())))")))
25: (SB-IMPL::TOPLEVEL-INIT)
26: ((FLET SB-UNIX::BODY :IN SAVE-LISP-AND-DIE))
27: ((FLET "WITHOUT-INTERRUPTS-BODY-34" :IN SAVE-LISP-AND-DIE))
28: ((LABELS SB-IMPL::RESTART-LISP :IN SAVE-LISP-AND-DIE))
koji-kojiro commented 5 years ago

I think it is caused by cl-readline. Can you check the library works properly? Some sample codes could be found at the wiki page of cl-readline.

Noammac commented 5 years ago

vinadrel/cl-readline-example works with some issues, such as C-c not being handled and C-o only writing inserted text.

koji-kojiro commented 5 years ago

I think that is expected behavior, though I just took a quick look at the code. How about syntax highlighting? Please check if it works.

koji-kojiro commented 5 years ago

Also, let me know what kind of readline library you use.

Noammac commented 5 years ago

Syntax highlighting works.

I use cl-readline as installed by quicklisp.

On Sat, 26 Jan 2019 at 16:45, TANI Kojiro notifications@github.com wrote:

Also, let me know what kind of readline library you use.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/koji-kojiro/cl-repl/issues/44#issuecomment-457836724, or mute the thread https://github.com/notifications/unsubscribe-auth/ASpZq5QiMvGZyUcbd9j5E4GGTo2ZNivYks5vHGoYgaJpZM4aT390 .

koji-kojiro commented 5 years ago

Sorry, I misunderstood. No idea at this time... How did you install cl-repl?

Noammac commented 5 years ago

Using roswell. ros install koji-kojiro/cl-repl

koji-kojiro commented 5 years ago

hmm... I'm sure that is problem around cl-readline, but I don't know what goes wrong...

koji-kojiro commented 5 years ago

@Noammac Would you mind tryting the following?

  1. $ ros install koji-kojiro/cl-readline-test
  2. $ cl-readline-test

cl-readline-test is a simple application for investigation. That just echoes inputed text. Please report if it works correctly or not. Also please let me show the compilation message appearing while executing ros install ~.

Noammac commented 5 years ago

Installation message:

Installing from github koji-kojiro/cl-readline-test
To load "cl-readline-test":
  Load 1 ASDF system:
    cl-readline-test
; Loading "cl-readline-test"
..................................................
[package cl-readline-test]
; compiling file "/home/noammac/.roswell/local-projects/koji-kojiro/cl-readline-test/package.lisp" (written 01 FEB 2019 07:22:23 PM):
; compiling (IN-PACKAGE :CL-USER)
; compiling (DEFPACKAGE :CL-READLINE-TEST ...)

; wrote /home/noammac/.cache/common-lisp/sbcl-1.4.13-linux-x64/home/noammac/.roswell/local-projects/koji-kojiro/cl-readline-test/package-tmpJAIDFZTC.fasl
; compilation finished in 0:00:00.001
; compiling file "/home/noammac/.roswell/local-projects/koji-kojiro/cl-readline-test/main.lisp" (written 01 FEB 2019 07:22:23 PM):
; compiling (IN-PACKAGE :CL-READLINE-TEST)
; compiling (DEFUN MAIN ...)

; wrote /home/noammac/.cache/common-lisp/sbcl-1.4.13-linux-x64/home/noammac/.roswell/local-projects/koji-kojiro/cl-readline-test/main-tmp8V3J6PE9.fasl
; compilation finished in 0:00:00.001
[1/3] System 'cl-readline-test' found. Loading the system..
[2/3] Processing build-hook..
[3/3] Attempting to install the scripts in roswell/ subdirectory of the system...
Found 1 scripts: cl-readline-test
/home/noammac/.roswell/bin/cl-readline-test
up to date. stop

cl-readline-test:

* Ctrl-D to exit.
> This is a test.
This is a test.
> ω
ω
> bye.

Not a hitch with cl-readlne-test

koji-kojiro commented 5 years ago

hmm... Could you delete ~/.roswell/local-project/koji-kojiro/cl-repl and then re-install cl-repl? Or, delete .roswell and re-install everything if you don't mind.

Noammac commented 5 years ago

rm -rfd .roswell and reinstalled. I still get the error.

koji-kojiro commented 5 years ago

Sorry, I found that I misread the backtraces first you showed me. The error is not caused by cl-readline, though I'm not sure where it comes from...

ryukinix commented 5 years ago

Same here.

luksamuk commented 5 years ago

Same here. I noticed that disabling syntax highlighting makes everything turn back into normal.

koji-kojiro commented 5 years ago

Thank you for the report. Could you explain in more detail? How did you disable syntax highlighting?

luksamuk commented 5 years ago

Of course. Sorry for the lack of information. I disabled syntax highlighting from .replrc. Here is the configuration I use currently:


(in-package :repl-user)

(color-scheme "off")
(disable-syntax)

I also tried removing both cl-repl and ros-repl; didn't work. If I comment out the (disable-syntax) line, anything evaluated breaks.

EDIT: Turning on or off the color scheme doesn't seem to affect the behaviour of the program.

ackalker commented 5 years ago

I'm having the same issue on Void Linux, packages: sbcl-1.5.2_1, libreadline8-8.0.000_1, building cl-repl directly from within system SBCL: (ql:quickload :cl-repl) from quicklisp/local-projects.

To try and find out what's going on, I did the following:

$ sbcl
This is SBCL 1.5.2, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (ql:quickload '(:swank :cl-repl))
[...]
* (swank:create-server)
;; Swank started at port: 4005.
4005

At this point, I setup tracing for functions cl-repl::read-input and callees, then started the repl without the debugger hooks (important! otherwise SLIME debugger has no access), then I tried to evaluate 42 in cl-repl, exiting the debugger on each break:

* (in-package :cl-repl)
#<PACKAGE "CL-REPL">
* WARNING: System definition file #P"/home/miki/quicklisp/dists/quicklisp/software/cl-ppcre-20180831-git/cl-ppcre.asd" contains definition for system "cl-ppcre-test". Please only define "cl-ppcre" and secondary systems with a name starting with "cl-ppcre/" (e.g. "cl-ppcre/test") in that file.
WARNING:
   redefining THREAD-FOR-EVALUATION (#<STRUCTURE-CLASS SWANK::MULTITHREADED-CONNECTION>
                                     #<SB-MOP:EQL-SPECIALIZER :FIND-EXISTING>) in DEFMETHOD
* (repl)
CL-REPL> 42CORRUPTION WARNING in SBCL pid 6874(tid 0x7fb3b67102c0):
Memory fault at (nil) (pc=0x7fb3b5d0edf0, fp=0x7fb3b5d31960, sp=0x7fb3b5f67210) tid 0x7fb3b67102c0
The integrity of this image is possibly compromised.
Continuing with fingers crossed.
CL-REPL> 42CORRUPTION WARNING in SBCL pid 6874(tid 0x7fb3b67102c0):
Memory fault at (nil) (pc=0x7fb3b5d0edf0, fp=0x7fb3b5d31960, sp=0x7fb3b5f67210) tid 0x7fb3b67102c0
The integrity of this image is possibly compromised.
Continuing with fingers crossed.

In Emacs, I switched to the debugger's trace window with C-c T and fetched all traces. This is what I got:

Traced specs (5)                                  [refresh]
                                                  [untrace all]

  [untrace] cl-repl::check-input
  [untrace] cl-repl::line-continue-p
  [untrace] cl-repl::read-input
  [untrace] cl-repl::read-input1
  [untrace] cl-readline:readline

Trace collection status (7/7)                     [refresh]
                                                  [clear]

   0 - cl-repl::read-input
     | < :EXITED-NON-LOCALLY
   1 `--- cl-repl::read-input1
          < :EXITED-NON-LOCALLY
   2 - cl-repl::read-input
     | < :EXITED-NON-LOCALLY
   3 `--- cl-repl::read-input1
          < :EXITED-NON-LOCALLY
   4 - cl-repl::read-input
     | < SWANK-TRACE-DIALOG:STILL-INSIDE
   5 `--- cl-repl::read-input1
        | < SWANK-TRACE-DIALOG:STILL-INSIDE
   6    `--- cl-readline:readline
             > :PROMPT
             > "CL-REPL> "
             > :ADD-HISTORY
             > T
             < SWANK-TRACE-DIALOG:STILL-INSIDE

I don't see anything strange here, except of course the non-local exits. Could it be that the string with ANSI escapes is tripping up readline? I guess this maybe goes beyond lisp-land and needs a look with GDB or something, unless we can reproduce it with some kind of cl-readline test.

ackalker commented 5 years ago

Same story when I try to evaluate (exit-with-prompt) at SBCL toplevel:

   0 - cl-repl::exit-with-prompt
     | < :EXITED-NON-LOCALLY
   1 `--- cl-readline:readline
          > :PROMPT
          > "Do you really want to exit ([y]/n)? "
          < :EXITED-NON-LOCALLY
ackalker commented 5 years ago

More testing: it appears that the system somehow is searching for libreadline.so.6.3, eventually falling back to libreadline.so, which on my system is a symlink to libreadline.so.8.0. I'm guessing that my libreadline is simply too new for cl-readline (incompatible ABI perhaps). Any opinions?

EDIT: Hm, maybe not, vindarel/cl-readline-example works without issues.

fukamachi commented 5 years ago

Same here. I still don't get why, but I found that it doens't appear when cl-repl isn't loaded.

Load only cl-readline and try rl:readline:

$ ros -Q -L sbcl -s cl-readline --eval '(rl:readline :prompt "CL-USER> ")'
CL-USER> <-- RETURN
$ # nothing happends

Load cl-repl and try rl:readline.

$ ros -Q -L sbcl -s cl-repl --eval '(rl:readline :prompt "CL-USER> ")'
CL-USER> <-- RETURN
CORRUPTION WARNING in SBCL pid 12433(tid 0x7fff8994a380):
Memory fault at 0x4 (pc=0x722d71, sp=0x4ff510)
The integrity of this image is possibly compromised.
Continuing with fingers crossed.

debugger invoked on a SB-SYS:MEMORY-FAULT-ERROR in thread
#<THREAD "main thread" RUNNING {10005505B3}>:
  Unhandled memory fault at #x4.

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

restarts (invokable by number or by possibly-abbreviated name):
  0: [CONTINUE] Ignore runtime option --eval "(ros:run '((:eval\"(ros:quicklisp)\")(:load\"/Users/fukamachi/.roswell/init.lisp\")(:system \"cl-repl\")(:eval \"(rl:readline :prompt \\\"CL-USER> \\\")\")(:quit)))".
  1: [ABORT   ] Skip rest of --eval and --load options.
  2:            Skip to toplevel READ/EVAL/PRINT loop.
  3: [EXIT    ] Exit SBCL (calling #'EXIT, killing the process).

("bogus stack frame")
0]
fukamachi commented 5 years ago

I found that (rl:register-function :redisplay #'redisplay-with-highlight) in enable-syntax (src/highlight.lisp) doing something bad, which is called as top-level form in src/main.lisp.

hellerve commented 5 years ago

FWIW, I just tried syntax highlighting in my own SBCL REPL, and was able to narrow the problem down to redisplaying as well. It seems like it doesn’t matter what the drop-in replacement for rl:redisplay does (I even tried it with an empty defun), the memory fault is still triggered.

If this is a new problem, this sounds to me like rl_redisplay now does something that _rl_update_final depends on, and that it didn’t use to do. I’m not quite sure what it is, and the readline codebase looks a bit too messy for me to investigate this deeply.

hellerve commented 5 years ago

Another fun property that I found while debugging my REPL: the error is not triggered when I run an old version of my REPL and load a new version—then the highlighting works as expected.

I suppose rl_redisplay does some sort of setup upon its first call that the rest of the library depends on since 8.0.

ryukinix commented 4 years ago

Hey! I have a solution, guys!

https://github.com/koji-kojiro/cl-repl/pull/51

Take a look on that PR.

hellerve commented 4 years ago

Thanks @ryukinix! I verified that this solves the bug for me personally :)