當咱們要在IIS PRD環境下分析異常,而且對問題毫無頭緒,又沒有權限直接上打Log的代碼。這個時候就是Debug Diagnostics Tool & Windbg大顯神威的時候了。線程
Debug Diagnostics Tool3d
安裝方法各位大俠請自行百度,重點說一下抓轉儲文件。對象
一開始是選擇抓取的程序,我固然要抓IIS的應用程序池嘍。。。blog
設定要抓取的文件個數,點擊Exceptions能夠設定在發生什麼異常時候抓取。教程
我固然是要抓高大上的.Net異常嘍。。。字符串
接下來是設置保存的位置。string
爲了演示隨便搞了一個會拋出異常的頁面:it
看一下生成的轉儲文件長個毛樣子哇:io
Windbgclass
下面該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: f
0:023> ~23 s
KERNELBASE!RaiseException+0x39:
000007fe`fdfaaaad 4881c4c8000000 add rsp,0C8h
0:023> !clrstack -l
OS Thread Id: 0x1280 (23)
Child SP IP Call Site
000000000d3ad610 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 0x00000000fff4d4e8
Name: TestStatic
MethodTable: 000007fe8fe2c3d8
EEClass: 000007fe8fe18bc8
Size: 24(0x18) bytes
File: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\e22c2559\92c7e946\App_Web_ix1d1jtk.dll
Fields:
MT Field Offset Type VT Attr Value Name
000007feee4f0e08 400000d 28 System.String 0 static 0000000400031900 abc
再來看一下他的字符串成員abc
0:023> !do 0000000400031900
Name: System.String
MethodTable: 000007feee4f0e08
EEClass: 000007feede14860
Size: 48(0x30) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
String: 11111111111
Fields:
MT Field Offset Type VT Attr Value Name
000007feee4f3980 40000ab 8 System.Int32 1 instance 11 m_stringLength
000007feee4f20f0 40000ac c System.Char 1 instance 31 m_firstChar
000007feee4f0e08 40000ad 18 System.String 0 shared static Empty