Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find recursion in your app?

My c# service got an internal .net execution error that points to recursion issue (e.g. stack overflow). The problem is that the service is pretty large, so I am having trouble finding where the recursion actually occurs.

Can someone with massive regex mojo hook me up with a search string that would find what I need?

like image 608
AngryHacker Avatar asked Nov 05 '09 19:11

AngryHacker


People also ask

What is an example of recursion?

A classic example of recursionThe factorial of a number is computed as that number times all of the numbers below it up to and including 1. For example, factorial(5) is the same as 5*4*3*2*1 , and factorial(3) is 3*2*1 .

How do you read recursion easily?

A recursive function always has to say when to stop repeating itself. There should always be two parts to a recursive function: the recursive case and the base case. The recursive case is when the function calls itself. The base case is when the function stops calling itself.


2 Answers

This is an unanswerable question in the general case. Except for the most trivial examples (e.g. a function calling itself directly), there's no way to analyze a program and determine if recursion occurs. You'll just need to start hitting the debugger or other runtime tools.

This is an example of the halting problem.

like image 76
Cogwheel Avatar answered Sep 22 '22 12:09

Cogwheel


A recursion is not easy to find in some situations like:

method1() {
  method2()
}

method2() {
  method1()
}

So a regex probably would not help you to find it unless it's a trivial case.

like image 45
rossoft Avatar answered Sep 20 '22 12:09

rossoft