問題描述
我在這里遇到了薛定諤的貓"類型的問題——我的程序(實(shí)際上是我的程序的測試套件,但仍然是一個(gè)程序)崩潰了,但只有在發(fā)布模式下構(gòu)建時(shí),并且只有在從命令行.通過穴居人調(diào)試(即到處都是討厭的 printf() 消息),我確定了代碼崩潰的測試方法,盡管不幸的是,實(shí)際崩潰似乎發(fā)生在某些析構(gòu)函數(shù)中,因?yàn)槲铱吹降淖詈笠粭l跟蹤消息在其他可以干凈執(zhí)行的析構(gòu)函數(shù).
I've got a "Schroedinger's Cat" type of problem here -- my program (actually the test suite for my program, but a program nonetheless) is crashing, but only when built in release mode, and only when launched from the command line. Through caveman debugging (ie, nasty printf() messages all over the place), I have determined the test method where the code is crashing, though unfortunately the actual crash seems to happen in some destructor, since the last trace messages I see are in other destructors which execute cleanly.
當(dāng)我嘗試在 Visual Studio 中運(yùn)行這個(gè)程序時(shí),它沒有崩潰.從 WinDbg.exe 啟動(dòng)時(shí)也是如此.只有從命令行啟動(dòng)時(shí)才會(huì)發(fā)生崩潰.這發(fā)生在 Windows Vista 下,順便說一句,不幸的是我現(xiàn)在無法訪問 XP 機(jī)器進(jìn)行測試.
When I attempt to run this program inside of Visual Studio, it doesn't crash. Same goes when launching from WinDbg.exe. The crash only occurs when launching from the command line. This is happening under Windows Vista, btw, and unfortunately I don't have access to an XP machine right now to test on.
如果我能讓 Windows 打印出堆棧跟蹤,或者除了簡單地終止程序,就像它已經(jīng)干凈地退出一樣其他東西,那就太好了.有沒有人對我如何在此處獲取更有意義的信息并希望修復(fù)此錯(cuò)誤有任何建議?
It would be really nice if I could get Windows to print out a stack trace, or something other than simply terminating the program as if it had exited cleanly. Does anyone have any advice as to how I could get some more meaningful information here and hopefully fix this bug?
問題確實(shí)是由越界數(shù)組引起的,我在這篇文章中對此進(jìn)行了更多描述.感謝大家?guī)椭业竭@個(gè)問題!
The problem was indeed caused by an out-of-bounds array, which I describe more in this post. Thanks everybody for your help in finding this problem!
推薦答案
在我見過或聽說過的 100% 的情況下,C 或 C++ 程序在調(diào)試器中運(yùn)行良好,但在外部運(yùn)行時(shí)失敗,原因是一直寫到函數(shù)局部數(shù)組的末尾.(調(diào)試器會(huì)在堆棧上放置更多內(nèi)容,因此您不太可能覆蓋重要的內(nèi)容.)
In 100% of the cases I've seen or heard of, where a C or C++ program runs fine in the debugger but fails when run outside, the cause has been writing past the end of a function local array. (The debugger puts more on the stack, so you're less likely to overwrite something important.)
這篇關(guān)于程序僅在發(fā)布版本時(shí)崩潰——如何調(diào)試?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!