异常没有在-O2上发现

时间:2015-06-10 09:28:38

标签: c++ g++

我目前正在为OpenTTD NoAI API添加一些功能。但是,我遇到的问题似乎来自OpenTTD代码。问题是代码适用于我测试过的所有系统,除了一个。

ScriptObject::DoCommand方法中,抛出Script_Suspend类的实例。这应该在ScriptInstance::GameLoop方法中捕获。在一个系统上,当使用-O2或-O3编译程序时,不会捕获异常并且程序崩溃。它在-O0和-O1上工作正常。

要调试程序,我使用backtrace and backtrace_symbols函数在多个点打印堆栈跟踪:

堆栈跟踪-O0

In Script_Instance::GameLoop
./openttd-build/openttd(_ZN14ScriptInstance8GameLoopEv+0x156) [0x75f3ae]
./openttd-build/openttd(_ZN2AI8GameLoopEv+0xef) [0x52c455]
./openttd-build/openttd(_Z13StateGameLoopv+0xc26) [0x6a93a3]
./openttd-build/openttd(_Z8GameLoopv+0x7a) [0x6a967c]
./openttd-build/openttd(_ZN16VideoDriver_Null8MainLoopEv+0x19) [0x80ea6d]
./openttd-build/openttd(_Z12openttd_mainiPPc+0x145b) [0x6a7ff2]
./openttd-build/openttd(main+0x3a) [0x6bcebe]
/lib64/libc.so.6(__libc_start_main+0xf4) [0x3f0801d8a4]
./openttd-build/openttd [0x4f39f9]
In ScriptObject::DoCommand:
./openttd-build/openttd(_ZN12ScriptObject9DoCommandEjjjjPKcPFvP14ScriptInstanceE+0x23a) [0x74b420]
./openttd-build/openttd(_ZN13ScriptCompany7SetNameEP4Text+0x81) [0x738d8d]
./openttd-build/openttd(_ZN9SQConvert19DefSQStaticCallbackI13ScriptCompanyPFbP4TextEEExP4SQVM+0x185) [0x5525d5]
./openttd-build/openttd(_ZN4SQVM10CallNativeEP15SQNativeClosurexxR11SQObjectPtrRb+0x334) [0x528fc4]
./openttd-build/openttd(_ZN4SQVM7ExecuteER11SQObjectPtrxxxS1_yNS_13ExecutionTypeE+0x6dc) [0x52348c]
./openttd-build/openttd(_ZN4SQVM4CallER11SQObjectPtrxxS1_yy+0xbc) [0x525992]
./openttd-build/openttd(_Z7sq_callP4SQVMxyyi+0x99) [0x4f88c1]
./openttd-build/openttd(_ZN8Squirrel10CallMethodE11tagSQObjectPKcPS0_i+0xf6) [0x7615c0]
./openttd-build/openttd(_ZN14ScriptInstance8GameLoopEv+0x326) [0x75f57e]
./openttd-build/openttd(_ZN2AI8GameLoopEv+0xef) [0x52c455]
./openttd-build/openttd(_Z13StateGameLoopv+0xc26) [0x6a93a3]
./openttd-build/openttd(_Z8GameLoopv+0x7a) [0x6a967c]
./openttd-build/openttd(_ZN16VideoDriver_Null8MainLoopEv+0x19) [0x80ea6d]
./openttd-build/openttd(_Z12openttd_mainiPPc+0x145b) [0x6a7ff2]
./openttd-build/openttd(main+0x3a) [0x6bcebe]
/lib64/libc.so.6(__libc_start_main+0xf4) [0x3f0801d8a4]
./openttd-build/openttd [0x4f39f9]
In Script_Suspend Constructor:
./openttd-build/openttd(_ZN14Script_SuspendC2EiPFvP14ScriptInstanceE+0x8f) [0x73a81b]
./openttd-build/openttd(_ZN12ScriptObject9DoCommandEjjjjPKcPFvP14ScriptInstanceE+0x290) [0x74b476]
./openttd-build/openttd(_ZN13ScriptCompany7SetNameEP4Text+0x81) [0x738d8d]
./openttd-build/openttd(_ZN9SQConvert19DefSQStaticCallbackI13ScriptCompanyPFbP4TextEEExP4SQVM+0x185) [0x5525d5]
./openttd-build/openttd(_ZN4SQVM10CallNativeEP15SQNativeClosurexxR11SQObjectPtrRb+0x334) [0x528fc4]
./openttd-build/openttd(_ZN4SQVM7ExecuteER11SQObjectPtrxxxS1_yNS_13ExecutionTypeE+0x6dc) [0x52348c]
./openttd-build/openttd(_ZN4SQVM4CallER11SQObjectPtrxxS1_yy+0xbc) [0x525992]
./openttd-build/openttd(_Z7sq_callP4SQVMxyyi+0x99) [0x4f88c1]
./openttd-build/openttd(_ZN8Squirrel10CallMethodE11tagSQObjectPKcPS0_i+0xf6) [0x7615c0]
./openttd-build/openttd(_ZN14ScriptInstance8GameLoopEv+0x326) [0x75f57e]
./openttd-build/openttd(_ZN2AI8GameLoopEv+0xef) [0x52c455]
./openttd-build/openttd(_Z13StateGameLoopv+0xc26) [0x6a93a3]
./openttd-build/openttd(_Z8GameLoopv+0x7a) [0x6a967c]
./openttd-build/openttd(_ZN16VideoDriver_Null8MainLoopEv+0x19) [0x80ea6d]
./openttd-build/openttd(_Z12openttd_mainiPPc+0x145b) [0x6a7ff2]
./openttd-build/openttd(main+0x3a) [0x6bcebe]
/lib64/libc.so.6(__libc_start_main+0xf4) [0x3f0801d8a4]
./openttd-build/openttd [0x4f39f9]

堆叠痕迹-O2

In Script_Instance::GameLoop
./openttd-build/openttd(_ZN14ScriptInstance8GameLoopEv+0x19f) [0x7584bf]
In SciptObject::DoCommand:
./openttd-build/openttd(_ZN12ScriptObject9DoCommandEjjjjPKcPFvP14ScriptInstanceE+0x26d) [0x74660d]
./openttd-build/openttd [0x116e700]
In Script_Suspend:
./openttd-build/openttd(_ZN14Script_SuspendC2EiPFvP14ScriptInstanceE+0x7e) [0x735aee]
./openttd-build/openttd(_ZN12ScriptObject9DoCommandEjjjjPKcPFvP14ScriptInstanceE+0x2c0) [0x746660]
./openttd-build/openttd [0x116e700]

我注意到-O2中的堆栈跟踪要短得多。这可能是某种被破坏的调用堆栈,如果是这样,它可能是由什么引起的?

使用的编译器是CentOS 5.11上的GCC 4.7。

0 个答案:

没有答案