【问题标题】:Simple c class compiled with gcov doesn't return during execution使用 gcov 编译的简单 c 类在执行期间不返回
【发布时间】:2014-08-07 13:27:12
【问题描述】:

我正在尝试使用 gcov,因此我开始使用一些小型 c 类来测试它。 下面的类就是我用的example.c

#include <stdio.h>

int main(){
printf("Hello \n"); // I also tried without this printf
return 0;
}

这样编译后由于某种原因:

g++ -ftest-coverage -fprofile-arcs example.c -o test

当我尝试执行它时,执行永远不会返回 :-(

prompt> ./test
...   
...
... 

这个简单的 exe 永远不会从他的执行中返回,当我强制 ctrl + c 终止它时,*gcda 文件当然是空的。

有什么想法吗? 非常感谢。

【问题讨论】:

  • 我试试就可以了
  • 奇怪的是它可以在一台机器上运行,但是当我在另一台机器上尝试时,我遇到了这个问题:-S 我很困惑..这些机器应该是平等的
  • 也许可以试试strace ./test
  • tksbirdspider.. 实际上由于某种原因它在 fcntl 上有一些问题: mprotect(0x7f577fd32000, 32768, PROT_READ) = 0 mprotect(0x602000, 4096, PROT_READ) = 0 mprotect(0x7f577ff6f000, 4096, PROT_READ) = 0 munmap(0x7f577ff14000, 366624) = 0 getpid() = 13273 open("/home/ex/example.gcda", O_RDWR|O_CREAT, 0666) = 3 fcntl(3, F_SETLKW, {type=F_WRLCK, wherece =SEEK_SET, start=0, len=0}

标签: code-coverage gcov


【解决方案1】:

似乎在等待写锁。

当我做strace ./test 2&gt;&amp;1 | grep fcntl 我得到

fcntl(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0}) = 0
fcntl(3, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)

根据http://linux.die.net/man/2/fcntl,它与锁定有关 (这里不是专家)

进一步分析表明它等待锁定test.gcda。 你用别的东西打开了吗?

我为什么这么认为(按照文件描述符3):

<snip>
open("/home/<user>/test.gcda", O_RDWR|O_CREAT, 0666) = 3
fcntl(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0}) = 0
fcntl(3, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
<snip>
close(3)                                = 0
<snip>

显然它会在我的机器上得到它。

【讨论】:

  • 不,我没有用别的东西打开它。相反,我也删除了它并再次执行测试,但结果相同。但是,是的,它看起来像你在答案中写的那样......
猜你喜欢
  • 2013-08-06
  • 2019-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-18
  • 2016-09-10
  • 1970-01-01
  • 2010-10-06
相关资源
最近更新 更多