Forum > General
Enter/Exit function/procedure message
440bx:
Hello,
For debugging and analysis purposes of a program, I'd like to have a message such as "entering <function/procedure name>" and "exiting <function/procedure name>" whenever a function/procedure is entered and exited.
The first question is: is there a way to tell the compiler to automatically generate code that does that ? (IOW, instrument the code.)
if the answer to the above question is "no" (which I believe is quite likely) then, suggestions as to how to accomplish this manually will be appreciated. The "entering <function/procedure name>" is easy. The "exiting <function/procedure name>" is more difficult/cumbersome because it has to account for every instance of an "exit" statement in the code. Is there any way to have the "exiting" message without risking not having it due to missing an "exit" statement ?
Thank you for your help.
dsiders:
--- Quote from: 440bx on September 24, 2024, 10:02:28 pm ---Hello,
For debugging and analysis purposes of a program, I'd like to have a message such as "entering <function/procedure name>" and "exiting <function/procedure name>" whenever a function/procedure is entered and exited.
The first question is: is there a way to tell the compiler to automatically generate code that does that ? (IOW, instrument the code.)
if the answer to the above question is "no" (which I believe is quite likely) then, suggestions as to how to accomplish this manually will be appreciated. The "entering <function/procedure name>" is easy. The "exiting <function/procedure name>" is more difficult/cumbersome because it has to account for every instance of an "exit" statement in the code. Is there any way to have the "exiting" message without risking not having it due to missing an "exit" statement ?
Thank you for your help.
--- End quote ---
This popped up on the radar a while back: https://wiki.freepascal.org/FPProfiler... even if you're not interested in the timing aspects. I don't know much about it other than it exists.
440bx:
--- Quote from: dsiders on September 24, 2024, 10:26:41 pm ---This popped up on the radar a while back: https://wiki.freepascal.org/FPProfiler... even if you're not interested in the timing aspects. I don't know much about it other than it exists.
--- End quote ---
Thank you! This looks promising. I'll definitely have a close look at it as it might be (or have) what I'm looking for.
Martin_fr:
I use to "Code Templates" for that.
The first (that I insert on top of each method is
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---debuglnEnter(['> $ProcedureName() ',dbgsName(Self),dbgs(self),' '| ]); try
And at the bottom
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---finally debuglnExit(['< $ProcedureName() '| ]); end;
Of course the could also be ifdefed, if you prefer that.
And while I haven't done myself, it should be possible to record a macro.
Something like ("det" and "fdx" are the names of my templates)
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---beginecChar('d');ecChar('e');ecChar('t');ecAutoCompletion;ecFindBlockStart;ecFindBlockStart;ecFindBlockOtherEnd;ecLineBreak;ecUp;ecChar('f');ecChar('d');ecChar('x');ecAutoCompletion;ecDown;ecLineStart;ecFindBlockOtherEnd;end.Inserts code at both ends, if started at an empty line below the initial "begin".
440bx:
@Martin,
That looks like a really good solution. I hadn't thought about using a "finally" to ensure the output of the "exiting" message.
I haven't played with templates but, it looks simple enough. I'll definitely give your suggestion a try.
Thank you, that looks like it might be the simplest way to go.
Navigation
[0] Message Index
[#] Next page