Debugging - Printable Version

+- Forum (
+-- Forum: Compilers and Computer Languages (
+--- Forum: ZX Basic Compiler (
+---- Forum: Help & Support (
+---- Thread: Debugging (/showthread.php?tid=885)

Debugging - pinback - 07-21-2019


I have proved an old program from the ZX Spectrum Basic to Boriel's Basic.
Some 700 lines of code.
The program can compile now and it is running on a Spectrum emulator.

However I get an error "3 Subscript wrong, 30:1"
wich is a very generic error coming from the "RANDOMIZE USR 32768".

Is there any way to tell where the error occurred in my source file?

Here is what I used for compilation:
python3 -taB program.bas --array-base 1 --string-base 1 --debug-array --debug-memory

Re: Debugging - boriel - 07-22-2019

Unfortunately, it's hard to debug that.
It basically means that yes, you're having an out of bound array access.
I will add more debug capabilities soon.

An old way to debug this is to execute a PRINT <line number> after each array access, to locate the line more easily.

PS: Try compiling with --enable-break flag. This will update the line number, and probably you'll get a more accurate position
Note that the line number reported in the error won't be the BASIC one (i.e. '1000') but the actual line in your text .bas source code.

Re: Debugging - pinback - 07-22-2019

Hmm, I used the "--enable-break" and something strange happened:
The error is gone now.

Ok, lets see how far I come...

Re: Debugging - boriel - 07-22-2019

But if you remove the chkbreak the error happens again :?: Confusedhock:

Re: Debugging - pinback - 07-23-2019

I can't reproduce that. Now I experience something slightly different.

Seems that input is not working anymore if I enable --enable-break.

The program does load but doesn't react on input anymore:
- Executing task: python3 -taB program.bas --array-base 1 --string-base 1 --debug-memory --enable-break
- Executing task: python3 -taB program.bas --array-base 1 --string-base 1 --debug-array --enable-break <
- Executing task: python3 -taB program.bas --array-base 1 --string-base 1 --enable-break <

The program loads and seems to work correctly (with input):
- Executing task: python3 -taB program.bas --array-base 1 --string-base 1

The program load, I can input something then "3 Subscript wrong, 30:0" error:
- Executing task: python3 -taB program.bas --array-base 1 --string-base 1 --debug-array

Most probably this is also important:
I am using the
#include <input.bas>
in the first line of my program.

Re: Debugging - boriel - 07-23-2019

Which compiler version are you using?

Re: Debugging - pinback - 07-25-2019

zxb 1.9.2

RE: Debugging - boriel - 10-11-2021

Not sure if this was solved in later versions??