Incorrect stack trace with precompiled GCC + header
I am debugging a project that uses pre-compiled headers under GDB. While checking the crash stack trace, I found that GDB was printing correct function names but incorrect file and line details.
Take a 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
Note 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 -> 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
Once 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 am sure that the precompiled chapter and all files are compiled with the same set of command line flags and that this precompiled header was actually found and used (marked with the -H option). Optimization not included.
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-pointinitialized -Wsequence
gcc -v gives the following output
Using built-in specifications.
Target: x86_64-linux-gnu
Configurable 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-check = release --build = x86_64-linux-gnu --host = x86_64-linux-gnu --target = x86_64-linux-gnu
Theme Model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
What could be wrong here?
source to share
This is a compiler error: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44550
Fixed in g ++ 4.5, so you must update your compiler.
However, it would be better to include your precompiled header as the first line of the cpp file instead of the h file, since the precompiled header inclusion should be at the top of the compilation block. In your case, you will include it every time you include your header file. This change will stop this error from you.
source to share