加载clr调试插件
.load psscor2
设置调试符号文件地址,一般指向网站的bin目录下,里面每个Dll会有一个 PDB文件
.sympath D:\website\pdhbj\Pdhb.SynAdmin\bin
或执行File>>Symbol File Path,填入:
srv* D:\website\pdhbj\Pdhb.SynAdmin\bin*http://msdl.microsoft.com/download/symbols
在CLR的Exception抛出来的时候,能断点停下来,方便调试
sxe clr
!name2ee Beyondbit_PDHB_SynAdmin!Beyondbit.SynAdmin.SynAdminProject.OutNewProjectBook.btnManage_Click
!bpmd -md 00000642803d2ae8
g
执行
!pe 得到如下结果:
Exception object: 00000001bf44b470
Exception type: System.NullReferenceException
Message: hello
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 80004003
这样我们就知道Exception的Message文本了
------------------------------------------------------------------------
!dae
出现以下文本:
Number of exceptions of this type: 2
Exception MethodTable: 000007feedb63078
Exception object: 00000001bfcb2ca8
Exception type: System.NullReferenceException
Message: hello
InnerException: <none>
StackTrace (generated):
SP IP Function
000000000161E1C0 000007FF001C064C WebApplication1._Default.Go(Int32, System.String)
000000000161E200 000007FF001C05A7 WebApplication1._Default.Page_Load(System.Object, System.EventArgs)
000000000161E230 000007FEE3C13ECA System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr, System.Object, System.Object, System.EventArgs)
000000000161E260 000007FEE9219DCB System.Web.Util.CalliEventHandlerDelegateProxy.Callback(System.Object, System.EventArgs)
000000000161E290 000007FEE9210585 System.Web.UI.Control.OnLoad(System.EventArgs)
000000000161E2D0 000007FEE92105E3 System.Web.UI.Control.LoadRecursive()
000000000161E320 000007FEE920CB6D System.Web.UI.Page.ProcessRequestMain(Boolean, Boolean)
StackTraceString: <none>
HResult: 80004003
------------------------------------------------------------------------------------------------------------------------------
执行DumpStack可以看到异常抛出的地方在 WebApplication1!WebApplication1._Default.Go(Int32, System.String)+0x7b也就是Default页面的Go方法
0:029> !DumpStack
OS Thread Id: 0xa3c (29)
Child-SP RetAddr Call Site
000000000505df80 000007feef989413 KERNELBASE!RaiseException+0x3d
000000000505e050 000007feefec3310 mscorwks!StrongNameFreeBuffer+0x53b7
000000000505e140 000007ff001a064b mscorwks!CorLaunchApplication+0xee90
000000000505e2f0 000007ff001a05a6 WebApplication1!WebApplication1._Default.Go(Int32, System.String)+0x7b
000000000505e330 000007fede0f3ec9 WebApplication1!WebApplication1._Default.Page_Load(System.Object, System.EventArgs)+0x46
000000000505e360 000007fee8289dca System_Web_RegularExpressions_ni!System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr, System.Object, System.Object, System.EventArgs)+0x19
000000000505e390 000007fee8280584 System_Web_ni!System.Web.Util.CalliEventHandlerDelegateProxy.Callback(System.Object, System.EventArgs)+0x2a
000000000505e3c0 000007fee82805e2 System_Web_ni!System.Web.UI.Control.OnLoad(System.EventArgs)+0x84
000000000505e400 000007fee827cb6c System_Web_ni!System.Web.UI.Control.LoadRecursive()+0x42
000000000505e450 000007fee827c070 System_Web_ni!System.Web.UI.Page.ProcessRequestMain(Boolean, Boolean)+0x97c
000000000505e520 000007fee827bf9b System_Web_ni!System.Web.UI.Page.ProcessRequest(Boolean, Boolean)+0xa0
000000000505e580 000007fee827bf30 System_Web_ni!System.Web.UI.Page.ProcessRequest()+0x5b
000000000505e5e0 000007ff001a0269 System_Web_ni!System.Web.UI.Page.ProcessRequest(System.Web.HttpContext)+0xf0
000000000505e640 000007fee82833d7 App_Web_nxt80xwq!ASP.default_aspx.ProcessRequest(System.Web.HttpContext)+0x9
000000000505e670 000007fee824679b System_Web_ni!System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+0x257
000000000505e720 000007fee8254d95 System_Web_ni!System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef)+0xab
000000000505e7c0 000007fee8245853 System_Web_ni!System.Web.HttpApplication+ApplicationStepManager.ResumeSteps(System.Exception)+0x1a5
000000000505e870 000007fee8249b74 System_Web_ni!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext, System.AsyncCallback, System.Object)+0xd3
000000000505e8d0 000007fee824975c System_Web_ni!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest)+0x1c4
000000000505e960 000007fee824838c System_Web_ni!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest)+0x7c
000000000505e9a0 000007feefa80282 System_Web_ni!System.Web.Hosting.ISAPIRuntime.ProcessRequest(IntPtr, Int32)+0x18c
000000000505ead0 000007feef964363 mscorwks!IEE+0xda36
000000000505eb30 000007feef972d6e mscorwks!CreateAssemblyNameObject+0x60ab
000000000505ebd0 000007feeff651a6 mscorwks!CompareAssemblyIdentity+0x51f2
000000000505ec70 000007feef9a44c0 mscorwks!CorExeMain2+0x1516
000000000505eec0 000007feef9534ca mscorwks!StrongNameFreeBuffer+0x20464
000000000505ef30 000007feefa803fe mscorwks!StrongNameTokenFromPublicKey+0x8bf6a
000000000505f220 000007fee0548433 mscorwks!IEE+0xdbb2
000000000505f2d0 000007fee05487f3 webengine!InitializeManagedCode+0x9d3
000000000505f780 000007fee058adc4 webengine!IsManagedDebuggerConnectedIndirect+0x73
000000000505f7c0 000007feef8dbb37 webengine!SetMinRequestsExecutingToDetectDeadlock+0x284
000000000505f7f0 000007feef8ee92a mscorwks!StrongNameTokenFromPublicKey+0x145d7
000000000505f890 000007feef8ab1fc mscorwks!StrongNameTokenFromPublicKey+0x273ca
000000000505f930 0000000076c4652d mscorwks!GetMetaDataInternalInterfaceFromPublic+0x93c4
000000000505fd80 0000000076d7c521 kernel32!BaseThreadInitThunk+0xd
000000000505fdb0 0000000000000000 ntdll!RtlUserThreadStart+0x21
------------------------------------------------------------------------------------------------------------------------------
!DumpStackObjects
OS Thread Id: 0xa3c (29)
RSP/REG Object Name
000000000505e0f0 00000001bf42a018 System.Web.Caching.CacheEntry
000000000505e128 00000001bf44b470 System.NullReferenceException
000000000505e130 000000013f2f1808 System.EventArgs
000000000505e140 00000001bf44b470 System.NullReferenceException
000000000505e160 00000001bf44b470 System.NullReferenceException
000000000505e218 000000013f2f1808 System.EventArgs
000000000505e220 00000001bf44aa90 System.ComponentModel.EventHandlerList
000000000505e230 00000001bf44b470 System.NullReferenceException
000000000505e238 000000013f2f1808 System.EventArgs
000000000505e240 00000001bf2e0998 System.String
000000000505e2d0 00000001bf448dc0 ASP.default_aspx
000000000505e2d8 00000001bf448dc0 ASP.default_aspx
------------------------------------------------------------------------------------------------------------------------------
!do 00000001bf2e0998
Name: System.String
MethodTable: 000007feee187ca0
EEClass: 000007feedd8e550
Size: 36(0x24) bytes
GC Generation: 0
(C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)
String: hello
Fields:
MT Field Offset Type VT Attr Value Name
000007feee18ef10 4000096 8 System.Int32 1 instance 6 m_arrayLength
000007feee18ef10 4000097 c System.Int32 1 instance 5 m_stringLength
000007feee1896e8 4000098 10 System.Char 1 instance 68 m_firstChar
000007feee187ca0 4000099 20 System.String 0 shared static Empty
>> Domain:Value 0000000001501640:000000017f290370 0000000003bca6e0:000000017f290370 <<
000007feee189598 400009a 28 System.Char[] 0 shared static WhitespaceChars
>> Domain:Value 0000000001501640:000000017f290e58 0000000003bca6e0:00000000ff2900b0 <<
------------------------------------------------------------------------------------------------------------------------------
...
Total 9 exceptions
可以用!PrintException 00000001bfcb2ca8看看
########################################################################################
# x Beyondbit.PDHB_SynAdmin!*
.load psscor2
.sympath D:\website\pdhbj\Pdhb.SynAdmin\bin
!name2ee Beyondbit_PDHB_SynAdmin!Beyondbit.SynAdmin.SynAdminProject.OutNewProjectBook.btnManage_Click
!bpmd -md 00000642803d2ae8
x Beyondbit.PDHB_SynAdmin!*
!name2ee Beyondbit_PDHB_SynAdmin!Beyondbit.SynAdmin.SynAdminProject.OutNewProjectBook.InitProject
!bpmd -md 0000064280467738
!name2ee Beyondbit_PDHB_SynAdmin!Beyondbit.SynAdmin.SynAdminProject.OutNewProjectBook.SavePdhbadverInfo
Module: 00000642801e30f0 (Beyondbit.PDHB_SynAdmin.DLL)
Token: 0x0000000006001236
MethodDesc: 0000064280467748
Name: Beyondbit.SynAdmin.SynAdminProject.OutNewProjectBook.SavePdhbadverInfo(Int32, Int32, Int32)
JITTED Code Address: 00000642804c66b0
!bpmd -md 0000064280467748
!name2ee Beyondbit_PDHB_SynAdmin!Beyondbit.SynAdmin.SynAdminProject.OutNewProjectBook.SaveFiles
!name2ee Beyondbit_SynAdmin_DataAccess!Beyondbit.SynAdmin.DataAccess.SaveProjectSpecialInfo
sxe ld:Beyondbit_SynAdmin_DataAccess