【发布时间】:2015-08-02 17:30:32
【问题描述】:
这是我第一次处理“gcov”,所以我想一步一步来。我关注Wikipedia页面,所以我创建了一个简单的c文件如下:
#include <stdio.h>
int
main (void)
{
int i;
for (i = 1; i < 10; i++)
{
if (i % 3 == 0)
printf ("%d is divisible by 3\n", i);
if (i % 11 == 0)
printf ("%d is divisible by 11\n", i);
}
return 0;
}
然后我编译了文件:
gcc -Wall -fprofile-arcs -ftest-coverage test.c
然后我输入:
gcov test.c
根据维基百科页面,我应该得到类似的东西:
88.89% of 9 source lines executed in file test.c
Creating test.c.gcov
但是,我得到的是:
File 'test.c'
Lines executed:0.00% of 7
test.c:creating 'test.c.gcov'
我不知道问题出在哪里。我正在使用 mac 10.10.4。当我输入
gcc --version
我明白了:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx- include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.4.0
Thread model: posix
当我输入时
gcov --version
我明白了:
LLVM (http://llvm.org/):
LLVM version 3.6.0svn from Apple Clang 6.1.0 (build 602.0.53)
Optimized build.
Default target: x86_64-apple-darwin14.4.0
Host CPU: x86-64
我真正想要的是一个跟踪程序执行的工具,即行执行的顺序。我想我可以通过使用“gcov”来实现这一点。
有什么想法吗?
【问题讨论】: