仅运行一个函数时的c ++代码覆盖率

时间:2013-05-09 09:38:10

标签: c++ analysis gcov

我想获取代码覆盖率信息。在运行只有一个功能。 例如,我只想知道“run()”经历了哪些行。

TEST.CPP:

#include "..."

int main(){
  init();
  gcov_start_recording();
  run();
  gcov_end_recording();
  return 0;
}

1 个答案:

答案 0 :(得分:1)

It is unable to get source code information from a normal binary file.
My basic idea is :
1.  Executable should be complied as debug version ,
 which keep the symbol infomation.  
2. You need a external wrapper  script for GDB. 

set break point at entry and exit of the function. 
collect trace output from GDB . 
filter the duplicate line in the output . 
finally you will get the code cover information .