Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Simple trace functions (manually debug your code)

Author
Message
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 8th May 2011 16:12
I had to find out what was wrong with a piece I had been working on so I come up with this if anyone is interested.



At the beginning of your program just call WL_TRACE_INIT(filename$). At the end of your code just add WL_TRACE_CLOSE(). If your program exits safely then the close function will write a final line of text to the file.

Using it just call WL_TRACE_WRITE(mystring$). You can make up your strings just like in a print statement.



If your program crashes then the text file will only have in it where it has got up to.

So far this has helped me with two bugs over the last twenty four hours. Hope it comes in useful for someone.

Warning! May contain Nuts!
tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 9th May 2011 06:20
Nice! I do this sort of thing all the time. Look into using the append file commands (I believe Matrix1 has them, I use another dll) and the files won't be destructive and you can also have several programs write to the same file nearly at the same time, if that is ever needed.


A 3D marble platformer using Newton physics.
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th May 2011 16:41
This is my preferred method of debugging. If you use Matrix1 plugins, you can also output to a console window at the same time, which I do based on a flag setting. Ian's commands also are better at keeping up the pace when it crashes, and you can have multi-coloured and styled output (e.g warnings in red, section headers in bold)

I went a little over the top and wrote a program to create debug functions for all arrays and their typed fields, so I can output a full array of data when times get desperate!

=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 9th May 2011 18:22
I also have written a set of debug functions, which use IanM's console as primary output, and also sending this to a log file.

They can record averages, min and max values, and actual value of any variable in my code regardless of what it is. and also record a debug log of functions called etc.

This is topped of with my Hardware report generator which creates a report of the pc's cpu type and speed, ram, gfx card etc.

All this helpful info is then anonymously deposited via ftp to my web server to help to analyse programs performance on various pc's.

It's dead neat

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 9th May 2011 22:34
I do miss a proper debugger like the old days of the Atari and Amiga. I just needed something simple that works so I can track my vars. That's probably the best feature of the VS debugger is the variable watch.

This is probably going to be a resident in most of my programs in DBP from now on.

Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-11 02:36:46
Your offset time is: 2026-07-11 02:36:46