4

我想要的是一个能够告诉我哪些函数调用特定函数 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 运行很棒的工具时,它将以某种方式返回函数 BC 和 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 很好地配合,我将非常高兴!

4

2 回答 2

7

你可以看看 cscope 工具(http://cscope.sourceforge.net/)。它支持非常大的项目和许多不同的查询类型:

  • 找到这个 C 符号
  • 找到这个全局定义
  • 查找此函数调用的函数
  • 查找调用此函数的函数...
于 2012-02-25T15:50:08.790 回答
2

首先,存在不同编译单元之间的调用问题,例如foo.c定义函数foo1调用函数bar2定义在bar.c(并且bar2可能调用foobar定义foo.c在另一个文件中foofoo.c

然后,您可能会考虑开发 GCC 插件或MELT扩展以满足您的需求。

您还可以购买昂贵的静态分析工具。

Emacs 有cedet,您可能会感兴趣。

于 2012-02-25T15:44:59.380 回答