Windows下Release崩溃定位
1. MAP文件
什么是 MAP 文件?简单地讲, MAP 文件是程序的全局符号、源文件和代码行号信息的唯一的文本表示方法,它可以在任何地方、任何时候使用,不需要有额外的程序进行支持。而且,这是唯一能找出程序崩溃的地方的救星。
2. 如何生成MAP文件
(1)VC6.0 按下 Alt+F7 ,打开“Project Settings”选项页,选择 C/C++ 选项卡,并在最下面的 Project Options 里面输入:/Zd ,然后要选择 Link 选项卡,在最下面的 Project Options 里面输入: /mapinfo:lines 和 /map:PROJECT_NAME.map 。最后按下 F7 来编译生成 EXE 可执行文件和 MAP 文件。
其中,Line Numbers Only选不选没什么影响,主要是Project Options 里面输入: /mapinfo:lines
/Zi — 表示生成pdb调试信息;
/MAP[:filename] — 表示生成map文件名;
/MAPINFO:EXPORTS — 表示生成的map文件中加入exported functions(生成DLL文件时);
/MAPINFO:LINES — 表示生成的map文件中加入代码行信息。
(2)VS2010 首先配置vc2010生成map文件和cod文件:
1)**.map文件:**property->Configuration Properties->Linker->Debugging 中的Generate Map File选择Yes(/MAP);
3. 代码示例
include <stdio.h>
include "kdvtype.h"
void Crash(void)
{
s8 i = 1;
s8 j = 1;
i /= (j-1);
}
int main(void)
{
Crash();
return 0;
}
Crash地址:0x0040101a
4.MAP文件
crash //―――模块名
Timestamp is 57342463 (Thu May 12 14:36:19 2016) //―――时间戳
Preferred load address is 00400000 //―――默认加载基地址
//各节的起始地址、长度、节名、类型等信息
Start Length Name Class
0001:00000000 00004152H .text CODE
0002:00000000 000000a0H .idata$5 DATA
0002:000000a0 000003b4H .rdata DATA
0002:00000454 00000014H .idata$2 DATA
0002:00000468 00000014H .idata$3 DATA
0002:0000047c 000000a0H .idata$4 DATA
0002:0000051c 000002b8H .idata$6 DATA
0002:000007d4 00000000H .edata DATA
0003:00000000 00000004H .CRT$XCA DATA
0003:00000004 00000004H .CRT$XCZ DATA
0003:00000008 00000004H .CRT$XIA DATA
0003:0000000c 00000004H .CRT$XIC DATA
0003:00000010 00000004H .CRT$XIZ DATA
0003:00000014 00000004H .CRT$XPA DATA
0003:00000018 00000004H .CRT$XPZ DATA
0003:0000001c 00000004H .CRT$XTA DATA
0003:00000020 00000004H .CRT$XTZ DATA
0003:00000030 00002490H .data DATA
0003:000024c0 0000051cH .bss DATA
//各符号在节内的偏移地址、加载地址及符号出处
Address Publics by Value Rva+Base Lib:Object
0001:00000000 ?Crash@@YAXXZ 00401000 f crash.obj
0001:00000023 _main 00401023 f crash.obj
0001:0000002f _mainCRTStartup 0040102f f LIBC:crt0.obj
0001:0000010e __amsg_exit 0040110e f LIBC:crt0.obj
0001:00000157 __cinit 00401157 f LIBC:crt0dat.obj
0001:00000184 _exit 00401184 f LIBC:crt0dat.obj
0001:00000195 __exit 00401195 f LIBC:crt0dat.obj
0001:000001a6 __cexit 004011a6 f LIBC:crt0dat.obj
0001:000001b5 __c_exit 004011b5 f LIBC:crt0dat.obj
0001:00000277 __XcptFilter 00401277 f LIBC:winxfltr.obj
0001:000003fb __setenvp 004013fb f LIBC:stdenvp.obj
0001:000004b4 __setargv 004014b4 f LIBC:stdargv.obj
0001:00000701 ___crtGetEnvironmentStringsA 00401701 f LIBC:a_env.obj
0001:00000833 __ioinit 00401833 f LIBC:ioinit.obj
0001:000009de __ioterm 004019de f LIBC:ioinit.obj
0001:00000a01 __GetLinkerVersion 00401a01 f LIBC:heapinit.obj
0001:00000a2e ___heap_select 00401a2e f LIBC:heapinit.obj
0001:00000b76 __heap_init 00401b76 f LIBC:heapinit.obj
0001:00000bd3 __heap_term 00401bd3 f LIBC:heapinit.obj
0001:00000c7c __global_unwind2 00401c7c f LIBC:exsup.obj
0001:00000cbe __local_unwind2 00401cbe f LIBC:exsup.obj
0001:00000d16 __NLG_Return2 00401d16 f LIBC:exsup.obj
0001:00000d26 __abnormal_termination 00401d26 f LIBC:exsup.obj
0001:00000d49 __NLG_Notify1 00401d49 f LIBC:exsup.obj
0001:00000d52 __NLG_Notify 00401d52 f LIBC:exsup.obj
0001:00000d65 __NLG_Dispatch 00401d65 f LIBC:exsup.obj
0001:00000d74 __except_handler3 00401d74 f LIBC:exsup3.obj
0001:00000e31 __seh_longjmp_unwind@4 00401e31 f LIBC:exsup3.obj
0001:00000e4c __FF_MSGBANNER 00401e4c f LIBC:crt0msg.obj
0001:00000e85 __NMSG_WRITE 00401e85 f LIBC:crt0msg.obj
0001:00000fd8 __GET_RTERRMSG 00401fd8 f LIBC:crt0msg.obj
0001:00001009 _free 00402009 f LIBC:free.obj
0001:00001080 _strcpy 00402080 f LIBC:strcat.obj
0001:00001090 _strcat 00402090 f LIBC:strcat.obj
0001:00001170 _malloc 00402170 f LIBC:malloc.obj
0001:00001182 __nh_malloc 00402182 f LIBC:malloc.obj
0001:000011ae __heap_alloc 004021ae f LIBC:malloc.obj
0001:00001230 _strlen 00402230 f LIBC:strlen.obj
0001:000012ab __setmbcp 004022ab f LIBC:mbctype.obj
0001:0000166f __getmbcp 0040266f f LIBC:mbctype.obj
0001:0000167f ___initmbctable 0040267f f LIBC:mbctype.obj
0001:000016a0 _memcpy 004026a0 f LIBC:memcpy.obj
0001:000019d5 _strtol 004029d5 f LIBC:strtol.obj
0001:00001bf4 _strtoul 00402bf4 f LIBC:strtol.obj
0001:00001c20 _strchr 00402c20 f LIBC:strchr.obj
0001:00001c26 ___from_strstr_to_strchr 00402c26 f LIBC:strchr.obj
0001:00001ce0 _strstr 00402ce0 f LIBC:strstr.obj
0001:00001d60 _strncmp 00402d60 f LIBC:strncmp.obj
0001:00001da0 __alloca_probe 00402da0 f LIBC:chkstk.obj
0001:00001da0 __chkstk 00402da0 f LIBC:chkstk.obj
0001:00001dcf __get_sbh_threshold 00402dcf f LIBC:sbheap.obj
0001:00001dee __set_sbh_threshold 00402dee f LIBC:sbheap.obj
0001:00001ea1 ___sbh_heap_init 00402ea1 f LIBC:sbheap.obj
0001:00001ee9 ___sbh_find_block 00402ee9 f LIBC:sbheap.obj
0001:00001f14 ___sbh_free_block 00402f14 f LIBC:sbheap.obj
0001:0000223d ___sbh_alloc_block 0040323d f LIBC:sbheap.obj
0001:00002546 ___sbh_alloc_new_region 00403546 f LIBC:sbheap.obj
0001:000025f7 ___sbh_alloc_new_group 004035f7 f LIBC:sbheap.obj
0001:000026f2 ___sbh_resize_block 004036f2 f LIBC:sbheap.obj
0001:000029e8 ___sbh_heapmin 004039e8 f LIBC:sbheap.obj
0001:00002ab9 ___sbh_heap_check 00403ab9 f LIBC:sbheap.obj
0001:00002de8 __get_old_sbh_threshold 00403de8 f LIBC:sbheap.obj
0001:00002dee __set_ol