我的项目包含许多文件。
有时我需要知道特定函数在源代码中的定义(实现)位置。我目前所做的是在源文件中对函数名称进行文本搜索,这非常耗时。
我的问题是:有没有更好的方法(编译器/链接器标志)在源文件中找到该函数定义?....因为链接器已经经历了解决所有这些引用的所有麻烦。
我希望有比在调试器中进入函数调用更好的方法,因为函数可以隐藏在许多调用中。
我的项目包含许多文件。
有时我需要知道特定函数在源代码中的定义(实现)位置。我目前所做的是在源文件中对函数名称进行文本搜索,这非常耗时。
我的问题是:有没有更好的方法(编译器/链接器标志)在源文件中找到该函数定义?....因为链接器已经经历了解决所有这些引用的所有麻烦。
我希望有比在调试器中进入函数调用更好的方法,因为函数可以隐藏在许多调用中。
尝试cscope 实用程序。
从手册:
允许搜索代码:
文件包括文件
基于诅咒(文本屏幕)
“截图”:
C symbol: atoi
File Function Line
0 stdlib.h <global> 86 extern int atoi (const char *nptr);
1 dir.c makefilelist 336 dispcomponents = atoi(s);
2 invlib.c invdump 793 j = atoi(term + 1);
3 invlib.c invdump 804 j = atoi(term + 1);
4 main.c main 287 dispcomponents = atoi(s);
5 main.c main 500 dispcomponents = atoi(s);
6 stdlib.h atoi 309 int atoi (const char *nptr) __THROW
Find this C symbol:
Find this global definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:
如果符号已导出,那么您可以连接objdump
或nm
查看.o
文件。但是,这对于在头文件中查找内容没有用。
我的建议是将您的项目放入git
(它具有许多其他优点)并使用git grep
它仅查看 git 修订控制下的那些文件(这意味着您不会grep
反对文件和其他不相关的文件)。git grep
也很好,很快。