tracing lines executed
tracing lines executed
Is it possible to print a trace of the last x number of line numbers executed (with full debug turned on) at will? I have a problem in a function that's called from many parts of my code and I like to trace where the function was called from. I could add unique tags to each function call and print those but because there are so many of them that would be tedious. If I have to I will.
-
- Posts: 4310
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: tracing lines executed
Check out Profiling in the manual.
Re: tracing lines executed
I usually just open a file at the beginning and close it as the end.
You can print to the file information you need.
for instance replace (from your ide) return with print #1, __function__:return
Then you can undefine call and redefine call to information you want, here the calling line number.
Then CALL your function.
example:
You can print to the file information you need.
for instance replace (from your ide) return with print #1, __function__:return
Then you can undefine call and redefine call to information you want, here the calling line number.
Then CALL your function.
example:
Code: Select all
#undef call
#define call print #1,__line__,:
open "checkfile.dat" for output as #1
print #1, "call from","function"
print #1,""
function function_a as long
print #1, __function__:return 1
end function
function function_b as long
print #1, __function__:return 1
end function
function function_c as long
print #1, __function__:return 1
end function
function function_d as long
call function_a
print #1, __function__:return 1
end function
function function_e as long
print #1, __function__:return 1
end function
function function_f as long
print #1, __function__:return 1
end function
function function_g as long
print #1, __function__:return 1
end function
function function_h as long
print #1, __function__:return 1
end function
function loadfile(file As String) As String
Dim As Long ff=Freefile
if Open(file For Binary Access Read As #ff)=0 then
Dim As String text
If Lof(ff) > 0 Then
text = String(Lof(ff), 0)
Get #ff, , text
End If
Close #ff
Return text
else:print "unable to load ";file:end if
End function
call function_a
#define irange(f,l) Int(Rnd*(((l)+1)-(f))+(f))
dim as string st="abcdefgh"
dim as long counter
'some random calls
do
counter+=1
var i=irange(0,(len(st)-1))
var k=st[i]
select case k
case asc("a"):call function_a
case asc("b"):call function_b
case asc("c"):call function_c
case asc("d"):call function_d
case asc("e"):call function_e
case asc("f"):call function_f
case asc("g"):call function_g
case asc("h"):call function_h
end select
loop until counter>20
call function_a
close #1
var L=loadfile("checkfile.dat")
print L
sleep
kill "checkfile.dat"
Re: tracing lines executed
Thanks. I had something similar. I was hoping something built-in. Anyway, I'll go back to doing what I used to do. It also needed to flush out the output after each print to avoid losing any output, using flushRecordOnDisk(trace_file_lun)
with
#define flushRecordOnDisk(fileID) fflush(cast(FILE ptr, Cast( FILE Ptr, FileAttr( fileID, fbFileAttrHandle ))))
with
#define flushRecordOnDisk(fileID) fflush(cast(FILE ptr, Cast( FILE Ptr, FileAttr( fileID, fbFileAttrHandle ))))
Re: tracing lines executed
Perhaps caller/callee diagrams may help, like in this documentation:
https://users.freebasic-portal.de/tjf/P ... a007df78dc
https://users.freebasic-portal.de/tjf/P ... a007df78dc