as title says, this is a perfect, easy and quick way to detect a problem point in sources.
If crashes, frozen app, bad program flow, or so.Base idea is well known, to log events into the logfile,
what I used for years.Now added immediate write with macro.
Surprisingly, because of Kovid-19 sad days with a lot of free time, I decided to find out finally a yearly
omitted minor bug in my oldest app, sGui featured.Success ! (Just only some kind of flashing, flipping help
gadget visibility was there randomly.)
Due matured code I didn't remember, which part of code is safe, tested and well working.No docs, notes.
Also I am not familiar with compiler error codes yet.
Then I decided to expand debug logs into the logfile not only for variable values in problem points, but for
whole app flow marking on important places - in/out Sub-Funcs-Macros points and decision ways in If-Loops
to see program flow.After app's runtest I opened the logfile.What I saw there was unbelievable.
The best part of code I thinked in problematic place was the worst ! Executed every time thru loop..
Whole problem (logical bug) solved in a half hour pleasantly /;D
What I want to say.If you don't use some debugger.Usable for any app, any level of build stage.Easy.Rapid speed.
You see everything important. Pleasant logfile size. After a few weeks upgrading of all my apps to this new
debug method I had a max that filesize cca 4,5 MB.Nice.And amazing is that you don't need to read all, just
jump to the end of logfile to see what happened before the crash.Then, if not yet clear what is wrong, only add
a new log point to trace flow.
If I see nothing bad and close to crashpoint, I mark every line to figure out, which line is bad.This leads to success.
This whole method consist only of a few things used in an app sources.
- to add logfile in core routines module
- write important events, places, flags, variables and values into it
(not needed to log whole program, in case you use this method for the first time, just log things near to the crashpoint
which you visually saw before app crash, huh)
- to add macro 'fileflush' - write to harddisk IMMEDIATELY
https://freebasic.net/forum/viewtopic.php?f=7&t=27627
- optionally used keywords 'Typeof' and 'Sizeof'
- optionally used log polling source method (viz math polling interval method, here polling source with filelogs
in incremental way => compile>run>poll source between last logpoint and crashpoint>add new file logpoint and repeat this process again)
Base principle democode, for example (32bit):
Code: Select all
REM next 4 lines placed in core routines module, as first thing to do
Dim Shared As String logFileName:logFileName="appLogfile.txt"
dim shared as integer logFN: logFN=freefile
open logFileName for output as #logFN
#define fileflush(fileID) fflush(cast(FILE ptr, Cast( FILE Ptr, FileAttr( fileID, fbFileAttrHandle ))))
'write #logFN,"some event .. in/out/value/name/place":fileflush(logFN) 'log important events on important places
REM mark in-out points of procedures to see which is broken
#macro myMakro_1()
write #logFN,"myMakro_1() .. IN":fileflush(logFN)
'body
'of
'macro
write #logFN,"myMakro_1() .. Out":fileflush(logFN)
#endmacro
function myFunction_a() as byte
write #logFN,"myFunction_a() .. IN":fileflush(logFN)
'body
'of
'function
write #logFN,"myFunction_a() .. Out":fileflush(logFN)
end function
Sub mySub_I()
write #logFN,"myFunction_a() .. IN":fileflush(logFN)
'body
'of
'sub
write #logFN,"myFunction_a() .. Out":fileflush(logFN)
End Sub
REM mark decision ways in IF blocks to see program flow
Do
'...
write #logFN,"something=",'value of something' 'add YOUR correct expression/variable value here !
fileflush(logFN)
if 'something' then
write #logFN,"if 'something' .. ",str(something):fileflush(logFN)
'commands
elseif 'another thing' then
write #logFN,"elseif 'another thing' .. ",str(another thing):fileflush(logFN)
'commands
else
write #logFN,"else .. ":fileflush(logFN)
'commands
end if
'...
Loop