views:

237

answers:

7

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?

+5  A: 

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

rossoft
Yep. Build a call graph and look for cycles.
ephemient
And hope there are no OS callbacks involved in the recursion ;)
Cogwheel - Matthew Orlando
+4  A: 

How about using a profiling tool like RedGate's Ants profiler or dotTrace?

They both offer free trials. Just run the code with the profiler running and it will quickly show you where your time/memory is being spent.

I'd bet that your problem recursive function will stick out quite a bit.

Additionally, what error logging framework are you using? In case the answer is none, consider adopting one. This Question deals with the options. With a good system, you should be able to get the stack trace which, if you're lucky, may give you clues as to where the exception is occurring.

Michael La Voie
I have hundreds of installations around US, this is the only instance that is giving me fits. I can't replicate the problem, but I'd like to at least get close to it, by locating the recursion
AngryHacker
+5  A: 

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.

Cogwheel - Matthew Orlando
Yes - Very true. Debugging services is trickier than normal applications, though, which may be why they're asking.
Reed Copsey
I think you are overstating it a bit. In most cases I think some static analysis an find some cycles - this would not be that hard. Would it be exhaustive? No, but I think to make a practical check for this would not be so hard. Using a regex is not going to happen though.
Tim
I think "some cycles" fits with the "most trivial examples" I was trying to get across. But yeah, even then you'd likely need a full parser just to get started.
Cogwheel - Matthew Orlando
+2  A: 

Attach to the service in the debugger and debug it properly. You will find this much easier than trying to search the code of any reasonably sized project.

Reed Copsey
+3  A: 

I agree a regexp isn't going to cut it here.

A more direct way would be to get a dump file and look at it to see where the exception was thrown.

Or you could look at a static analysis tool like NDepend to examine the programs flow.

Rob Walker
+1  A: 

The easiest way to do this is to get a stack trace of the thing that is crashing. The stack trace will look like this:

Blah
Foo
Baz
Hello
...
Frob
Frob
Frob
Frob
[several hundred more Frobs]
Frob
Frob
...
Frob
Something -- crash!

The "Frob" is the recursive function. :-)

Eric Lippert
A: 

Do you have exception stacktrace? Stacktrace shows sequence of calls

Serge