BBCSDL icon indicating copy to clipboard operation
BBCSDL copied to clipboard

Segfault when loading program from the command line in console mode (Linux)

Open mike632t opened this issue 1 year ago • 2 comments

After building the Linux console version of the BBC BASIC interpreter I found that loading an ASCII source file from the command line resulted in a segfault.

Building using make:

~/BBCSDL$ cd console/linux/
~/BBCSDL/console/linux$ 
~/BBCSDL/console/linux$ make 
gcc -Wall -I ../../include -I ../../../BBCSDL/include -c -O2 ../../src/bbmain.c -o bbmain.o
gcc -Wall -I ../../include -I ../../../BBCSDL/include -c -O2 ../../src/bbexec.c -o bbexec.o
gcc -Wall -I ../../include -I ../../../BBCSDL/include -Wno-array-bounds -c -O2 ../../src/bbeval.c -o bbeval.o
gcc -Wall -I ../../include -I ../../../BBCSDL/include -c -Os ../../src/bbasmb_x86_64.c -o bbasmb.o
nasm -f elf64 -s ../../../BBCSDL/src/bbdata_x86_64.nas -o bbdata.o
gcc -Wall -I ../../include -I ../../../BBCSDL/include -Wno-array-bounds -Wno-unused-result -c -Os ../../src/bbccos.c -o bbccos.o
gcc -Wall -I ../../include -I ../../../BBCSDL/include -Wno-array-bounds -Wno-unused-result -c -Os ../../src/bbccon.c -o bbccon.o
gcc -Wall -I ../../include -I ../../../BBCSDL/include bbmain.o bbexec.o bbeval.o bbasmb.o bbdata.o bbccos.o bbccon.o -L . -L/usr/include -ldl -lm -lrt -pthread \
-o bbcbasic -Wl,-s -Wl,-R,'$ORIGIN'
cp bbcbasic ../../
~/BBCSDL/console/linux$

Display the test program:

~/BBCSDL/console/linux$ cd ../..
~/BBCSDL$
~/BBCSDL$ cat new.bbc 
REM My first program
PRINT "BBB   BBB    CCC"
WAIT 100
PRINT "B  B  B  B  C   "
WAIT 100
PRINT "BBB   BBB   C   "
WAIT 100
PRINT "B  B  B  B  C   "
WAIT 100
PRINT "BBB   BBB    CCC"
END
~/BBCSDL$

Attempt to run the test program from the command line:

~/BBCSDL$ ./bbcbasic new.bbc 
Segmentation fault
~/BBCSDL$

Attempt to load the program from the command line:

~/BBCSDL$ ./bbcbasic -load new.bbc 
BBC BASIC for Linux Console v0.45
(C) Copyright R. T. Russell, 2023
Segmentation fault
~/BBCSDL$

Loading the program from the interpreter works:

~/BBCSDL$ ./bbcbasic
BBC BASIC for Linux Console v0.45
(C) Copyright R. T. Russell, 2023
>LOAD "new"
>LIST
    1 REM My first program
    2 PRINT "BBB   BBB    CCC"
    3 WAIT 100
    4 PRINT "B  B  B  B  C   "
    5 WAIT 100
    6 PRINT "BBB   BBB   C   "
    7 WAIT 100
    8 PRINT "B  B  B  B  C   "
    9 WAIT 100
   10 PRINT "BBB   BBB    CCC"
   11 END
>

It is still pretty cool though. I wonder if it will compile on VMS...?

mike632t avatar Jan 02 '24 16:01 mike632t

After building the Linux console version of the BBC BASIC interpreter I found that loading an ASCII source file from the command line resulted in a segfault.

BBC BASIC only supports loading tokenised (binary internal format) files from the command line. You are giving it a plain-text file which won't work. I agree that ideally it shouldn't segfault as a result, but it can't work.

It is still pretty cool though. I wonder if it will compile on VMS...?

It relies on some GCC/Clang extensions which may not be supported by the compiler. Also you would need to do something about the bbdata_xxx_xxx source file because that is CPU-dependent. If you really wanted to attempt it you might find that the using the Wasm/Emscripten version of that file (bbdata_wasm32.c) along with the BBC.h in bin/wasm would give you the best chance.

rtrussell avatar Jan 02 '24 16:01 rtrussell

There is no rush - It is well over 30 years since I last tried using BBC BASIC!
It is still pretty cool to be able to run it on Linux though. I'd just got as far as wondering what to do about the CPU dependent code, thanks for pointing me at the WASM version, I'll may take another look some time (when I get around to it)...

mike632t avatar Jan 02 '24 21:01 mike632t

I have updated the console mode edition to check that the file specified on the command line is a valid tokenised (internal format) program, and if not to report an error. I hope this will be an effective workaround to this issue.

rtrussell avatar Apr 07 '24 17:04 rtrussell