Question

I am trying to debug gcov code. I wrote a simple C program which calls __gcov_flush() method which is part of gcc/gcov.

After confirming that libgcov.a library has not been built with debug symbols, I have installed debuginfo packages for gcc on my machine (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

However, even after installing the proper version of debuginfo (gcov.debug) packages, GDB still cannot recognize the line number information, it just passes the control to next line without reporting line number (or stepping into the function).

(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".

Why GDB cannot identify line number information for gcov? If I have not installed the proper version of debuginfo packages for gcc/gcov, How to confirm it?

Was it helpful?

Solution

After confirming that libgcov.a library has not been built with debug symbols, I have installed debuginfo packages

You don't appear to understand how debuginfo packages work. They can't magically add debuginfo to an archive library that was built without debug symbols (or one that was stripped).

The usual build flow is:

  • build everything with -g
  • prepare separate debuginfo packages for all fully-linked binaries (executables and shared libraries)
  • strip fully-linked binaries (but not archive libraries)

This allows binaries and shared libraries to be small, but still debuggable after installing the debuginfo package.

Apparently, on SLES10 the "but not archive libraries" was not honored, and libgcov.a got stripped as well. Since separate debuginfo packages do not work for archive libraries, you can't get that info back. Your only option is to rebuild GCC from sources.

P.S. Why would they strip libgcov.a?

It's a trade-off: binaries that end-users link will be smaller, but code in libgcov.a will not be debuggable.

Since most end-users never debug libgcov.a, I'd say it was not an unreasonable trade-off.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top