.gcda文件不会在多次运行中合并 [英] .gcda files don't merge on multiple runs

查看:219
本文介绍了.gcda文件不会在多次运行中合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个使用通用C ++类的主要功能.

I have two main functions that use a common C++ class.

文件1:main.cpp

File1: main.cpp

   #include <iostream>
   #include "HelloAnother.h"

   int main() {
       HelloAnother::sayHello1();
       return 0;
   }

文件2:main2.cpp

File2: main2.cpp

   #include <iostream>
   #include "HelloAnother.h"

   int main() {
       HelloAnother::sayHello2();
       return 0;
   }

文件3:HelloAnother.h

File3: HelloAnother.h

   #pragma once
    class HelloAnother {
        public:
         static void sayHello1();
         static void sayHello2();
    };

文件4:HelloAnother.cpp

File4: HelloAnother.cpp

#include <iostream>
#include "HelloAnother.h"
void HelloAnother::sayHello1() {
    std::cout << "Hello 1!!!" << std::endl;
}

void HelloAnother::sayHello2() {
    std::cout << "Hello 2 !!!" << std::endl;
}

现在,我编译两个可执行文件: clang-3.8 -o main -fprofile-arcs -ftest-coverage --coverage -g -fPIC -lstdc++ main.cpp HelloAnother.cpp

Now I compile two executables: clang-3.8 -o main -fprofile-arcs -ftest-coverage --coverage -g -fPIC -lstdc++ main.cpp HelloAnother.cpp

clang-3.8 -o main2 -fprofile-arcs -ftest-coverage --coverage -g -fPIC -lstdc++ main2.cpp HelloAnother.cpp

现在,我运行./main

你好1 !!!

Hello 1!!!

当我重新运行./main

你好1 !!!

Hello 1!!!

分析:/media/sf_ubuntu-shared/test-profiling/main.gcda:无法映射:无效的参数 分析:/media/sf_ubuntu-shared/test-profiling/HelloAnother.gcda:无法映射:无效参数

profiling: /media/sf_ubuntu-shared/test-profiling/main.gcda: cannot map: Invalid argument profiling: /media/sf_ubuntu-shared/test-profiling/HelloAnother.gcda: cannot map: Invalid argument

第二次运行时,我在尝试创建/合并.gcda文件时遇到此错误(以上).

One second run, I get this error (above) in trying to create/merge .gcda files.

现在,如果我尝试运行./main2

Now, If I try to run ./main2

你好2 !!!

Hello 2 !!!

分析:/media/sf_ubuntu-shared/test-profiling/HelloAnother.gcda:无法映射:无效的参数

profiling: /media/sf_ubuntu-shared/test-profiling/HelloAnother.gcda: cannot map: Invalid argument

当我生成代码覆盖率报告时,对第二个函数的调用不会像未进行调用那样显示.

When I generate the code coverage report, the call to second function doesn't show up as if the call wasn't made.

有人可以帮助我调试此问题吗?该问题似乎与多次运行时合并.gcda文件有关,但不确定如何解决.

Can anyone help me debug this issue pls? The issue seems to be related to merging of .gcda files on multiple runs, but not sure how to solve it.

我也尝试了clang-3.5,但结果相同.

I also tried clang-3.5 but with same results.

推荐答案

经过大量搜索和反复试验后,这对我有用:

After a lot of searching and trial/error this is what works for me:

  1. 编译第一个可执行文件,然后运行它.这样会生成HelloAnother.gcda和main.gcda文件.
  2. 执行lcov --gcov-tool=gcov-4.4 --directory . --capture --output-file coverage.main.info
  3. rm -rf * .gcda; rm -rf * .gcno
  4. 编译第二个可执行文件(main2.cpp),运行它.这样会生成另一个 HelloAnother.gcda和一个main2.gcda文件.
  5. 执行lcov --gcov-tool=gcov-4.4 --directory . --capture --output-file coverage.main2.info
  6. 现在要生成漂亮的html报告,请执行:genhtml -o coverage coverage.main.info coverage.main2.info
  1. Compile first executable, run it. This generates HelloAnother.gcda and main.gcda files.
  2. Execute lcov --gcov-tool=gcov-4.4 --directory . --capture --output-file coverage.main.info
  3. rm -rf *.gcda; rm -rf *.gcno
  4. Compile second executable (main2.cpp), run it. This generates another HelloAnother.gcda and a main2.gcda file.
  5. Execute lcov --gcov-tool=gcov-4.4 --directory . --capture --output-file coverage.main2.info
  6. Now to generate nice looking html report do: genhtml -o coverage coverage.main.info coverage.main2.info

这篇关于.gcda文件不会在多次运行中合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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