於ASP.NET網頁專案中,使用SOS.dll來進行除錯。
於ASP.NET網頁專案中,使用SOS.dll來進行除錯時,需要開啟unmanaged code debugging。開啟方式依順從「專案屬性」/「Web」/「偵錯工具」中勾選「機器碼」。
於VS2010 IDE中載入SOS.dll後,打開「即時運算視窗」(Immediate Window) 以顯示相關訊息,從「偵錯」/「視窗」中勾選。
專案偵錯時,設立中斷點後,在即時運算視窗中輸入相關命令即可。下面直接用一個範例來簡單說明,程式碼如下:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ta(5) As Integer
For i As Integer = 0 To ta.Length - 1
ta(i) = i + 7
Next
End Sub
於即時運算視窗輸入指令如下:
.load sos
擴充功能 C:\Windows\Microsoft.NET\Framework\v4.0.30319\sos.dll 已載入
!dso
PDB symbol for clr.dll not loaded
OS Thread Id: 0x1e5c (7772)
ESP/REG Object Name
04C4D008 01b4d0c4 ASP.webform2_aspx
04C4D148 01b4d0c4 ASP.webform2_aspx
04C4D14C 0190efa8 System.EventArgs
04C4D150 01b502c4 System.Int32[]
04C4D390 01b502c4 System.Int32[]
04C4D3A0 01b502c4 System.Int32[]
04C4D3A4 01b4d0c4 ASP.webform2_aspx
04C4D3A8 01b4d0c4 ASP.webform2_aspx
04C4D3D8 0190efa8 System.EventArgs
04C4D3DC 01b4d0c4 ASP.webform2_aspx
04C4D3E0 01b4e668 System.ComponentModel.EventHandlerList
04C4D3EC 0190efa8 System.EventArgs
...
!do 01b502c4
Name: System.Int32[]
MethodTable: 611628b8
EEClass: 60e99d38
Size: 36(0x24) bytes
Array: Rank 1, Number of elements 6, Type Int32
Element Type:System.Int32
Fields:
None
!da 01b502c4
Name: System.Int32[]
MethodTable: 611628b8
EEClass: 60e99d38
Size: 36(0x24) bytes
Array: Rank 1, Number of elements 6, Type Int32
Element Methodtable: 611628f8
[0] 01b502cc
[1] 01b502d0
[2] 01b502d4
[3] 01b502d8
[4] 01b502dc
[5] 01b502e0
!DumpVC 611628f8 01b502cc
擴充功能 C:\Windows\Microsoft.NET\Framework\v4.0.30319\sos.dll 已載入
!dso
PDB symbol for clr.dll not loaded
OS Thread Id: 0x1e5c (7772)
ESP/REG Object Name
04C4D008 01b4d0c4 ASP.webform2_aspx
04C4D148 01b4d0c4 ASP.webform2_aspx
04C4D14C 0190efa8 System.EventArgs
04C4D150 01b502c4 System.Int32[]
04C4D390 01b502c4 System.Int32[]
04C4D3A0 01b502c4 System.Int32[]
04C4D3A4 01b4d0c4 ASP.webform2_aspx
04C4D3A8 01b4d0c4 ASP.webform2_aspx
04C4D3D8 0190efa8 System.EventArgs
04C4D3DC 01b4d0c4 ASP.webform2_aspx
04C4D3E0 01b4e668 System.ComponentModel.EventHandlerList
04C4D3EC 0190efa8 System.EventArgs
...
!do 01b502c4
Name: System.Int32[]
MethodTable: 611628b8
EEClass: 60e99d38
Size: 36(0x24) bytes
Array: Rank 1, Number of elements 6, Type Int32
Element Type:System.Int32
Fields:
None
!da 01b502c4
Name: System.Int32[]
MethodTable: 611628b8
EEClass: 60e99d38
Size: 36(0x24) bytes
Array: Rank 1, Number of elements 6, Type Int32
Element Methodtable: 611628f8
[0] 01b502cc
[1] 01b502d0
[2] 01b502d4
[3] 01b502d8
[4] 01b502dc
[5] 01b502e0
!DumpVC 611628f8 01b502cc
Name: System.Int32
MethodTable: 611628f8
EEClass: 60e99ce4
Size: 12(0xc) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
Fields:
MT Field Offset Type VT Attr Value Name
611628f8 40004a5 0 System.Int32 1 instance 7 m_value
// 亦可直接使用 !da 01b502c4 -details 來輸出Array的細節。
!name2ee Tai_Power.dll Tai_Power.WebForm2
Module: 047c2eac
Assembly: Tai_Power.DLL
Token: a5bae830020000f7
MethodTable: 047ca280
EEClass: 04b9b6bc
Name: Tai_Power.WebForm2
Module: 047c2eac
Assembly: Tai_Power.DLL
Token: a5bae830020000f7
MethodTable: 047ca280
EEClass: 04b9b6bc
Name: Tai_Power.WebForm2
更多細節參考底下連結。
Ref.