C源代码中的计数函数 [英] Counting functions in C source code

查看:133
本文介绍了C源代码中的计数函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完整的C项目,可以使用gcc或Visual Studio进行构建.没有对外部库的调用.

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?

推荐答案

使用gcc:

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

请注意,即使禁用优化,gcc仍可以内联某些函数,因此应使用以下代码进行编译:

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

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

(即使在-O0中,默认情况下也会启用-finline-functions-called-once)

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

这篇关于C源代码中的计数函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆