Re: [fpc-pascal] detecting recursive loops

2018-05-06 Thread leledumbo via fpc-pascal
> Any ideas how to identify potential unintentional loops?

That depends on your design. Is it intended that the 3 procedures can call
each other, directly or indirectly? If no, then things are a lot easier. You
can just put on the currently entered procedure name to a map shared by the
3 (or just make it global) and on start of each procedure, you check whether
the current procedure is in the map already or not. If yes, then the current
call stack has formed a recursion.



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] detecting recursive loops

2018-05-06 Thread Mark Morgan Lloyd

On 05/05/18 21:15, James Richters wrote:

I'm having an issue with one of my programs that I suspect is being caused by a 
recursive loop... in simplified form... something like this:
Procedure Proc1;Begin   Proc2;End;Procedure Proc2;Begin   Proc1;End;
I ended up getting a runtime error and the report showed something like above, 
where I had a loop of the same 3 procedures calling each other over and over in 
sequence in a loop before the actual error.   Unfortunately I didn't take down 
all the information because I thought I could make it happen again.. but I 
haven't had the runtime error again... however under certain conditions 
sequences that normally happen very fast become very slow and I suspect it 
somehow is getting into this recursive loop again.
It's a very large very complicated program and trying figure out where this is 
happening is becoming quite a challenge.   I was wondering if there is some 
method of detecting these recursive loops, either during compilation, or is 
there some option that would force a runtime error if a loop of procedures 
happened.
Any ideas how to identify potential unintentional loops?


I occasionally put entry/exit counters on functions that I suspect are 
going to be a problem, InterlockedIncrement() etc. You can obviously 
have your code check that as a verification of sanity, or pick up a haig 
value using a conditional breakpoint.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal