我正在嘗試調試gcov
代碼。我寫了一個簡單的C程序,它調用了gcc/gcov的一部分的方法__gcov_flush()
。即使安裝了debuginfo,GDB仍未顯示行號信息
在確認libgcov.a
庫尚未使用調試符號構建後,我在我的機器上安裝了gcc的debuginfo軟件包(SLES 10
)。
# gcc -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.1.2 --enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new --program-suffix= --enable-version-specific-runtime-libs --without-system-libunwind --with-cpu=generic --host=x86_64-suse-linux
Thread model: posix
gcc version 4.1.2 20070115 (SUSE Linux)
# rpm -qi gcc-debuginfo-4.1.2_20070115-0.29.6.x86_64
Name : gcc-debuginfo Relocations: (not relocatable)
Version : 4.1.2_20070115 Vendor: SUSE LINUX Products GmbH, Nuernberg, Germany
Release : 0.29.6 Build Date: Sat Sep 5 03:04:50 2009
Install Date: Thu Apr 24 05:25:32 2014 Build Host: bingen
Group : Development/Debug Source RPM: gcc-4.1.2_20070115-0.29.6.src.rpm
Size : 251823743 License: GPL v2 or later
Signature : DSA/SHA1, Sat Sep 5 03:06:59 2009, Key ID a84edae89c800aca
Packager : http://bugs.opensuse.org
URL : http://gcc.gnu.org/
Summary : Debug information for package gcc
Description :
This package provides debug information for package gcc.
Debug information is useful when developing applications that use this
package or when debugging this package.
Distribution: SUSE Linux Enterprise 10
/usr/lib/debug/usr/bin # ls -lrt gcov.debug
-rw-r--r-- 1 root root 94216 Sep 5 2009 gcov.debug
然而,即使安裝debuginfo軟的正確版本(gcov.debug
)軟件包之後,GDB仍然不能識別行號信息,它只是傳遞控制到下一行而不報告行號(或步入功能) 。
(gdb)s
26 i++;
(gdb)s
27 __gcov_flush();
(gdb)s
28 printf("%d",i);
(gdb)
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "/usr/lib/debug".
爲什麼GDB無法識別gcov的行號信息?如果我沒有安裝gcc/gcov的debuginfo軟件包的正確版本,如何確認?
@ernesto我已經更新了答案。 –
感謝您的信息。雖然看起來很明顯,但請澄清一下:對於靜態庫,調試符號將在可執行文件鏈接的機器上,而不是運行exe的機器上,對嗎?當程序運行時,機器是否有帶調試符號的靜態庫並不重要。 – ernesto
@ernesto這是正確的:將歸檔庫複製到在靜態鏈接(構建)時與其鏈接的二進制文件中。歸檔庫在運行時*不在所有*處使用,並且不需要存在。 –