码迷,mamicode.com
首页 > Web开发 > 详细

.net 高级调试学习(3)异常查看

时间:2018-07-15 19:48:53      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:dfa   intern   dynamic   main   显示   dump   一个   ons   高级   

还是 .net 高级调试学习(2)中的源代码,

运行调试程序到输出异常,windbg自动中断后,

1、执行.loadby sos clr

2、执行!printexception ,(PS :缩写!pe)看到如下:

Exception object: 0000000002557cb8
Exception type:   System.ArgumentException
Message:          Obj cannot be null
InnerException:   <none>
StackTrace (generated):
    SP               IP               Function
    000000000025E8D0 000007FE909C0CB5 03ObjTypes!Advanced.NET.Debugging.Chapter3.ObjTypes.ThrowException(Advanced.NET.Debugging.Chapter3.ObjTypes)+0x95
    000000000025E930 000007FE909C065B 03ObjTypes!Advanced.NET.Debugging.Chapter3.ObjTypes.Main(System.String[])+0x1db

StackTraceString: <none>
HResult: 80070057

3, 执行!DumpObj  0000000002557cb8 查看具体异常内容

Name:        System.ArgumentException
MethodTable: 000007feef11ba28
EEClass:     000007feeeb179f8
Size:        168(0xa8) bytes
File:        C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007feef108548  4000262        8        System.String  0 instance 0000000002559bf8 _className
000007feef128d58  4000263       10 ...ection.MethodBase  0 instance 0000000000000000 _exceptionMethod
000007feef108548  4000264       18        System.String  0 instance 0000000000000000 _exceptionMethodString
000007feef108548  4000265       20        System.String  0 instance 0000000002557d60 _message
000007feef11f9e0  4000266       28 ...tions.IDictionary  0 instance 0000000000000000 _data
000007feef108778  4000267       30     System.Exception  0 instance 0000000000000000 _innerException
000007feef108548  4000268       38        System.String  0 instance 0000000000000000 _helpURL
000007feef108b28  4000269       40        System.Object  0 instance 0000000002557e20 _stackTrace
000007feef108b28  400026a       48        System.Object  0 instance 0000000002557e98 _watsonBuckets
000007feef108548  400026b       50        System.String  0 instance 0000000000000000 _stackTraceString
000007feef108548  400026c       58        System.String  0 instance 0000000000000000 _remoteStackTraceString
000007feef10af70  400026d       88         System.Int32  1 instance                0 _remoteStackIndex
000007feef108b28  400026e       60        System.Object  0 instance 0000000000000000 _dynamicMethods
000007feef10af70  400026f       8c         System.Int32  1 instance      -2147024809 _HResult
000007feef108548  4000270       68        System.String  0 instance 0000000000000000 _source
000007feef1298a0  4000271       78        System.IntPtr  1 instance                0 _xptrs
000007feef10af70  4000272       90         System.Int32  1 instance       -532462766 _xcode
000007feef0d44d0  4000273       80       System.UIntPtr  1 instance                0 _ipForWatsonBuckets
000007feef0fa808  4000274       70 ...ializationManager  0 instance 0000000002557da0 _safeSerializationManager
000007feef108b28  4000261       a8        System.Object  0   shared           static s_EDILock
                                 >> Domain:Value  00000000000c7840:NotInit  <<
000007feef108548  400038a       98        System.String  0 instance 0000000000000000 m_paramName

 

3、也可以使用 !threads 查看所有线程的异常,显示如下:

 

ThreadCount:      2
UnstartedThread:  0
BackgroundThread: 1
PendingThread:    0
DeadThread:       0
Hosted Runtime:   no
                                                                                                        Lock  
       ID OSID ThreadOBJ           State GC Mode     GC Alloc Context                  Domain           Count Apt Exception
   0    1 2064 000000000011a090    2a020 Preemptive  0000000002562C68:0000000002563FD0 00000000000c7840 0     MTA System.ArgumentException 0000000002557cb8
   2    2 1240 000000000011e0c0    2b220 Preemptive  0000000000000000:0000000000000000 00000000000c7840 0     MTA (Finalizer) 

 

书中使用的是kb 命令,查看托管和非托管的调用栈

 # RetAddr           : Args to Child                                                           : Call Site
00 000007fe`f0171f09 : 00000000`00000001 00000000`0025e5e8 00000000`02557cb8 00000000`0025e6b8 : KERNELBASE!RaiseException+0x39
01 000007fe`f0171d10 : 00000000`02556138 ffffffff`fffffffe 00000000`00000000 00000000`00000000 : clr!RaiseTheExceptionInternalOnly+0x2f0
02 000007fe`909c0cb5 : 00000000`70000195 000007fe`908b40c0 00000000`0025eb38 00000000`0025ea00 : clr!IL_Throw+0x111
03 000007fe`909c065b : 00000000`02556cd8 00000000`00000000 00000000`02556b4c 00000000`00000000 : 0x000007fe`909c0cb5
04 000007fe`f0024073 : 00000000`02553470 000007fe`908b40c0 00000000`00000000 00000000`00000000 : 0x000007fe`909c065b
05 000007fe`f0023f25 : 00000000`0025ed08 000007fe`f00b38f1 00000000`00000000 00000000`00000000 : clr!CallDescrWorkerInternal+0x83
06 000007fe`f0024506 : 00000000`00000001 00000000`0025ec80 00000000`0025ec50 00000000`0025ebc8 : clr!CallDescrWorkerWithHandler+0x4e
07 000007fe`f01158e1 : 00000000`0025eb50 00000000`00000000 00000000`00000000 00000000`00000001 : clr!MethodDescCallSite::CallTargetWorker+0xf8
08 000007fe`f0115a7a : 00000000`00000001 00000000`00000000 00000000`00000000 00000000`02553470 : clr!RunMain+0x1e7
09 000007fe`f0115971 : 00000000`00000000 00000000`02551508 00000000`00000000 00000000`00c09a10 : clr!Assembly::ExecuteMainMethod+0xb6
0a 000007fe`f0115be3 : 00000000`0025f6c8 00000000`01140000 00000000`00000000 00000000`00000000 : clr!SystemDomain::ExecuteMainMethod+0x5ea
0b 000007fe`f0115bba : 00000000`01140000 00000000`0025f820 00000000`00000000 000007fe`f0e94998 : clr!ExecuteEXE+0x3f
0c 000007fe`f012805c : ffffffff`ffffffff 00000000`00000000 00000000`00000000 00000000`00000000 : clr!_CorExeMainInternal+0xb2
0d 000007fe`f0e37fd5 : 00000000`00000000 000007fe`00000091 00000000`00000000 00000000`0025f788 : clr!CorExeMain+0x14
0e 000007fe`f0ed5b21 : 00000000`00000000 000007fe`f0128048 00000000`00000000 00000000`00000000 : mscoreei!CorExeMain+0xe0
0f 00000000`76e159cd : 000007fe`f0e30000 00000000`00000000 00000000`00000000 00000000`00000000 : MSCOREE!CorExeMain_Exported+0x57
10 00000000`7704a561 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0xd
11 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x1d

说红色行的Args to Child 的第一个参数就是异常的指针,但是这里明显不是,而是上一行的红色才是,不知是不是.net2和.net4的差异问题,于是我用.net2编译的程序来调试,输出如下:

0:000> !pe
c0000005 Exception in C:\Windows\Microsoft.NET\Framework64\v2.0.50727\sos.pe debugger extension.
      PC: 000007fe`e281f8e4  VA: 00000000`00000000  R/W: 0  Parameter: 00000000`00000000
0:000> !pe
Exception object: 00000000025dc6c0
Exception type: System.ArgumentException
Message: Obj cannot be null
InnerException: <none>
StackTrace (generated):
    SP               IP               Function
    000000000020E9D0 000007FE8DFA0A9F 03ObjTypes!Advanced.NET.Debugging.Chapter3.ObjTypes.ThrowException(Advanced.NET.Debugging.Chapter3.ObjTypes)+0x8f
    000000000020EA10 000007FE8DFA0345 03ObjTypes!Advanced.NET.Debugging.Chapter3.ObjTypes.Main(System.String[])+0x225

StackTraceString: <none>
HResult: 80070057
0:000> kb
 # RetAddr           : Args to Child                                                           : Call Site
00 000007fe`ed6a436f : 00000000`002adce0 00000000`002adce0 00000000`0020e780 00000000`002adce0 : KERNELBASE!RaiseException+0x39
01 000007fe`edc808a0 : 00000000`025dc6c0 00000000`00000000 00000000`00000000 00000000`00000001 : mscorwks!RaiseTheExceptionInternalOnly+0x2ff
02 000007fe`8dfa0a9e : 00000000`70000195 000007fe`8de43528 00000000`00000001 00000000`00000000 : mscorwks!JIT_Throw+0x130
03 000007fe`8dfa0344 : 00000000`025daef8 00000000`00000000 00000000`025dae34 00000000`00000000 : 0x000007fe`8dfa0a9e
04 000007fe`ed838f32 : 00000000`025d94c8 00000000`00000000 000007fe`8de43c70 000007fe`ed70f7b9 : 0x000007fe`8dfa0344
05 000007fe`ed6c6683 : 00000000`00000002 00000000`00000016 000007fe`ed5f7690 00000000`00000000 : mscorwks!CallDescrWorker+0x82
06 000007fe`edc18d31 : 00000000`0020ec88 00000000`00000000 00000000`0020ee90 00000000`00000008 : mscorwks!CallDescrWorkerWithHandler+0xd3
07 000007fe`ed783d6f : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`0020f0f0 : mscorwks!MethodDesc::CallDescr+0x2b1
08 000007fe`ed7a7e24 : 00000000`00280000 00000000`00000000 00000000`0000001e 00000000`00000000 : mscorwks!ClassLoader::RunMain+0x22b
09 000007fe`edd061ad : 00000000`0020f6e0 00000000`00000000 00000000`003939e8 00000000`00000200 : mscorwks!Assembly::ExecuteMainMethod+0xbc
0a 000007fe`ed7b52e7 : 00000000`00000000 00000000`00000000 00000000`00000000 000007fe`ed7cf566 : mscorwks!SystemDomain::ExecuteMainMethod+0x47d
0b 000007fe`ed797d9c : ffffffff`fffffffe 00000000`0020d7f0 0000077c`00000000 00000000`00000000 : mscorwks!ExecuteEXE+0x47
0c 000007fe`f0e37fd5 : ffffffff`ffffffff 00000000`002adce0 00000000`00000000 00000000`0020f9a8 : mscorwks!_CorExeMain+0xac
0d 000007fe`f0ed5b21 : 00000000`00000000 000007fe`ed797cf0 00000000`00000000 00000000`00000000 : mscoreei!CorExeMain+0xe0
0e 00000000`76e159cd : 000007fe`f0e30000 00000000`00000000 00000000`00000000 00000000`00000000 : MSCOREE!CorExeMain_Exported+0x57
0f 00000000`7704a561 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0xd
10 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x1d

发现这个是和书上说的是一致的,所以.net2 和net4程序还是有很大差异的。

 

也可以通过.!dumpstackobjects   (缩写!dso) 查看本线程调用栈所有对象实例

OS Thread Id: 0x2064 (0)
RSP/REG          Object           Name
000000000025E630 0000000002557cb8 System.ArgumentException
000000000025E6A8 0000000002557cb8 System.ArgumentException
000000000025E708 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes
000000000025E710 0000000002557cb8 System.ArgumentException
000000000025E720 0000000002556138 System.Byte[]
000000000025E740 0000000002557cb8 System.ArgumentException
000000000025E750 0000000002557cb8 System.ArgumentException
000000000025E830 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes
000000000025E838 0000000002557cb8 System.ArgumentException
000000000025E8F0 0000000002553470 System.String[]
000000000025E8F8 0000000002557d60 System.String    Obj cannot be null
000000000025E900 0000000002557cb8 System.ArgumentException
000000000025E910 0000000002553470 System.String[]
000000000025E930 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes
000000000025E950 0000000002557bb8 System.Int32
000000000025E958 00000000025535c0 System.String    Greater {0}
000000000025E960 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes
000000000025E968 0000000002557bb8 System.Int32
000000000025E970 00000000025535c0 System.String    Greater {0}
000000000025E978 0000000002557b88 Advanced.NET.Debugging.Chapter3.Comparer`1[[System.Int32, mscorlib]]
000000000025E980 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes
000000000025E988 0000000002557b88 Advanced.NET.Debugging.Chapter3.Comparer`1[[System.Int32, mscorlib]]
000000000025E990 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes
000000000025EA20 0000000002553470 System.String[]
000000000025EB08 0000000002553470 System.String[]
000000000025EBC8 0000000002553470 System.String[]
000000000025ED98 0000000002553470 System.String[]
000000000025EDC0 0000000002551508 System.AppDomain
000000000025EEA8 0000000002551508 System.AppDomain
000000000025F078 0000000002551508 System.AppDomain
000000000025F370 0000000002551440 System.SharedStatics

 

.net 高级调试学习(3)异常查看

标签:dfa   intern   dynamic   main   显示   dump   一个   ons   高级   

原文地址:https://www.cnblogs.com/karl-F/p/9314066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!