分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

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

发布时间:2023-09-06 02:04责任编辑:沈小雨关键词:暂无标签

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

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

1、执行.loadby sos clr

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

Exception object: 0000000002557cb8Exception type: ??System.ArgumentExceptionMessage: ?????????Obj cannot be nullInnerException: ??<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[])+0x1dbStackTraceString: <none>HResult: 80070057

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

Name: ???????System.ArgumentExceptionMethodTable: 000007feef11ba28EEClass: ????000007feeeb179f8Size: ???????168(0xa8) bytesFile: ???????C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dllFields: ?????????????MT ???Field ??Offset ????????????????Type VT ????Attr ???????????Value Name000007feef108548 ?4000262 ???????8 ???????System.String ?0 instance 0000000002559bf8 _className000007feef128d58 ?4000263 ??????10 ...ection.MethodBase ?0 instance 0000000000000000 _exceptionMethod000007feef108548 ?4000264 ??????18 ???????System.String ?0 instance 0000000000000000 _exceptionMethodString000007feef108548 ?4000265 ??????20 ???????System.String ?0 instance 0000000002557d60 _message000007feef11f9e0 ?4000266 ??????28 ...tions.IDictionary ?0 instance 0000000000000000 _data000007feef108778 ?4000267 ??????30 ????System.Exception ?0 instance 0000000000000000 _innerException000007feef108548 ?4000268 ??????38 ???????System.String ?0 instance 0000000000000000 _helpURL000007feef108b28 ?4000269 ??????40 ???????System.Object ?0 instance 0000000002557e20 _stackTrace000007feef108b28 ?400026a ??????48 ???????System.Object ?0 instance 0000000002557e98 _watsonBuckets000007feef108548 ?400026b ??????50 ???????System.String ?0 instance 0000000000000000 _stackTraceString000007feef108548 ?400026c ??????58 ???????System.String ?0 instance 0000000000000000 _remoteStackTraceString000007feef10af70 ?400026d ??????88 ????????System.Int32 ?1 instance ???????????????0 _remoteStackIndex000007feef108b28 ?400026e ??????60 ???????System.Object ?0 instance 0000000000000000 _dynamicMethods000007feef10af70 ?400026f ??????8c ????????System.Int32 ?1 instance ?????-2147024809 _HResult000007feef108548 ?4000270 ??????68 ???????System.String ?0 instance 0000000000000000 _source000007feef1298a0 ?4000271 ??????78 ???????System.IntPtr ?1 instance ???????????????0 _xptrs000007feef10af70 ?4000272 ??????90 ????????System.Int32 ?1 instance ??????-532462766 _xcode000007feef0d44d0 ?4000273 ??????80 ??????System.UIntPtr ?1 instance ???????????????0 _ipForWatsonBuckets000007feef0fa808 ?4000274 ??????70 ...ializationManager ?0 instance 0000000002557da0 _safeSerializationManager000007feef108b28 ?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: ?????2UnstartedThread: ?0BackgroundThread: 1PendingThread: ???0DeadThread: ??????0Hosted 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 Site00 000007fe`f0171f09 : 00000000`00000001 00000000`0025e5e8 00000000`02557cb8 00000000`0025e6b8 : KERNELBASE!RaiseException+0x3901 000007fe`f0171d10 : 00000000`02556138 ffffffff`fffffffe 00000000`00000000 00000000`00000000 : clr!RaiseTheExceptionInternalOnly+0x2f002 000007fe`909c0cb5 : 00000000`70000195 000007fe`908b40c0 00000000`0025eb38 00000000`0025ea00 : clr!IL_Throw+0x11103 000007fe`909c065b : 00000000`02556cd8 00000000`00000000 00000000`02556b4c 00000000`00000000 : 0x000007fe`909c0cb504 000007fe`f0024073 : 00000000`02553470 000007fe`908b40c0 00000000`00000000 00000000`00000000 : 0x000007fe`909c065b05 000007fe`f0023f25 : 00000000`0025ed08 000007fe`f00b38f1 00000000`00000000 00000000`00000000 : clr!CallDescrWorkerInternal+0x8306 000007fe`f0024506 : 00000000`00000001 00000000`0025ec80 00000000`0025ec50 00000000`0025ebc8 : clr!CallDescrWorkerWithHandler+0x4e07 000007fe`f01158e1 : 00000000`0025eb50 00000000`00000000 00000000`00000000 00000000`00000001 : clr!MethodDescCallSite::CallTargetWorker+0xf808 000007fe`f0115a7a : 00000000`00000001 00000000`00000000 00000000`00000000 00000000`02553470 : clr!RunMain+0x1e709 000007fe`f0115971 : 00000000`00000000 00000000`02551508 00000000`00000000 00000000`00c09a10 : clr!Assembly::ExecuteMainMethod+0xb60a 000007fe`f0115be3 : 00000000`0025f6c8 00000000`01140000 00000000`00000000 00000000`00000000 : clr!SystemDomain::ExecuteMainMethod+0x5ea0b 000007fe`f0115bba : 00000000`01140000 00000000`0025f820 00000000`00000000 000007fe`f0e94998 : clr!ExecuteEXE+0x3f0c 000007fe`f012805c : ffffffff`ffffffff 00000000`00000000 00000000`00000000 00000000`00000000 : clr!_CorExeMainInternal+0xb20d 000007fe`f0e37fd5 : 00000000`00000000 000007fe`00000091 00000000`00000000 00000000`0025f788 : clr!CorExeMain+0x140e 000007fe`f0ed5b21 : 00000000`00000000 000007fe`f0128048 00000000`00000000 00000000`00000000 : mscoreei!CorExeMain+0xe00f 00000000`76e159cd : 000007fe`f0e30000 00000000`00000000 00000000`00000000 00000000`00000000 : MSCOREE!CorExeMain_Exported+0x5710 00000000`7704a561 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0xd11 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x1d

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

0:000> !pec0000005 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`000000000:000> !peException object: 00000000025dc6c0Exception type: System.ArgumentExceptionMessage: Obj cannot be nullInnerException: <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[])+0x225StackTraceString: <none>HResult: 800700570:000> kb # RetAddr ??????????: Args to Child ??????????????????????????????????????????????????????????: Call Site00 000007fe`ed6a436f : 00000000`002adce0 00000000`002adce0 00000000`0020e780 00000000`002adce0 : KERNELBASE!RaiseException+0x3901 000007fe`edc808a0 : 00000000`025dc6c0 00000000`00000000 00000000`00000000 00000000`00000001 : mscorwks!RaiseTheExceptionInternalOnly+0x2ff02 000007fe`8dfa0a9e : 00000000`70000195 000007fe`8de43528 00000000`00000001 00000000`00000000 : mscorwks!JIT_Throw+0x13003 000007fe`8dfa0344 : 00000000`025daef8 00000000`00000000 00000000`025dae34 00000000`00000000 : 0x000007fe`8dfa0a9e04 000007fe`ed838f32 : 00000000`025d94c8 00000000`00000000 000007fe`8de43c70 000007fe`ed70f7b9 : 0x000007fe`8dfa034405 000007fe`ed6c6683 : 00000000`00000002 00000000`00000016 000007fe`ed5f7690 00000000`00000000 : mscorwks!CallDescrWorker+0x8206 000007fe`edc18d31 : 00000000`0020ec88 00000000`00000000 00000000`0020ee90 00000000`00000008 : mscorwks!CallDescrWorkerWithHandler+0xd307 000007fe`ed783d6f : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`0020f0f0 : mscorwks!MethodDesc::CallDescr+0x2b108 000007fe`ed7a7e24 : 00000000`00280000 00000000`00000000 00000000`0000001e 00000000`00000000 : mscorwks!ClassLoader::RunMain+0x22b09 000007fe`edd061ad : 00000000`0020f6e0 00000000`00000000 00000000`003939e8 00000000`00000200 : mscorwks!Assembly::ExecuteMainMethod+0xbc0a 000007fe`ed7b52e7 : 00000000`00000000 00000000`00000000 00000000`00000000 000007fe`ed7cf566 : mscorwks!SystemDomain::ExecuteMainMethod+0x47d0b 000007fe`ed797d9c : ffffffff`fffffffe 00000000`0020d7f0 0000077c`00000000 00000000`00000000 : mscorwks!ExecuteEXE+0x470c 000007fe`f0e37fd5 : ffffffff`ffffffff 00000000`002adce0 00000000`00000000 00000000`0020f9a8 : mscorwks!_CorExeMain+0xac0d 000007fe`f0ed5b21 : 00000000`00000000 000007fe`ed797cf0 00000000`00000000 00000000`00000000 : mscoreei!CorExeMain+0xe00e 00000000`76e159cd : 000007fe`f0e30000 00000000`00000000 00000000`00000000 00000000`00000000 : MSCOREE!CorExeMain_Exported+0x570f 00000000`7704a561 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0xd10 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 ??????????Name000000000025E630 0000000002557cb8 System.ArgumentException000000000025E6A8 0000000002557cb8 System.ArgumentException000000000025E708 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes000000000025E710 0000000002557cb8 System.ArgumentException000000000025E720 0000000002556138 System.Byte[]000000000025E740 0000000002557cb8 System.ArgumentException000000000025E750 0000000002557cb8 System.ArgumentException000000000025E830 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes000000000025E838 0000000002557cb8 System.ArgumentException000000000025E8F0 0000000002553470 System.String[]000000000025E8F8 0000000002557d60 System.String ???Obj cannot be null000000000025E900 0000000002557cb8 System.ArgumentException000000000025E910 0000000002553470 System.String[]000000000025E930 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes000000000025E950 0000000002557bb8 System.Int32000000000025E958 00000000025535c0 System.String ???Greater {0}000000000025E960 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes000000000025E968 0000000002557bb8 System.Int32000000000025E970 00000000025535c0 System.String ???Greater {0}000000000025E978 0000000002557b88 Advanced.NET.Debugging.Chapter3.Comparer`1[[System.Int32, mscorlib]]000000000025E980 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes000000000025E988 0000000002557b88 Advanced.NET.Debugging.Chapter3.Comparer`1[[System.Int32, mscorlib]]000000000025E990 0000000002556cd8 Advanced.NET.Debugging.Chapter3.ObjTypes000000000025EA20 0000000002553470 System.String[]000000000025EB08 0000000002553470 System.String[]000000000025EBC8 0000000002553470 System.String[]000000000025ED98 0000000002553470 System.String[]000000000025EDC0 0000000002551508 System.AppDomain000000000025EEA8 0000000002551508 System.AppDomain000000000025F078 0000000002551508 System.AppDomain000000000025F370 0000000002551440 System.SharedStatics

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

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved