Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all the functions' names from c/cpp files

Tags:

c

clang

For example, there is a C file a.c, there are three functions in this file: funA(), funB() and funC().

I want to get all the function names from this file.

Additionally, I also want to get the start line number and end line number of each function.

Is there any solution?

Can I use clang to implement it?

like image 960
Roger Zhang Avatar asked Oct 27 '25 15:10

Roger Zhang


1 Answers

You can compile the file and use nm http://en.wikipedia.org/wiki/Nm_(Unix) on the generated binary. You can then just parse the output of nm to get the function names.

If you want to get line numbers, you can use the function names to parse the source file for line numbers.

All the this can be accomplished with a short perl script that makes system calls to gcc and nm.

This is assuming you are using a *nix system of course...

like image 102
Chris VanWyk Avatar answered Oct 29 '25 07:10

Chris VanWyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!