[英]Find function/variable definition for a reference in source code
My project contains many files.我的项目包含许多文件。
Sometimes I need to know where a particular function is defined (implemented) in source code.有时我需要知道特定函数在源代码中的定义(实现)位置。 What I currently do is text search within source files for the function name, which is very time consuming.我目前所做的是在源文件中搜索函数名称的文本,这非常耗时。
My question is: Is there a better way (compiler/linker flag) to find that function definition in source files?.... Since the linker has gone through all the trouble of resolving all these references already.我的问题是:有没有更好的方法(编译器/链接器标志)在源文件中找到该函数定义?....因为链接器已经经历了解析所有这些引用的所有麻烦。
I am hoping for method better than stepping into a function call in debugger, since a function can be buried within many calls.我希望有比在调试器中进入函数调用更好的方法,因为一个函数可以隐藏在许多调用中。
Try cscope utility .尝试cscope 实用程序。
From the manual:从手册:
Allows searching code for:允许搜索代码:
files including a file文件包括文件
Curses based (text screen)基于诅咒(文本屏幕)
A "screenshot":一个“截图”:
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:
If the symbol is exported, then you could wire up objdump
or nm
and look at the .o
files.如果符号已导出,那么您可以连接objdump
或nm
并查看.o
文件。 This is not useful for finding things in header files though.但是,这对于在头文件中查找内容没有用。
My suggestion would be to put your project in git
(which carries numerous other advantages) and use git grep
which looks only at those files under git's revision control (meaning you don't grep
object files and other irrelevances).我的建议是将您的项目放在git
(它具有许多其他优点)并使用git grep
,它仅查看 git 修订控制下的那些文件(意味着您不会grep
目标文件和其他无关文件)。 git grep
is also nice and quick. git grep
也很好而且很快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.