Windows 7 64位,Visual Studio 2010,控制台C ++应用程序,Win32调试配置:
#include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { char* p = NULL; *p = 1; return 0; }
开始调试。显然,我得到了这个错误消息:
Unhandled exception at 0x77d915de in test.exe: 0xC0000005: Access violation writing location 0x00000000.
我选择Debug并查看以下堆栈:
ntdll.dll!77d915de() [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] ntdll.dll!77d915de() ntdll.dll!77d8014e() msvcr100d.dll!_heap_alloc_dbg_impl(unsigned int nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 504 + 0xc bytes C++ >ffffffff()
调试器在dbgheap.c中的__finally
行中断。堆栈已损坏,堆栈中缺少行*p = 1
。输出窗口:
'test.exe': Loaded 'C:\tmp\test\Debug\test.exe', Symbols loaded. 'test.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file 'test.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file 'test.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file 'test.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded. First-chance exception at 0x010f13a8 in test.exe: 0xC0000005: Access violation writing location 0x00000000. Unhandled exception at 0x77d915de in test.exe: 0xC0000005: Access violation writing location 0x00000000.
现在,如果我在x64 Debug配置中运行相同的程序,一切正常 - 调试器在行*p = 1
上中断。如何正确调试Win32程序?
答案 0 :(得分:3)
Debug-> Exceptions-> win32 Exception-> c0000005勾选“Thrown”列或整个Win32 Exceptions http://msdn.microsoft.com/en-us/library/038tzxdw(v=vs.100).aspx
的“Thrown”列中的框*p = 1;
00041375 mov eax,dword ptr [p]
00041378 mov byte ptr [eax],1
test2.exe中0x00041378处的第一次机会异常:0xC0000005:访问冲突写入位置0x00000000