·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> Debug Diagnostics Tool创建.Net异常转储并用Windbg分析异常

Debug Diagnostics Tool创建.Net异常转储并用Windbg分析异常

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

Debug Diagnostics Tool创建.Net异常转储并用Windbg分析异常

当我们要在IIS PRD环境下分析异常,并且对问题毫无头绪,又没有权限直接上打Log的代码。这个时候就是Debug Diagnostics Tool & Windbg大显神威的时候了。

Debug Diagnostics Tool

安装方法各位大侠请自行百度,重点说一下抓转储文件。

一开始是选择抓取的程序,我当然要抓IIS的应用程序池喽。。。

设定要抓取的文件个数,点击Exceptions可以设定在发生什么异常时候抓取。

我当然是要抓高大上的.Net异常喽。。。

接下来是设置保存的位置。

为了演示随便搞了一个会抛出异常的页面:

看一下生成的转储文件长个毛样子哇:

Windbg

下面该windbg出手了,这个网上教程比较多,直接说重点了:

~#:查看问题线程,~线程id s:切换线程,!clrstack -l:查看当前堆栈并打印局部变量。

0:023> ~#. 23 Id: 790.1280 Suspend: 1 Teb: 000007ff`ffec6000 Unfrozen Start: clr!Thread::intermediateThreadProc (000007fe`ef57dafc) Priority: 0 Priority class: 32 Affinity: f0:023> ~23 sKERNELBASE!RaiseException+0x39:000007fe`fdfaaaad 4881c4c8000000 add rsp,0C8h0:023> !clrstack -lOS Thread Id: 0x1280 (23) Child SP ip Call Site000000000d3ad610 000007fefdfaaaad [FaultingExceptionFrame: 000000000d3ad610] 000000000d3adb60 000007fe8fe415cc *** WARNING: Unable to verify checksum for App_Web_ix1d1jtk.dll_Default.Page_Load(System.Object, System.EventArgs) [c:\inetpub\wwwroot\Default.aspx.cs @ 17] LOCALS: 0x000000000d3adb80 = 0x00000000fff4d4e8 0x000000000d3adb88 = 0x0000000000000000 0x000000000d3adb8c = 0x0000000000000001

呵呵,0x00000000fff4d4e8这个地址就是我们代码里面随便new的对象:sssssss奥,来DO一下看看这个对象吧:

0:023> !do 0x00000000fff4d4e8Name: TestStaticMethodTable: 000007fe8fe2c3d8EEClass: 000007fe8fe18bc8Size: 24(0x18) bytesFile: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary asp.net Files\root\e22c2559\92c7e946\App_Web_ix1d1jtk.dllFields: MT Field Offset Type VT Attr Value Name000007feee4f0e08 400000d 28 System.String 0 static 0000000400031900 abc

再来看一下他的字符串成员abc

0:023> !do 0000000400031900Name: System.StringMethodTable: 000007feee4f0e08EEClass: 000007feede14860Size: 48(0x30) bytesFile: C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dllString: 11111111111Fields: MT Field Offset Type VT Attr Value Name000007feee4f3980 40000ab 8 System.Int32 1 instance 11 m_stringLength000007feee4f20f0 40000ac c System.Char 1 instance 31 m_firstChar000007feee4f0e08 40000ad 18 System.String 0 shared static Empty