Reputation: 828
When working on a big project, I would like to know in which header file a particular function is defined. Is there a way to do that for C++ in Ubunt (linux)?
Upvotes: 2
Views: 288
Reputation: 167
This can be done using the GNU Debugger (GDB). Given a function name, MYFUNCTION
, a binary file MYFILE.o
, and some optional arguments, MYARGS
(delimited by spaces), you can run the following:
gdb -batch -ex "break MYFUNCTION" -ex "run" --ex "info line" --args MYFILE.o MYARGS | grep -P "Line [0-9]+"
If the function was called, the output will look like:
Line 1234 of "../path/to/function.c" starts at address 0x7ffff7d9e1a3 <MYFUNCTION+16> and ends at 0x7ffff7d9e1aa <MYFUNCTION+23>.
Otherwise, the output will return:
Function "MYFUNCTION" not defined.
-g
flag).Upvotes: 1
Reputation: 642
One method which helps me is through editor called Vs code
. Just pointing the cursor on the function name and pressing F12
or in some machines Fn+F12
will let you to the function definition's location. Other editors should have this as well...
To note: This is a specific way and not a general solution to your problem.
Upvotes: 0