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 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您可能想尝试 cflow:
它应该打印一个调用图并标记递归函数。
You might want to try cflow:
It should print a callgraph and mark the recursive functions.
如果您的代码通过函数指针进行间接调用,则检测其中的递归调用可能非常困难(在一般情况下可能是不可能的,因为相当于停止问题。)。
但我完全不确定消除递归是否值得付出努力。对于某些递归算法或问题,您只需用堆栈(在堆中)模拟它来替换它,但这没有多大帮助(并且使代码不可读)。
一个更务实的解决方案(至少在 Linux 上)是限制堆栈大小,并运行测试,直到它们因填充堆栈而中断。然后您可以使用调试器来了解它是如何发生的。
我认为你不应该太关心递归......
If your code has indirect calls thru function pointers, detecting recursive calls in it could be extremely difficult (and probably impossible in the general case, since equivalent to the halting problem.).
But I am not sure at all that eliminating recursion is worth the effort. For some recursive algorithms or problems, you'll just replace it by simulating it with a stack (in heap), and that don't help much (and makes the code unreadable).
A more pragmatic solution (at least on Linux) would be to limit the stack size, and run tests till they break by filling the stack. Then you can use the debugger to understand how it happens.
I think you should not bother that much about recursion...
CIL 可以生成 CFG C 程序,但这有点像用大锤打钉书钉。
CIL can produce a CFG for C programs, but it is a bit like using a sledgehammer to put in a staple.