I'm debugging a project that uses precompiled headers under GDB. While inspecting crash stack trace, I found that GDB prints correct functions names but incorrect file and line number information.
Look at the following examples:
file.h
#ifndef FILE_H_
#define FILE_H
#include "../precompiled_header.h"
void func_A();
void func_B();
#endif //FILE_H
Notice that there are only five lines in the header.
file.cpp
#include "file.h"
void func_A()
{
int *a = 0;
*a =0;
}
void func_B()
{
func_A();
}
int main()
{
func_B();
return 0;
}
gdb program -> run -> bt: will print something like
....
func_A(): file.h at 32 <- incorrect file and line information
func_B(): file.h at 40 <- incorrect file and line information
main(): file.cpp at 14
As soon as I remove precompiled_header.h.gch, gdb prints
func_A(): file.cpp at 5 <- OK!
func_B(): file.cpp at 10 <- OK!
main(): file.cpp at 14
I'm sure that precompiled head and all the files are compiled with the same set of command line flags and that this precompiled header is really found and used(checked with -H option). No optimizations are turned on.
The program is compiled with
-D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unused -fexceptions -std=gnu++0x-fPIC -Winvalid-pch -Wdisabled-optimization -Wuninitialized -Wsequence-point -Winit-self
gcc -v gives the following output
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5.1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux- gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
What could be wrong here?