GCC调试器堆栈跟踪显示错误的文件名和行号 [英] GCC debugger stack trace displays wrong file name and line number

查看:188
本文介绍了GCC调试器堆栈跟踪显示错误的文件名和行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Mac OS X上移植一个相当大的C ++项目来使用g ++ 4.0。我的项目编译没有错误,但是我无法让GDB正常工作。当我在GDB命令行输入bt来查看堆栈时,显示的所有文件名和行号都是错误的。



例如,根据GDB堆栈跟踪,我的 main()函数应该是stdexcept Mac OS X SDK,这没有任何意义。

什么可能导致GDB发生故障?我已经在代码中检查了#line和#file语句,并确保代码只有unix行结尾。我也清理并重建了这个项目。我也尝试过调试一个Hello World项目,并且这个项目没有同样的问题。



问题可能与我所在的第三方库之一有关链接和编译的方式?或者是完全不同的东西?



以下是对 gcc ld的两个示例性调用 Xcode 执行。 AFAIK我的项目中的所有cpp文件都被编译并链接到相同的参数。


/Developer/usr/bin/gcc-4.0 -x c ++
-arch i386 -fmessage-length = 0 -pipe -Wno-trigraphs -fascal-strings -fasm-blocks -O0 -fpermissive -Wreturn -Wunused-variable -DNO_BASS_SOUND -D_DEBUG -DXCODE -D__WXMAC__ -isysroot /Developer/SDKs/MacOSX10.5.sdk
-mfix -and-continue -fvisibility-inlines-hidden -mmacosx-version -min = 10.4 -gdwarf-2 -D_FILE_OFFSET_BITS = 64 -D_LARGE_FILES -D__WXDEBUG__ -D__WXMAC__ -c/ Users / adriangrigore / Documents / Gemsweeper
Mac / TSDLGameBase .cpp-o
/ Users / adriangrigore / Documents / Gemsweeper
Mac / build / Gemsweeper
Mac.build/Debug/Gemsweeper
Mac.build/Objects-normal/ i386 / TSDLGameBase.o

/ Developer / usr / bin / g ++ - 4.0 -arch i386
-isysroot /Developer/SDKs/MacOSX10.5.sdk
-L / Users / adriangrigore / Documents / Gemsweeper
Mac / build / Debug
-L ​​/ Developer / SDKs / MacOSX10.5.sdk / usr / local / lib
-L ​​/ opt / local / lib-F / Users / adriangrigore / Documents / Gemsweeper
Mac / build / Debug
-F / Users / adriangrigore / Library / Frameworks
-F / Developer / SDKs / MacOSX10.5.sdk / Library / Frameworks
-filelist / Users / adriangrigore / Documents / Gemsweeper
Mac / build / Gemsweeper
Mac.build/Debug/Gemsweeper
Mac.build/Objects-normal/i386/Gemsweeper
Mac。 LinkFileList
-mmacosx-version-min = 10.4 /opt/local/lib/libboost_program_options-mt.a
/opt/local/lib/libboost_filesystem-mt.a
/ opt / local /lib/libboost_serialization-mt.a
/opt/local/lib/libboost_system-mt.a
/opt/local/lib/libboost_thread-mt.a
/ Users / adriangrigore /文件/ Gemsweeper
Mac / 3rd
派对/ FreeImage / Dist / libfreeimage.a
/ Users / adriangrigore / Documents / Gemsweeper
Mac / 3rd
派对/ cpuinfo-1.0 / libcpuinfo.a
-L ​​/ usr / local / lib -framework IOKit -framework Carbon -framework Cocoa -framework System -framework QuickTime -framework OpenGL -framework AGL -lwx_macd_richtext-2.8 -lwx_macd_aui-2.8 - lwx_macd_ xrc-2.8 -lwx_macd_qa-2.8 -lwx_macd_html-2.8 -lwx_macd_adv-2.8 -lwx_macd_core-2.8 -lwx_base_carbond_xml-2.8 -lwx_base_carbond_net-2.8 -lwx_base_carbond-2.8 -framework SDL -framework Cocoa -o/ Users / adriangrigore / Documents / Gemsweeper
Mac / build / Debug / Gemsweeper
Mac.app/Contents/MacOS/Gemsweeper Mac


请注意,我已经问过关于Xcode调试器的一个类似的问题: here < a>,但我正在重新发布,因为我刚刚得知这实际上不是Xcode的错,而是GCC / ld / GDB的问题。



编辑: 我的项目使用以下第三方库: SDL Boost wxWidgets 。我不确定这个问题是否重要,但我只是想提一下它,以防万一。



我试过编译一个Xcode SDL项目模板,并没有遇到同样的问题,所以它必须是由于我的项目中特殊的东西。



第二次编辑:正如我刚刚发现的那样,我在搜索字符串为这是自动生成的文件时犯了一个错误。我刚刚找到几十个具有相同字符串的文件,它们都属于 FreeImage ,它是第三方库之一正在使用。所以,这个问题似乎与FreeImage有关,但我仍然不确定如何继续。

解决方案

症状,当我的gdb版本不符合我的g ++版本。



尝试获取最新的gdb。


I am trying to port a fairly large C++ project to using g++ 4.0 on Mac OS X. My project compiles without errors, but I can't get GDB to work properly. When I look at the stack by typing "bt" on the GDB command line, all file names and line numbers displayed are wrong.

For example, according to the GDB stack trace, my main() function is supposed to be in stdexcept from the Mac OS X SDK, which does not make any sense.

What could cause GDB to malfunction so badly? I've already checked for #line and #file statements in my code and made sure that the code only has unix line endings. I've also cleaned and rebuilt the project. I've also tried debugging a Hello World project and that one did not have the same problem.

Could the problem have to do with one of the third party libraries I am linking and the way those are compiled? Or is it something completely different?

Here are two exemplary calls to gcc and ld as executed by Xcode. AFAIK all cpp-files in my project are compiled and linked with the same parameters.

/Developer/usr/bin/gcc-4.0 -x c++ -arch i386 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -fpermissive -Wreturn-type -Wunused-variable -DNO_BASS_SOUND -D_DEBUG -DXCODE -D__WXMAC__ -isysroot /Developer/SDKs/MacOSX10.5.sdk -mfix-and-continue -fvisibility-inlines-hidden -mmacosx-version-min=10.4 -gdwarf-2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXDEBUG__ -D__WXMAC__ -c "/Users/adriangrigore/Documents/Gemsweeper Mac/TSDLGameBase.cpp" -o "/Users/adriangrigore/Documents/Gemsweeper Mac/build/Gemsweeper Mac.build/Debug/Gemsweeper Mac.build/Objects-normal/i386/TSDLGameBase.o"

/Developer/usr/bin/g++-4.0 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk "-L/Users/adriangrigore/Documents/Gemsweeper Mac/build/Debug" -L/Developer/SDKs/MacOSX10.5.sdk/usr/local/lib -L/opt/local/lib "-F/Users/adriangrigore/Documents/Gemsweeper Mac/build/Debug" -F/Users/adriangrigore/Library/Frameworks -F/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks -filelist "/Users/adriangrigore/Documents/Gemsweeper Mac/build/Gemsweeper Mac.build/Debug/Gemsweeper Mac.build/Objects-normal/i386/Gemsweeper Mac.LinkFileList" -mmacosx-version-min=10.4 /opt/local/lib/libboost_program_options-mt.a /opt/local/lib/libboost_filesystem-mt.a /opt/local/lib/libboost_serialization-mt.a /opt/local/lib/libboost_system-mt.a /opt/local/lib/libboost_thread-mt.a "/Users/adriangrigore/Documents/Gemsweeper Mac/3rd party/FreeImage/Dist/libfreeimage.a" "/Users/adriangrigore/Documents/Gemsweeper Mac/3rd party/cpuinfo-1.0/libcpuinfo.a" -L/usr/local/lib -framework IOKit -framework Carbon -framework Cocoa -framework System -framework QuickTime -framework OpenGL -framework AGL -lwx_macd_richtext-2.8 -lwx_macd_aui-2.8 -lwx_macd_xrc-2.8 -lwx_macd_qa-2.8 -lwx_macd_html-2.8 -lwx_macd_adv-2.8 -lwx_macd_core-2.8 -lwx_base_carbond_xml-2.8 -lwx_base_carbond_net-2.8 -lwx_base_carbond-2.8 -framework SDL -framework Cocoa -o "/Users/adriangrigore/Documents/Gemsweeper Mac/build/Debug/Gemsweeper Mac.app/Contents/MacOS/Gemsweeper Mac"

Please note that I have already asked a similar question regarding the Xcode debugger here, but I am reposting since I just learned that this is in fact not Xcode's fault, but a problem with GCC / ld / GDB.

Edit: My project makes use of the following third-party libraries: SDL, Boost, wxWidgets. I am not sure if this matters for this problem, but I just wanted to mention it just in case it does.

I've tried compiling an Xcode SDL project template and did not experience the same problem, so it must be due to something special in my project.

Second Edit: As I just found out, I made a mistake while searching files with the string "This is an automatically generated". I just found several dozen files with the same string, all belonging to FreeImage, one of the third party libraries I am using. So, the problem seems to be related to FreeImage, but I am not still not sure how to proceed.

解决方案

I got those symptoms, when my gdb version didn't match my g++ version.

Try to get the newest gdb.

这篇关于GCC调试器堆栈跟踪显示错误的文件名和行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆