Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting functions in C source code

I have complete project in C, which can be built with gcc or Visual Studio. There are no calls to external libraries.

I would like to know how many functions there is in that project.

There are no unused functions in source code, and the project comes with tests which run it with different params, so for a dynamic approach (e.g. run-time call tree) I would need to accumulate results after each test.

Are there any tools that can perform static or dynamic analysis?

like image 780
mszabc Avatar asked Dec 15 '22 06:12

mszabc


1 Answers

With gcc:

$ nm elf_file | grep "T " | grep -v " _" | wc -l

Note that gcc can inline some functions even with optimizations disabled, so you should compile with:

-O0 -fno-builtin -fno-inline-functions-called-once

(-finline-functions-called-once is enabled by default even in -O0)

like image 196
ouah Avatar answered Jan 13 '23 02:01

ouah