2018-01-12 创建人:Ruo_Xiao
2018-01-15 修改人:Ruo_Xiao
添加为dump、exe和pdb版本保持一致的原因。
后续加入!
1、 exe文件、dmp文件和pdb文件必须保持一致!
在上篇博客中,我们简单的介绍了如何用dmp文件和pdb文件定位代码中崩溃位置。链接如下:
http://blog.csdn.net/itworld123/article/details/79041500
上述能够成功定位的一个前提是exe文件、dmp文件和pdb文件都是同时生成的,即:exe文件和pdb文件同时生成,dmp文件是由当前exe生成的。若生成崩溃信息之后,又重新编译了exe,与此同时也重新生成了pdb文件,那么即使代码没有任何改动,此时WinDbg也没有办法进行代码行号定位了,显示的信息如下:
WRITE_ADDRESS: 0000000c
FOLLOWUP_IP:
TEST11+100b
012b100b c7050c00000005000000 mov dword ptr ds:[0Ch],5
MOD_LIST:
FAULTING_THREAD: 0000139c
BUGCHECK_STR: APPLICATION_FAULT_NULL_CLASS_PTR_DEREFERENCE_INVALID_POINTER_WRITE_WRONG_SYMBOLS
PRIMARY_PROBLEM_CLASS: NULL_CLASS_PTR_DEREFERENCE
DEFAULT_BUCKET_ID: NULL_CLASS_PTR_DEREFERENCE
LAST_CONTROL_TRANSFER: from 746b336a to 012b100b
STACK_TEXT:
WARNING: Stack unwind information not available. Following frames may be wrong.
0029f934 746b336a 7efde000 0029f980 77139902 TEST11+0x100b
0029f940 77139902 7efde000 7735f926 00000000 kernel32!BaseThreadInitThunk+0x12
0029f980 771398d5 012b132d 7efde000 00000000 ntdll!RtlInitializeExceptionChain+0x63
0029f998 00000000 012b132d 7efde000 00000000 ntdll!RtlInitializeExceptionChain+0x36
STACK_COMMAND: ~0s; .ecxr ; kb
SYMBOL_STACK_INDEX: 0
SYMBOL_NAME: TEST11+100b
FOLLOWUP_NAME: MachineOwner
IMAGE_NAME: TEST11.exe
BUCKET_ID: WRONG_SYMBOLS
FAILURE_BUCKET_ID: NULL_CLASS_PTR_DEREFERENCE_c0000005_TEST11.exe!Unknown
WATSON_STAGEONE_URL: http://watson.microsoft.com/StageOne/TEST11_exe/0_0_0_0/5a58a12a/TEST11_exe/0_0_0_0/5a58a12a/c0000005/0000100b.htm?Retriage=1
Followup: MachineOwner
上述信息大家可以看到,定位源码的功能已经消失了。
2、关闭代码优化功能。
#include "stdafx.h"
#include
#include
#pragma comment(lib,"Dbghelp.lib")
static long __stdcall CrashInfocallback(_EXCEPTION_POINTERS *pexcp);
void ErrorFun(int *p)
{
p[2] = 10; //这里崩溃
}
int _tmain(int argc, _TCHAR* argv[])
{
::SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)CrashInfocallback);
int *pi = NULL;
ErrorFun(pi);
return 0;
}
long __stdcall CrashInfocallback( _EXCEPTION_POINTERS *pexcp)
{
HANDLE hDumpFile = ::CreateFile(
L"MEMORY.DMP",
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if( hDumpFile != INVALID_HANDLE_VALUE)
{
MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
dumpInfo.ExceptionPointers = pexcp;
dumpInfo.ThreadId = ::GetCurrentThreadId();
dumpInfo.ClientPointers = TRUE;
::MiniDumpWriteDump(
::GetCurrentProcess(),
::GetCurrentProcessId(),
hDumpFile,
MiniDumpNormal,
&dumpInfo,
NULL,
NULL
);
}
::CloseHandle(hDumpFile);
return 0;
}
上述代码在没有关闭代码优化功能的情况下,按照上篇博客的方法,生成的信息如下:
WRITE_ADDRESS: 00000008
FOLLOWUP_IP:
TEST11!wmain+b [d:\huawei\projects\test11\test11\test11.cpp @ 22]
013e100b c705080000000a000000 mov dword ptr ds:[8],0Ah
MOD_LIST:
FAULTING_THREAD: 00000814
BUGCHECK_STR: APPLICATION_FAULT_NULL_CLASS_PTR_DEREFERENCE_INVALID_POINTER_WRITE_WRONG_SYMBOLS
PRIMARY_PROBLEM_CLASS: NULL_CLASS_PTR_DEREFERENCE
DEFAULT_BUCKET_ID: NULL_CLASS_PTR_DEREFERENCE
LAST_CONTROL_TRANSFER: from 013e120c to 013e100b
STACK_TEXT:
0038f9cc 013e120c 00000001 00032888 00033a40 TEST11!wmain+0xb [d:\huawei\projects\test11\test11\test11.cpp @ 22]
0038fa10 746b336a 7efde000 0038fa5c 77139902 TEST11!__tmainCRTStartup+0x122 [f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 552]
WARNING: Stack unwind information not available. Following frames may be wrong.
0038fa1c 77139902 7efde000 775e96bf 00000000 kernel32!BaseThreadInitThunk+0x12
0038fa5c 771398d5 013e132d 7efde000 00000000 ntdll!RtlInitializeExceptionChain+0x63
0038fa74 00000000 013e132d 7efde000 00000000 ntdll!RtlInitializeExceptionChain+0x36
STACK_COMMAND: ~0s; .ecxr ; kb
FAULTING_SOURCE_CODE:
18: int _tmain(int argc, _TCHAR* argv[])
19: {
20: ::SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)CrashInfocallback);
21: int *pi = NULL;
> 22: ErrorFun(pi);
23: return 0;
24: }
25:
26: long __stdcall CrashInfocallback( _EXCEPTION_POINTERS *pexcp)
27: {
SYMBOL_STACK_INDEX: 0
SYMBOL_NAME: test11!wmain+b
FOLLOWUP_NAME: MachineOwner
IMAGE_NAME: TEST11.exe
BUCKET_ID: WRONG_SYMBOLS
FAILURE_BUCKET_ID: NULL_CLASS_PTR_DEREFERENCE_c0000005_TEST11.exe!wmain
WATSON_STAGEONE_URL: http://watson.microsoft.com/StageOne/TEST11_exe/0_0_0_0/5a58a3c4/TEST11_exe/0_0_0_0/5a58a3c4/c0000005/0000100b.htm?Retriage=1
Followup: MachineOwner
大家可以发现,WinDbg确实定位到了源码位置,但是仅仅是函数外面,没有进去。
后来上网查了很多资料,最后隐约感觉到可能是Release代码优化的原因,所以当我关闭代码优化的时候,成功地定位到了真正的位置。信息如下:
WRITE_ADDRESS: 00000008
FOLLOWUP_IP:
TEST11!ErrorFun+6 [d:\huawei\projects\test11\test11\test11.cpp @ 15]
00df1006 c740080a000000 mov dword ptr [eax+8],0Ah
MOD_LIST:
FAULTING_THREAD: 000013ac
BUGCHECK_STR: APPLICATION_FAULT_NULL_CLASS_PTR_DEREFERENCE_INVALID_POINTER_WRITE_WRONG_SYMBOLS
PRIMARY_PROBLEM_CLASS: NULL_CLASS_PTR_DEREFERENCE
DEFAULT_BUCKET_ID: NULL_CLASS_PTR_DEREFERENCE
LAST_CONTROL_TRANSFER: from 00df102f to 00df1006
STACK_TEXT:
0028fbfc 00df102f 00000000 00000000 0028fc50 TEST11!ErrorFun+0x6 [d:\huawei\projects\test11\test11\test11.cpp @ 15]
0028fc0c 00df1232 00000001 003b2888 003b3a40 TEST11!wmain+0x1f [d:\huawei\projects\test11\test11\test11.cpp @ 22]
0028fc50 746b336a 7efde000 0028fc9c 77139902 TEST11!__tmainCRTStartup+0x122 [f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 552]
WARNING: Stack unwind information not available. Following frames may be wrong.
0028fc5c 77139902 7efde000 77413872 00000000 kernel32!BaseThreadInitThunk+0x12
0028fc9c 771398d5 00df1353 7efde000 00000000 ntdll!RtlInitializeExceptionChain+0x63
0028fcb4 00000000 00df1353 7efde000 00000000 ntdll!RtlInitializeExceptionChain+0x36
STACK_COMMAND: ~0s; .ecxr ; kb
FAULTING_SOURCE_CODE:
11: static long __stdcall CrashInfocallback(_EXCEPTION_POINTERS *pexcp);
12:
13: void ErrorFun(int *p)
14: {
> 15: p[2] = 10; //?a¨¤?¡À¨¤¨¤¡ê
16: }
17:
18: int _tmain(int argc, _TCHAR* argv[])
19: {
20: ::SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)CrashInfocallback);
SYMBOL_STACK_INDEX: 0
SYMBOL_NAME: test11!ErrorFun+6
FOLLOWUP_NAME: MachineOwner
IMAGE_NAME: TEST11.exe
BUCKET_ID: WRONG_SYMBOLS
FAILURE_BUCKET_ID: NULL_CLASS_PTR_DEREFERENCE_c0000005_TEST11.exe!ErrorFun
WATSON_STAGEONE_URL: http://watson.microsoft.com/StageOne/TEST11_exe/0_0_0_0/5a58a4b0/TEST11_exe/0_0_0_0/5a58a4b0/c0000005/00001006.htm?Retriage=1
Followup: MachineOwner
拓展:VS2010关闭代码优化的方法:
项目 -> 工程名 + 属性
弹出如下图所示的框:
对“优化”选择“已禁用”,默认为“使速度最大化”,确定之后,重新编译程序即可。
http://download.csdn.net/download/itworld123/10203098