Linux GDB:Can';t调试gcc/gcov

Linux GDB:Can';t调试gcc/gcov,linux,gcc,gdb,debug-symbols,gcov,Linux,Gcc,Gdb,Debug Symbols,Gcov,我正在使用gcov收集我的C项目的覆盖率信息。但是,有些文件没有生成覆盖率数据(gcda文件),尽管它们已在我的测试中执行 我想通过调试gcov/gcc源代码来找出原因。确切地说,我想一步一步地调试方法\uu gcov\u flush(),看看发生了什么。我不完全确定这个方法在哪里。我认为是libgcov.o文件驻留在libgcov.a库中,它是gcc的一部分 当我开始调试代码时,GDB报告说它找不到调试符号。所以,我为gcc和libgcc安装了debuginfo。然而,即使在安装了这两个deb

我正在使用gcov收集我的C项目的覆盖率信息。但是,有些文件没有生成覆盖率数据(gcda文件),尽管它们已在我的测试中执行

我想通过调试gcov/gcc源代码来找出原因。确切地说,我想一步一步地调试方法\uu gcov\u flush(),看看发生了什么。我不完全确定这个方法在哪里。我认为是libgcov.o文件驻留在libgcov.a库中,它是gcc的一部分

当我开始调试代码时,GDB报告说它找不到调试符号。所以,我为gcc和libgcc安装了debuginfo。然而,即使在安装了这两个debuginfo文件之后,GDB仍然报告它找不到libgcov.c

opensuse12:/usr/Cpro/gcov_example # gdb -q ./a.out
Reading symbols from /usr/Cpro/gcov_example/a.out...done.
(gdb)
(gdb) break __gcov_flush
Breakpoint 1 at 0x402820: file ../../../libgcc/libgcov.c, line 734.
(gdb) r
Starting program: /usr/Cpro/gcov_example/a.out
Breakpoint 1, __gcov_flush () at ../../../libgcc/libgcov.c:734
734     ../../../libgcc/libgcov.c: No such file or directory.
(gdb)
(gdb) info source
Current source file is ../../../libgcc/libgcov.c
Compilation directory is /home/abuild/rpmbuild/BUILD/gcc-4.7.1-20120723/obj-x86_64-suse-linux/x86_64-suse-linux/libgcc
Source language is c.
Compiled with DWARF 2 debugging format.
Does not include preprocessor macro info.
(gdb) show directories
Source directories searched: $cdir:$cwd
如果我试图直接调试gcc/gcov,GDB会正确地标识debuginfo文件

opensuse12:/usr/Cpro/gcov_example # gdb -q gcc
Reading symbols from /usr/bin/gcc...Reading symbols from /usr/lib/debug/usr/bin/gcc-4.7.debug...done.
done.
(gdb) break __gcov_flush
Function "__gcov_flush" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) q
opensuse12:/usr/Cpro/gcov_example #
opensuse12:/usr/Cpro/gcov_example # gdb -q gcov
Reading symbols from /usr/bin/gcov...Reading symbols from /usr/lib/debug/usr/bin/gcov-4.7.debug...done.
done.
(gdb) break __gcov_flush
Function "__gcov_flush" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) q
请注意,GDB正在从正确的位置读取符号:

从/usr/lib/debug/usr/bin/gcc-4.7读取符号。调试…完成。

从/usr/lib/debug/usr/bin/gcov-4.7读取符号。调试…完成。

但是仍然报告说,函数“\uuugcov\u flush”没有定义。/../../../libgcc/libgcov.c:没有这样的文件或目录

opensuse12:/usr/Cpro/gcov_example # gdb -q ./a.out
Reading symbols from /usr/Cpro/gcov_example/a.out...done.
(gdb)
(gdb) break __gcov_flush
Breakpoint 1 at 0x402820: file ../../../libgcc/libgcov.c, line 734.
(gdb) r
Starting program: /usr/Cpro/gcov_example/a.out
Breakpoint 1, __gcov_flush () at ../../../libgcc/libgcov.c:734
734     ../../../libgcc/libgcov.c: No such file or directory.
(gdb)
(gdb) info source
Current source file is ../../../libgcc/libgcov.c
Compilation directory is /home/abuild/rpmbuild/BUILD/gcc-4.7.1-20120723/obj-x86_64-suse-linux/x86_64-suse-linux/libgcc
Source language is c.
Compiled with DWARF 2 debugging format.
Does not include preprocessor macro info.
(gdb) show directories
Source directories searched: $cdir:$cwd
我还缺什么?libgcov.c不应该是gcc调试信息文件的一部分吗?还需要安装什么


我正在使用openSuSE 12.2。gcc和gcov都是4.7.1版本。

gdb似乎可以找到符号,但找不到源文件。您的源路径设置是什么?尝试“显示目录”我有更新我的帖子。请参阅第一部分代码中的“信息源”和“显示目录”输出。现在我有两个问题。(1) 它说它是用DWARF 2调试格式编译的,但没有显示源代码。(2) 当我们有一个带有调试符号的可执行文件时,为什么我们需要源代码?您应该调试您的程序,而不是gcc/gcov__gcov_flush是二进制文件退出时调用的函数。是的,我就是这么做的。使用命令“gdb-q./a.out”查看第一个块。它报告“libgcov.c:没有这样的文件或目录”,包含调试符号的文件包括变量类型和对象位置到源文件的映射;它们不包括源代码的文本。如果您想使用
libgcov.c
的源代码进行调试,您需要下载GCC4.7.1的源代码(如果OpenSUSE的存储库中有可用的源代码,可以键入
zypper si gcc47