Is there a debugger? How to debug my code (in C)?

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
Fabrizio
Member
Posts: 116
Joined: Tue Jul 11, 2017 9:28 pm

Is there a debugger? How to debug my code (in C)?

Post by Fabrizio »

Hi

I am having a problem with my code with random crashes (only with classic lib).
I am not having this problem (yet) with other compilers (CC65) or sdcc + new lib.
It may be related to using the sleep function but it could also be a bug in my own code.
Maybe I am writing data or overflowing in some portion of memory where I should not.

I need to figure this out. Is there a way to execute my code step by step?
I am not an Assembly guru and I would like to run single C commands at a time.

Fabrizio
stefano
Well known member
Posts: 2151
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Not in my knowledge. I remember a past proposal on a way to transmit debugging information to a known emulator but the theory is still just an idea.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

There is no source level debugger so you have to debug in assembly language.

If you add "-m --list --c-code-in-asm" to the compile line, you will get a .map file that shows where everything is in memory and each of your .c files will get a companion .c.lis file that is the corresponding translation to asm. With these files you can follow execution in an emulator.

However, this is not easy unless you are comfortable with assembly language.

The bugs you are seeing are likely in the classic library - a few have been found already. Can you give us the compile line you are using so we can have a look?
Fabrizio
Member
Posts: 116
Joined: Tue Jul 11, 2017 9:28 pm

Post by Fabrizio »

I am compiling my code
https://github.com/Fabrizio-Caruso/ASCII-CHASE/

with
zcc +zx -vn -SO3 -DSPECTRUM_NATIVE_DIRECTIVES -DSPECTRUM_32COL -D__SPECTRUM__ -DAMALLOC -lmalloc -lndos -create-app -o %deliverables%\ZXSpectrum_32col_experimental.prg

My code started working fine with the "fix":
#elif defined(__SC3000__) || defined(__MSX__) || defined(__CPC__) || defined(__SPECTRUM__)
#define sleep(sec) { { unsigned long ii; for(ii=0;ii<sec*2000UL;++ii){}; } };
in sleep_macros.h

Removing these two lines may generate crashes BUT I only had this problem with a previous version of my game.
So, I need to find out the exact version that had this weird issue otherwise you won't be able to reproduce it.

Removing the fix may generate crashes or random behavior in the game but I cannot reproduce it now with the latest version.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Fabrizio wrote:Removing these two lines may generate crashes BUT I only had this problem with a previous version of my game.
So, I need to find out the exact version that had this weird issue otherwise you won't be able to reproduce it.

Removing the fix may generate crashes or random behavior in the game but I cannot reproduce it now with the latest version.
The sleep thing was fixed:

https://github.com/z88dk/z88dk/commit/2 ... 2e09199451

and should have only affected zsdcc and classic compiles. (The compile line you list is sccz80 and classic).

I'll have a look again first with the older version of your code that I have with the recent fixes.
Post Reply