GCC -fprofile-arcs -ftest-coverage编译选项

gcc需要静态注入目标程序编译选项,在编译链接的时候加入2个选项(-ftest-coverage -fprofile-arcs ),编译结束之后会生成 .gcno 文件,而经过静态注入的目标程序在“正常结束”后,会在运行目录下产生.gcda数据文件,通过gcov工具就可产生覆盖率数据结果。

  • -ftest-coverage

    Produce a notes file that the gcov code-coverage utility (see gcov—a Test Coverage Program) can use to show program coverage. Each source file’s note file is called auxname.gcno. Refer to the -fprofile-arcs option above for a description of auxname and instructions on how to generate test coverage data. Coverage data matches the source files more closely if you do not optimize.
    让编译器生成与源代码同名的.gcno文件(note file),这种文件含有重建基本块依赖图和将源代码关联至基本块的必要信息。

  • -fprofile-arcs

    Add code so that program flow arcs are instrumented. During execution the program records how many times each branch and call is executed and how many times it is taken or returns. When the compiled program exits it saves this data to a file called auxname.gcda for each source file. The data may be used for profile-directed optimizations (-fbranch-probabilities), or for test coverage analysis (-ftest-coverage). Each object file’s auxname is generated from the name of the output file, if explicitly specified and it is not the final executable, otherwise it is the basename of the source file. In both cases any suffix is removed (e.g. foo.gcda for input file dir/foo.c, ordir/foo.gcda for output file specified as -o dir/foo.o). See Cross-profiling.
    让编译器静态注入对每个源代码行关联的计数器进行操作的代码,并在链接阶段链入经态度libgcov.a,其中包含在程序正常结束时生成*.gcda文件的逻辑;

可以参考:
https://blog.csdn.net/LU_ZHAO/article/details/104517587

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章