简体   繁体   中英

Way to check where the function is defined on C++

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)?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM