GCC6.3.0:标志“ --coverage”不起作用(未生成gdca文件)

时间:2018-11-14 10:36:40

标签: c++ c gcc code-coverage gcov

在C中具有一个代码片段,在C ++中具有相同的代码片段,生成的gdca文件执行由GCC 4.1.2编译的exe。 执行后用GCC6.3.0编译的同一代码段不会生成gdca文件,而不是C.exe而不是c ++。exe

我发现gcov库的实现是不同的,在GCC4.1.2和GCC6.3.0中,GCC6.3.0中gcov库的版本似乎是空的:

_gcov_merge_add.o:     file format elf32-i386

Disassembly of section .text:
00000000 <__gcov_merge_add>:
   0: 55                    push   %ebp
   1: 89 e5                 mov    %esp,%ebp
   3: 5d                    pop    %ebp
   4: c3                    ret
_gcov_merge_single.o:     file format elf32-i386

Disassembly of section .text:
00000000 <__gcov_merge_single>:
   0: 55                    push   %ebp
   1: 89 e5                 mov    %esp,%ebp
   3: 5d                    pop    %ebp
   4: c3                    ret
_gcov_merge_delta.o:     file format elf32-i386

Disassembly of section .text:
00000000 <__gcov_merge_delta>:
   0: 55                    push   %ebp
   1: 89 e5                 mov    %esp,%ebp
   3: 5d                    pop    %ebp
   4: c3                    ret
_gcov_merge_ior.o:     file format elf32-i386
_gcov_merge_time_profile.o:     file format elf32-i386
_gcov_merge_icall_topn.o:     file format elf32-i386
_gcov_interval_profiler.o:     file format elf32-i386
_gcov_pow2_profiler.o:     file format elf32-i386
_gcov_one_value_profiler.o:     file format elf32-i386
_gcov_indirect_call_profiler.o:     file format elf32-i386
_gcov_average_profiler.o:     file format elf32-i386
_gcov_ior_profiler.o:     file format elf32-i386

_gcov_indirect_call_profiler_v2.o:     file format elf32-i386

_gcov_time_profiler.o:     file format elf32-i386
_gcov_indirect_call_topn_profiler.o:     file format elf32-i386
_gcov_dump.o:     file format elf32-i386

Disassembly of section .text:
00000000 <__gcov_dump>:
   0: 55                    push   %ebp
   1: 89 e5                 mov    %esp,%ebp
   3: 5d                    pop    %ebp
   4: c3                    ret
_gcov_flush.o:     file format elf32-i386

Disassembly of section .text:
00000000 <__gcov_flush>:
   0: 55                    push   %ebp
   1: 89 e5                 mov    %esp,%ebp
   3: 5d                    pop    %ebp
   4: c3                    ret
_gcov_fork.o:     file format elf32-i386
_gcov_execl.o:     file format elf32-i386
_gcov_execlp.o:     file format elf32-i386
_gcov_execle.o:     file format elf32-i386
_gcov_execv.o:     file format elf32-i386
_gcov_execvp.o:     file format elf32-i386
_gcov_execve.o:     file format elf32-i386
_gcov_reset.o:     file format elf32-i386

Disassembly of section .text:
00000000 <__gcov_reset>:
   0: 55                    push   %ebp
   1: 89 e5                 mov    %esp,%ebp
   3: 5d                    pop    %ebp
   4: c3                    ret
_gcov.o:     file format elf32-i386

Disassembly of section .text:
00000000 <__gcov_init>:
   0: 55                    push   %ebp
   1: 89 e5                 mov    %esp,%ebp
   3: 5d                    pop    %ebp
   4: c3                    ret

The gcov within the GCC 6.3.0 was build with following flags:

/usr/gnu/gcc/V6.3.0/gcc-6.3.0_build/./gcc/xgcc
-B/usr/gnu/gcc/V6.3.0/gcc-6.3.0_build/./gcc/
-B/opt/V6.3.0/i686-elf/bin/ -B/opt/V6.3.0/i686-elf/lib/ -isystem
/opt/V6.3.0/i686-elf/include -isystem /opt/V6.3.0/i686-elf/sys-include
-fpic -O2 -mpreferred-stack-boundary=3 -O2  -fpic -O2
-mpreferred-stack-boundary=3 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -W
-Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes
-Wmissing-prototypes -Wold-style-definition  -isystem ./include
-fpic -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector
-Dinhibit_libc  -fpic -I. -I. -I../.././gcc
-I../../../gcc-6.3.0/libgcc -I../../../gcc-6.3.0/libgcc/.
-I../../../gcc-6.3.0/libgcc/../gcc
-I../../../gcc-6.3.0/libgcc/../include    -o _gcov_flush.o -MT
_gcov_flush.o -MD -MP -MF _gcov_flush.dep -DL_gcov_flush -c
../../../gcc-6.3.0/libgcc/libgcov-interface.c

任何想法gcov库有什么问题吗? 还是GCC6.3.0中缺少其他内容? 在GCC 6.3.0下是否还有其他人在gcov方面遇到困难?

1 个答案:

答案 0 :(得分:0)

当目标!=主机并且您的libc标志设置为true时,您将不会实现gcov库,gcov.a的对象转储未显示任何实现。在这种情况下,请将libgcc的 inhibit-libc 标志设置为false,重新编译即可实现gcov。