📄 csdn_文档中心_如何通过崩溃地址找到出错的代码行(zt).htm
字号:
00001346H .rdata DATA<BR>0002:00001346 00000000H .edata
DATA<BR>0003:00000000 00000104H .CRT$XCA DATA<BR>0003:00000104
00000104H .CRT$XCZ DATA<BR>0003:00000208 00000104H .CRT$XIA
DATA<BR>0003:0000030c 00000109H .CRT$XIC DATA<BR>0003:00000418
00000104H .CRT$XIZ DATA<BR>0003:0000051c 00000104H .CRT$XPA
DATA<BR>0003:00000620 00000104H .CRT$XPX DATA<BR>0003:00000724
00000104H .CRT$XPZ DATA<BR>0003:00000828 00000104H .CRT$XTA
DATA<BR>0003:0000092c 00000104H .CRT$XTZ DATA<BR>0003:00000a30
00000b93H .data DATA<BR>0003:000015c4 00001974H .bss
DATA<BR>0004:00000000 00000014H .idata$2 DATA<BR>0004:00000014
00000014H .idata$3 DATA<BR>0004:00000028 00000110H .idata$4
DATA<BR>0004:00000138 00000110H .idata$5 DATA<BR>0004:00000248
000004afH .idata$6 DATA</P>
<P>Address Publics by Value Rva+Base Lib:Object</P>
<P>0001:00000020 ?Crash@@YAXXZ 00401020 f
CrashDemo.obj<BR>0001:00000070 _main 00401070 f
CrashDemo.obj<BR>0004:00000000 __IMPORT_DESCRIPTOR_KERNEL32 00424000
kernel32:KERNEL32.dll<BR>0004:00000014 __NULL_IMPORT_DESCRIPTOR
00424014 kernel32:KERNEL32.dll<BR>0004:00000138
__imp__GetCommandLineA@0 00424138
kernel32:KERNEL32.dll<BR>0004:0000013c __imp__GetVersion@0 0042413c
kernel32:KERNEL32.dll<BR>0004:00000140 __imp__ExitProcess@4 00424140
kernel32:KERNEL32.dll<BR>0004:00000144 __imp__DebugBreak@0 00424144
kernel32:KERNEL32.dll<BR>0004:00000148 __imp__GetStdHandle@4
00424148 kernel32:KERNEL32.dll<BR>0004:0000014c __imp__WriteFile@20
0042414c kernel32:KERNEL32.dll<BR>0004:00000150
__imp__InterlockedDecrement@4 00424150
kernel32:KERNEL32.dll<BR>0004:00000154 __imp__OutputDebugStringA@4
00424154 kernel32:KERNEL32.dll<BR>0004:00000158
__imp__GetProcAddress@8 00424158
kernel32:KERNEL32.dll<BR>0004:0000015c __imp__LoadLibraryA@4
0042415c kernel32:KERNEL32.dll<BR>0004:00000160
__imp__InterlockedIncrement@4 00424160
kernel32:KERNEL32.dll<BR>0004:00000164 __imp__GetModuleFileNameA@12
00424164 kernel32:KERNEL32.dll<BR>0004:00000168
__imp__TerminateProcess@8 00424168
kernel32:KERNEL32.dll<BR>0004:0000016c __imp__GetCurrentProcess@0
0042416c kernel32:KERNEL32.dll<BR>0004:00000170
__imp__UnhandledExceptionFilter@4 00424170
kernel32:KERNEL32.dll<BR>0004:00000174
__imp__FreeEnvironmentStringsA@4 00424174
kernel32:KERNEL32.dll<BR>0004:00000178
__imp__FreeEnvironmentStringsW@4 00424178
kernel32:KERNEL32.dll<BR>0004:0000017c __imp__WideCharToMultiByte@32
0042417c kernel32:KERNEL32.dll<BR>0004:00000180
__imp__GetEnvironmentStrings@0 00424180
kernel32:KERNEL32.dll<BR>0004:00000184
__imp__GetEnvironmentStringsW@0 00424184
kernel32:KERNEL32.dll<BR>0004:00000188 __imp__SetHandleCount@4
00424188 kernel32:KERNEL32.dll<BR>0004:0000018c __imp__GetFileType@4
0042418c kernel32:KERNEL32.dll<BR>0004:00000190
__imp__GetStartupInfoA@4 00424190
kernel32:KERNEL32.dll<BR>0004:00000194 __imp__HeapDestroy@4 00424194
kernel32:KERNEL32.dll<BR>0004:00000198 __imp__HeapCreate@12 00424198
kernel32:KERNEL32.dll<BR>0004:0000019c __imp__HeapFree@12 0042419c
kernel32:KERNEL32.dll<BR>0004:000001a0 __imp__VirtualFree@12
004241a0 kernel32:KERNEL32.dll<BR>0004:000001a4 __imp__RtlUnwind@16
004241a4 kernel32:KERNEL32.dll<BR>0004:000001a8
__imp__GetLastError@0 004241a8
kernel32:KERNEL32.dll<BR>0004:000001ac
__imp__SetConsoleCtrlHandler@8 004241ac
kernel32:KERNEL32.dll<BR>0004:000001b0 __imp__IsBadWritePtr@8
004241b0 kernel32:KERNEL32.dll<BR>0004:000001b4
__imp__IsBadReadPtr@8 004241b4
kernel32:KERNEL32.dll<BR>0004:000001b8 __imp__HeapValidate@12
004241b8 kernel32:KERNEL32.dll<BR>0004:000001bc __imp__GetCPInfo@8
004241bc kernel32:KERNEL32.dll<BR>0004:000001c0 __imp__GetACP@0
004241c0 kernel32:KERNEL32.dll<BR>0004:000001c4 __imp__GetOEMCP@0
004241c4 kernel32:KERNEL32.dll<BR>0004:000001c8 __imp__HeapAlloc@12
004241c8 kernel32:KERNEL32.dll<BR>0004:000001cc
__imp__VirtualAlloc@16 004241cc
kernel32:KERNEL32.dll<BR>0004:000001d0 __imp__HeapReAlloc@16
004241d0 kernel32:KERNEL32.dll<BR>0004:000001d4
__imp__MultiByteToWideChar@24 004241d4
kernel32:KERNEL32.dll<BR>0004:000001d8 __imp__LCMapStringA@24
004241d8 kernel32:KERNEL32.dll<BR>0004:000001dc
__imp__LCMapStringW@24 004241dc
kernel32:KERNEL32.dll<BR>0004:000001e0 __imp__GetStringTypeA@20
004241e0 kernel32:KERNEL32.dll<BR>0004:000001e4
__imp__GetStringTypeW@16 004241e4
kernel32:KERNEL32.dll<BR>0004:000001e8 __imp__SetFilePointer@16
004241e8 kernel32:KERNEL32.dll<BR>0004:000001ec
__imp__SetStdHandle@8 004241ec
kernel32:KERNEL32.dll<BR>0004:000001f0 __imp__FlushFileBuffers@4
004241f0 kernel32:KERNEL32.dll<BR>0004:000001f4 __imp__CloseHandle@4
004241f4 kernel32:KERNEL32.dll<BR>0004:000001f8
\177KERNEL32_NULL_THUNK_DATA 004241f8 kernel32:KERNEL32.dll</P>
<P>entry point at 0001:000000f0</P>
<P><BR>Line numbers for
.\Debug\CrashDemo.obj(d:\msdev\myprojects\crashdemo\crashdemo.cpp)
segment .text</P>
<P>13 0001:00000020 14 0001:00000038 15 0001:0000003f 16
0001:00000046<BR>17 0001:00000050 20 0001:00000070 21 0001:00000088
22 0001:0000008d </P>
<P>如果仔细浏览 Rva+Base 这栏,你会发现第一个比崩溃地址 0x0040104a 大的函数地址是 0x00401070
,所以在 0x00401070 这个地址之前的那个入口就是产生崩溃的函数,也就是这行:</P>
<P>0001:00000020 ?Crash@@YAXXZ 00401020 f CrashDemo.obj </P>
<P>因此,发生崩溃的函数就是 ?Crash@@YAXXZ ,所有以问号开头的函数名称都是 C++ 修饰的名称。在我们的源程序中,也就是
Crash() 这个子函数。</P>
<P>OK,现在我们轻而易举地便知道了发生崩溃的函数名称,你是不是很兴奋呢?呵呵,先别忙,接下来,更厉害的招数要出场了。</P>
<P>请注意 MAP 文件的最后部分--代码行信息(Line numbers information),它是以这样的形式显示的:</P>
<P>13 0001:00000020 </P>
<P>第一个数字代表在源代码中的代码行号,第二个数是该代码行在所属的代码段中的偏移量。</P>
<P>如果要查找代码行号,需要使用下面的公式做一些十六进制的减法运算:</P>
<P>崩溃行偏移 = 崩溃地址(Crash Address) - 基地址(ImageBase Address) - 0x1000
</P>
<P>为什么要这样做呢?细心的朋友可能会留意到 Rva+Base 这栏了,我们得到的崩溃地址都是由 偏移地址(Rva)+
基地址(Base) 得来的,所以在计算行号的时候要把基地址减去,一般情况下,基地址的值是 0x00400000 。另外,由于一般的 PE
文件的代码段都是从 0x1000 偏移开始的,所以也必须减去 0x1000 。</P>
<P>好了,明白了这点,我们就可以来进行小学减法计算了:</P>
<P>崩溃行偏移 = 0x0040104a - 0x00400000 - 0x1000 = 0x4a </P>
<P>如果浏览 MAP 文件的代码行信息,会看到不超过计算结果,但却最接近的数是 CrashDemo.cpp 文件中的:</P>
<P>16 0001:00000046 </P>
<P>也就是在源代码中的第 16 行,让我们来看看源代码:</P>
<P>16 i /= j; </P>
<P>哈!!!果然就是第 16 行啊!</P>
<P>兴奋吗?我也一样! :)</P>
<P>方法已经介绍完了,从今以后,我们就可以精确地定位到源代码中的崩溃行,而且只要编译器可以生成 MAP 文件(包括
VC、MASM、VB、BCB、Delphi……),本方法都是适用的。我们时常抱怨 M$ 的产品如何如何差,但其实 M$
还是有意无意间提供了很多有价值的信息给我们的,只是我们往往不懂得怎么利用而已……相信这样一来,你就可以更为从容地面对“非法操作”提示了。你甚至可以要求用户提供崩溃的地址,然后就可以坐在家中舒舒服服地找到出错的那行,并进行修正。</P>
<P> </P><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center bgColor=#006699 border=0 cellPadding=0 cellSpacing=0
width=770>
<TBODY>
<TR bgColor=#006699>
<TD align=middle bgColor=#006699 id=white><FONT
color=#ffffff>对该文的评论</FONT></TD>
<TD align=middle>
<SCRIPT src="CSDN_文档中心_如何通过崩溃地址找到出错的代码行(ZT).files/readnum.htm"></SCRIPT>
</TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_如何通过崩溃地址找到出错的代码行(ZT).files/ico_pencil.gif"
width=16> </SPAN> playboy132 <I>(2004-5-8
13:38:18)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>To NopnoP:
我先报道:denglei132@163.com 多谢。 省得去追踪汇编代码。 <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_如何通过崩溃地址找到出错的代码行(ZT).files/ico_pencil.gif"
width=16> </SPAN> NopnoP <I>(2004-5-8
10:10:23)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>我有处理MAP文件的工具,只要简单的输入崩溃的地址就可以了.
需要的话可以给我发邮件zyb@myhexin.com <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_如何通过崩溃地址找到出错的代码行(ZT).files/ico_pencil.gif"
width=16> </SPAN> fzd999 <I>(2004-4-30
16:01:33)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>不过我其实也是转别人的贴,呵呵
<BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_如何通过崩溃地址找到出错的代码行(ZT).files/ico_pencil.gif"
width=16> </SPAN> fzd999 <I>(2004-4-30
15:48:39)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>晕~转我发的贴也不说一声 :(
<BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_如何通过崩溃地址找到出错的代码行(ZT).files/ico_pencil.gif"
width=16> </SPAN> Iamfish <I>(2004-4-30
13:35:13)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>DELPHI中如何生成MAP文件?
<BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_如何通过崩溃地址找到出错的代码行(ZT).files/ico_pencil.gif"
width=16> </SPAN> zhengyun_ustc <I>(2004-4-29
18:29:21)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3
width=532><BR>http://www.csdn.net/develop/Read_Article.asp?Id=14573
寻找崩溃的真相 http://www.csdn.net/develop/Read_Article.asp?Id=14559
对const声明变量的奇异行为的探讨 <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_如何通过崩溃地址找到出错的代码行(ZT).files/ico_pencil.gif"
width=16> </SPAN> PiggyXP <I>(2004-4-29
14:35:03)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>不错不错,好方法,不过不大懂汇编,收藏先
<BR></TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TH bgColor=#006699 id=white><FONT
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
<TBODY>
<TR>
<TD>你没有登陆,无法发表评论。 请先<A
href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=27335">登陆</A>
<A
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
<TBODY>
<TR align=middle>
<TD height=10 vAlign=bottom><A
href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A
href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A
href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A
href="http://www.csdn.net/english">English</A> </TD>
<TD align=middle rowSpan=3><A
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG
border=0 height=48 src="CSDN_文档中心_如何通过崩溃地址找到出错的代码行(ZT).files/biaoshi.gif"
width=40></A></TD></TR>
<TR align=middle>
<TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
<TR align=middle>
<TD vAlign=top><FONT face=Verdana>Copyright © CSDN.net, Inc. All rights
reserved</FONT></TD></TR>
<TR>
<TD height=15></TD>
<TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -