GCC 调试器堆栈跟踪显示错误的文件名和行号

GCC debugger stack trace displays wrong file name and line number(GCC 调试器堆栈跟踪显示错误的文件名和行号)
本文介绍了GCC 调试器堆栈跟踪显示错误的文件名和行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

什么会导致 GDB 出现如此严重的故障?我已经检查了代码中的 #line 和 #file 语句,并确保代码只有 unix 行结尾.我还清理并重建了该项目.我也尝试过调试一个 Hello World 项目,但没有遇到同样的问题.

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?

以下是 gccld 的两个示例调用"nofollow noreferrer">Xcode.AFAIK 我项目中的所有 cpp 文件都使用相同的参数进行编译和链接.

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.

/开发者/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/GemsweeperMac/TSDLGameBase.cpp" -o"/Users/adrianrigore/Documents/GemsweeperMac/构建/GemsweeperMac.build/Debug/GemsweeperMac.build/Objects-normal/i386/TSDLGameBase.o"

/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"

/开发者/usr/bin/g++-4.0 -arch i386-isysroot/Developer/SDKs/MacOSX10.5.sdk"-L/用户/adrianrigore/文档/GemsweeperMac/构建/调试"-L/开发者/SDKs/MacOSX10.5.sdk/usr/local/lib-L/opt/local/lib "-F/Users/adrianrigore/Documents/GemsweeperMac/构建/调试"-F/用户/adrianrigore/库/框架-F/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks-filelist "/Users/adrianrigore/Documents/GemsweeperMac/构建/GemsweeperMac.build/Debug/GemsweeperMac.build/Objects-normal/i386/GemsweeperMac.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/adrianrigore/Documents/Gemsweeper麦克/第三派对/FreeImage/Dist/libfreeimage.a""/Users/adrianrigore/Documents/Gemsweeper麦克/第三派对/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/GemsweeperMac/构建/调试/GemsweeperMac.app/Contents/MacOS/Gemsweeper Mac"

/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"

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

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.

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

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.

我已经尝试编译一个 Xcode SDL 项目模板,但没有遇到同样的问题,所以这一定是由于我的项目中的一些特殊情况.

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.

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

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.

推荐答案

当我的 gdb 版本与我的 g++ 版本不匹配时,我得到了这些症状.

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

尝试获取最新的 gdb.

Try to get the newest gdb.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)