I am looking for a recursion analysis tool [closed]
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this questionI ran into a problem this weekend where method 1 called method 2 which called method 3 which caught exception, and within the exception handling method 1 was call开发者_JAVA技巧ed again...
M1 -> M2 -> M3 -> M1 ....
The problem became obvious and easy to fix, once the problem happened.
Does anyone know of a tool to detect problems like this in a .NET application?
To do this right, you need a global call graph over the C# application, computed using C# semantics and what amounts to a points-to analysis, arguably including the libraries it calls. With such a call graph, you could enumerate the cycles in it, and those would be the candidates to check.
I don't know where you would get a tool that compute such a global call graph for C#, off the shelf.
You could approximate this using simple code scanning techniques. For each method M, extract the apparant set of calls it contains as identifiers I. Mostly they will appear as syntax that looks like identifier( After this step you have M_i -> I. You can build this as an (extermely conservative) basic call graph, and then compute the transitive closure. With that, you have an approximate call graph with cycles, and you can carry out your cycle analysis. This would mass methods passed by names, and other cases, but it might be good enough.
Gendarme will catch some (the most common, but basic) cases of recursions. MS FxCop has some too (IIRC). However neither have rules (presently) to cover more complex cases like: M1->M2->M3->M1...
Sadly I'm not aware of any other tool that can do such detection for .NET. Please share anything you find :-)
精彩评论