2014-04-24 33 views
0

我正在嘗試調試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軟件包的正確版本,如何確認?

回答

1

您不會出現後確認libgcov.a庫尚未建成使用調試符號,我已經安裝了debuginfo軟包

瞭解debuginfo軟包是如何工作的。它們不能奇蹟般地將debuginfo添加到沒有調試符號(或已被剝離)的內置庫中。

通常構建流程是:

  • 建立一切與-g
  • 所有完全聯二進制文件準備單獨debuginfo軟包(可執行文件和共享庫)
  • fully-鏈接二進制文件(但不是存檔庫)

這允許二進制文件和共享庫很小,但在安裝debuginfo包後仍然可以調試。

顯然,在SLES10上,「但不存檔的庫」沒有兌現,並且libgcov.a也被剝離了。由於單獨的debuginfo軟件包不適用于歸檔庫,因此無法恢復該信息。您唯一的選擇是從源重建GCC。

P.S.他們爲什麼要去掉libgcov.a

這是一個權衡:最終用戶鏈接的二進制文件將會更小,但libgcov.a中的代碼將不可調試。

由於大多數最終用戶從不調試libgcov.a,我認爲這不是一種不合理的折衷。

+0

@ernesto我已經更新了答案。 –

+0

感謝您的信息。雖然看起來很明顯,但請澄清一下:對於靜態庫,調試符號將在可執行文件鏈接的機器上,而不是運行exe的機器上,對嗎?當程序運行時,機器是否有帶調試符號的靜態庫並不重要。 – ernesto

+1

@ernesto這是正確的:將歸檔庫複製到在靜態鏈接(構建)時與其鏈接的二進制文件中。歸檔庫在運行時*不在所有*處使用,並且不需要存在。 –

相關問題