I have a nice and complicated crash

I’m using: SWI-Prolog version threaded, 64 bits, version 9.3.20-DIRTY

I put the following code in the console and first an errormessage comes up which is expected but then I use the cursor up to regain the same input again and press enter (using the cursor makes the difference).

(ins)$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.20-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

(ins)?- TERM = forall( ( current_input(_4504),repeat,read_string(_4504,' \n','',_11990,_11992),meta( _OX)),(writeln(_3548),_3554\== -1)), TERM.
ERROR: Unknown procedure: meta/1
ERROR: In:
ERROR:   [15] meta(_14818)
ERROR:   [14] '<meta-call>'(user:(...,...)) <foreign>
ERROR:   [13] forall(user:(...,...),user:(...,...)) at /usr/local/lib/swipl/boot/apply.pl:52
ERROR:   [12] '<meta-call>'(user:user: ...) <foreign>
ERROR:   [11] toplevel_call(user:user: ...) at /usr/local/lib/swipl/boot/toplevel.pl:1319
   Exception: (15) meta(_1924) ? abort
% Execution Aborted
(ins)?-

So far so good, now the cursor thingy (cursor up, enter):

(ins)?- TERM = forall( ( current_input(_4504),repeat,read_string(_4504,' \n','',_11990,_11992),meta( _OX)),(writeln(_3548),_3554\== -1)), TERM.
(ins)|: 

Unexpectedly the code compiles and I come into an input request.
When I now input “abc def” and press enter I get the crash:

(ins)|: abc def

ERROR: Unknown procedure: meta/1
ERROR: In:
ERROR:   [15] meta(_2902)
ERROR:   [14] '<meta-call>'(user:(...,...)) <foreign>
ERROR:   [13] forall(user:(...,...),user:(...,...)) at /usr/local/lib/swipl/boot/apply.pl:52
ERROR:   [12] '<meta-call>'(user:user: ...) <foreign>
ERROR:   [11] toplevel_call(user:user: ...) at /usr/local/lib/swipl/boot/toplevel.pl:1319
   Exception: (15) meta(_1242) ? depth

ERROR: Received fatal signal 11 (segv)
Time: Fri Oct 17 09:57:12 2025
Inferences: 536425
Thread: 1 (main)
C-stack trace labeled "crash":
  [0] save_backtrace() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/os/pl-cstack.c:337 [0x7fde52944a9e]
  [1] sigCrashHandler() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/os/pl-cstack.c:937 [0x7fde52944b69]
  [2] __restore_rt() at sigaction.c:? [0x7fde5266ede0]
  [3] wsizeofInd() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-data.h:310 [0x7fde5290b0dc]
  [4] firstClause___LD() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-index.c:783 [0x7fde5290bb58]
  [5] PL_next_solution___LD() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-vmi.c:3429 [0x7fde52839245]
  [6] PL_call_predicate() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-fli.c:4534 [0x7fde5291674f]
  [7] setPrintOptions() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-trace.c:641 [0x7fde528ae2c6]
  [8] traceAction() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-trace.c:750 [0x7fde528b1ddc]
  [9] PL_next_solution___LD() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-vmi.c:5118 [0x7fde52836b3d]
  [10] query_loop() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-pro.c:179 [0x7fde5288ec91]
  [11] prologToplevel() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-pro.c:655 [0x7fde5288f73d]
  [12] PL_toplevel() at /home/ox_external_source/sources_external/swi-prolog-github/swipl-devel/src/pl-fli.c:4999 [0x7fde5291788e]
  [13] swipl(+0x10b5) [0x556e9c4a60b5]
  [14] __libc_start_main() at ./csu/../csu/libc-start.c:308 [0x7fde52659d7a]
  [15] swipl(+0x10fa) [0x556e9c4a60fa]


PROLOG STACK (without arguments):
  [17] system:$set_debugger_write_options/1 <no clause>
  [16] system:$c_call_prolog/0 [PC=0 in top query clause]
  [15] meta/1 <no clause>
  [14] system:<meta-call>/1 [PC=19 in clause -1]
  [13] $apply:forall/2 [PC=6 in clause 1]
  [12] system:<meta-call>/1 [PC=6 in clause -1]
  [11] $toplevel:toplevel_call/1 [PC=3 in clause 1]
  [10] $toplevel:stop_backtrace/2 [PC=4 in clause 1]
  [9] $tabling:$wfs_call/2 [PC=17 in clause 1]
  [7] $toplevel:$execute_goal2/3 [PC=31 in clause 1]


PROLOG STACK (with arguments; may crash if data is corrupted):
     [17] Speicherzugriffsfehler

Just in case it is not reproducible: This all happens on an ordinary lxterminal 0.4.0 and prolog configured to use readline (vi bindings). But I guess this is a caching thing.

Thanks for reporting. Looks like some memory management issue. But, we are at 9.3.32 and the GNU readline package for SWI-Prolog is discontinued. Works fine in 9.3.32 under AddressSanitizer.

P.s. That said, 9.3.32 has a serious memory management issue in the swipl-win console. Fixe in the git version.

Sad. I hope I get rlwrap wrapped around swi prolog.

If you want vi,

?- el_bind(user_input, ['-v']).

To use that everywhere and always, add this to your init.pl:

:- multifile editline:el_setup/1.
editline:el_setup(Stream) :-
    el_bind(Stream, ['-v']).

Or, add this to ~/.editrc (or simply bind -v to address all programs using editline).

  swipl:bind -v

rlwrap works to some extend. I use it with other Prolog systems that have no built-in commandline editing. This notably lacks Prolog specific completion though.

1 Like