VS2008 C++仅当单步调试模式时发生 MFC 访问冲突
这太疯狂了。它开始发生在我的主项目中,所以我创建了一个小的示例全新项目来重现它,果然。它不会发生在我创建的仅是一个 Win32 控制台应用程序的示例项目中。
我在 Win7x64 上运行这个,如果这很重要的话。 VS2008 SP1。
就这样吧。我创建了一个带有按钮的小对话框应用程序。在该按钮的处理函数中放置一个断点。按钮处理函数如下所示:
void CTestProjectDlg::OnBnClickedButton1()
{
int i;
i = 2; // < breakpoint here
i = 3;
}
单击按钮,命中断点。 F10 进入步骤,然后繁荣:“TestProject.exe 中 0x0398f77b 处的第一次机会异常:0xC0000005:访问冲突。”
它让我可以选择“中断”或“继续”。如果我继续,它只会再次命中,而不是“第一次机会”。是的,我在“调试”->“异常”dlg 中检查了该异常。
如果我中断,调用堆栈只会显示断点所在的行。如果我再次 F10.. 我再次遇到异常,只是现在调用堆栈在 _AfxDispatchCmdMsg() 函数中显示我,而我原来的 OnBnClickedButton1() 不再在调用堆栈中。
我将断点放在哪里并不重要。
如果我不按 F10,而是按 F5 继续,则可以正常工作。
现在..如果我构建一个发布版本并在调试模式下运行:我命中断点,所有指针、变量值看起来都正常。 F10,这些就变成垃圾了。 this 指针现在为零。 m_csHello 现在是
但是,在 Release 模式下,不会捕获异常,并且一切运行良好。 “hello World 字符串按其应有的方式显示在对话框中。
我已进行查询,看看 IT 部门在过去一两天内是否在我的盒子上安装了某些补丁。两天前还没有发生这种情况.
您认为 VS2008 是否已损坏?
谢谢。
如果我构建/调试 x64 平台,则不会发生这种情况。 我还查看了包装盒上 VS2008 的所有修补程序/安全更新。它们是
最后,我将项目放在另一台过去 2-3 周没有更新的机器上。它可以在那里找到,并且安装了相同的 VS 更新。
我还更改了出于本文目的而跳过的代码。 ..这是一个简单的整数赋值,不涉及MFC。
目前我正在重新安装VS2008。
This is crazy. It started happening in my main project, so I created a tiny sample brand-new project to reproduce it in and sure enough.. It does NOT happen in a sample project I created that is only a Win32 console app.
I'm running this on Win7x64, if that matters. VS2008 SP1.
Here goes. I create a small dialog app with a button. Put a breakpoint in the handler function for that button. The button handler function looks like this:
void CTestProjectDlg::OnBnClickedButton1()
{
int i;
i = 2; // < breakpoint here
i = 3;
}
Click the button, hit the breakpoint. F10 to step, and boom: "First-chance exception at 0x0398f77b in TestProject.exe: 0xC0000005: Access violation."
It gives me the option to Break or Continue. If I Continue, it just hits it again, only not "First Chance". Yes I have that exception checked in the Debug->Exceptions dlg.
If I Break, the call stack just shows me the line where the breakpoint is. If I F10 again.. I get the exception again, only now the callstack shows me in the _AfxDispatchCmdMsg() function, and my original OnBnClickedButton1() is not in the callstack anymore.
It doesn't matter where I put the breakpoint.
If, instead of F10, I just continue with F5, it works normally.
Now.. if I build a Release version and run in debugging mode: I hit the breakpoint, and all the pointers, variable values look normal. F10, and these turn to garbage. The this pointer is now zero. The m_csHello is now
However, in Release mode, an exception is not caught, and it all runs fine. The "hello World string gets displayed in the dialog box as it should.
I have put in an inquiry to see if some patch was installed on my box by the IT dept in the last day or two. This wasn't happening 2 days ago.
What do you think? Is VS2008 corrupted?
Thanks.
Edit: Additional Information. This does not happen if I build/debug the x64 platform. Only for Win32.
I also took a look at all of the hotfixes/security updates for VS2008 on the box. They are
Finally, I put the project on a different machine that has not been updated for the past 2-3 weeks. It works find on there, and it has these same VS updates installed.
I have also altered the code that is being stepped over for the purpose of this post. .. It is a simple integer assignment, no MFC involved.
At the moment I am in the middle of re-installing VS2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
VS2008 SP1,Win7x64,调试32位代码也有同样的问题。如果我关闭选项
工具 -> , 问题就会消失。选项->调试->本机->启用 RPC 调试。
以下条目可能与此相关:
调试命令(单步执行/进入)导致未处理的异常
Had the same problem with VS2008 SP1, Win7x64, debugging code in 32bit. The problem vanishes if I turn off the option
Tools -> Options -> Debugging -> Native -> Enable RPC Debugging.
The following entry may be related to this:
Debugging commands (step over/into) cause unhandled exceptions
您说同一个项目在具有相同版本的 Visual Studio 的不同计算机上编译并运行得很好。代码看起来不错,所以是的,听起来 VS 2008 已损坏,需要重新安装。
You say the same project compiles and runs just fine on a different machine with the same version of Visual Studio. The code looks fine, so yeah, it sounds like VS 2008 is corrupted and needs to be reinstalled.
我也遇到同样的事情,再次在Win7x64,VS2008 SP1开发平台上。我的代码是c++、WTL、ATL、DirectShow 和各种其他库。
Windows 更新日志显示午餐时间我的计算机上有一个 Windows 更新。该问题仅在午餐时间后开始出现 - 没有项目更改!
该死的你和你愚蠢的自动更新破坏了开发环境m$!!!你们真丢脸!
I'm also experiencing the same thing, again on the Win7x64, VS2008 SP1 development platform. My code is c++, WTL, ATL, DirectShow and various other libraries.
Windows update log reveals that there was a windows update on my machine at lunchtime. The problem only started occurring after lunchtime - with no project changes!
Damn you and your stupid automatic updates that break development environments m$!!! Shame on y'all!
如果它在发布版中有效但不能调试,那么我认为您在某处有一个未初始化的变量。在调试中,它会自动设置为 0xcdcdcdcd (或其子部分,具体取决于变量大小),这会导致您在发布中失败,您已经拥有内存中的任何值,也许该值会阻止它破坏......通常是未初始化的像这样的变量被用作循环绑定,在调试中,您通过内存写入并覆盖一些重要的内容,这可能会在以后导致失败。在发布中,该值恰好是好的,但情况可能并不总是如此。
至于您在发布中的调试,请不要担心 this 值看起来像是空的。它很可能不是,但由于优化过程,调试器很难准确判断您在代码中的位置。
If it works in Release but not debug then I'd reckon you have an uninitialised variable somewhere. In debug it is automatically set to 0xcdcdcdcd (or a sub-portion thereof depending on variable size) which causes you to fail in Release you have whatever value was in memory already and perhaps that value prevents it from breaking ... Quite often an uninitialised variable like this is used as a loop bound and in debug you write through memory and overwrite something important which can LATER cause a failure. In release the value just happens to be OK but it may not always be the case.
As for your debugging in release don't worry that the this value looks like it is null. It most probably isn't but its very hard for the debugger to tell exactly where you are in code due to the optimisation process.
明智的做法是(与直觉相反)放弃所有断点等。重建您的项目(不是增量构建)。重要的是从头开始,捕获异常,获得干净的调用堆栈,并确保源文件的构建是准确的。您还应该禁用预编译头等。
The smart thing to do is (counter-intuitively) chuck all the breakpoints and such out. Rebuild your project (not an incremental build). The important thing is to start from a clean slate, grab the exception, and get a clean call stack and make sure that the build is accurate of the source files. You should also disable pre-compiled headers and such.