我想要的是一个能够告诉我哪些函数调用特定函数 A()(在 C 项目中)以及哪些函数调用这些函数等的工具,这样我就可以得到一个函数列表知道当它们被调用时,有可能调用函数 A()。
例如我们在一个项目中分散了以下功能:
void A()
{ /*does something*/ }
void B()
{
A();
/*and more stuff*/
}
void C()
{
if(unlikely_to_be_false)
A()
/* moar stoff */
}
void D()
{
/* code that does not refer to A() at all */
}
void E()
{
C()
}
当使用参数 A 运行 awesome 工具时,它将以某种方式返回函数 B C 和 E。
接近这个但不完全是我想完成的: 给定一个项目中某处的变量,找到对它的所有读/写操作(直接或间接)。
例如:
void A()
{
char* c; // this is our little variable
B(c); // this is in the resulting list
}
void B(char* x)
{
printf("%c", x); // this is definately in the list
*x='d' // this is also in the list
C(x); // also in the list
}
void C(void* ptr)
{
ptr = something; // also in the list
}
如果以上内容可以很好地与 emacs 一起使用,我将非常高兴!
最佳答案
您可以查看 cscope 工具 (http://cscope.sourceforge.net/)。它支持非常大的项目和许多不同的查询类型:
- 找到这个 C 符号
- 找到这个全局定义
- 查找该函数调用的函数
- 查找调用此函数的函数 ...
关于C 代码解析器,用于跟踪项目中的函数调用和变量访问(emacs 兼容性会很好),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9445437/