Exception的处理过程(Windbg调试器加载,AeDebug的JIT调试)

Exception的处理过程(Windbg调试器加载,AeDebug的JIT调试)1.如果有调试器加载,系统会通知调试器(firstchance)2.如果没有调试期加载,或者调试器没有处理exception,系统尝试寻找异常处理程序(catch…)3.如果没有找到异常处理程序,UnhandledExceptionFilter会尝试第二次通知调试器(secondchance

大家好,欢迎来到IT知识分享网。

 Exception的处理过程(Windbg调试器加载,AeDebug的JIT调试)

1.如果有调试器加载,系统会通知调试器(first chance)

2.如果没有调试期加载,或者调试器没有处理exception,系统尝试寻找异常处理程序(catch…)

3.如果没有找到异常处理程序,UnhandledExceptionFilter会尝试第二次通知调试器(second chance)

4.如果调试器不存在,且调用SetUnhandledExceptionFilter注册过callback,系统会调用该callback

5.如果没有注册callback,注册表中AeDebug指定的JIT会被调用。

 

static void Main(string[] args)

    {

      Console.WriteLine(“PRESS Enter to continue…”);

      Console.ReadLine();

 

      AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

      try

      {

        throw new Exception(“Fault”);

      }

      catch (Exception e)

      {

        Console.WriteLine(“Catch exception:”+e.Message);

        throw e;

      }

    }

 

    static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)

    {

      Exception e = (Exception)args.ExceptionObject;

      Console.WriteLine(“UnhandledException caught : ” + e.Message);

      //Environment.Exit(-1);

    }

 注册表中AeDebug的配置:

Exception的处理过程(Windbg调试器加载,AeDebug的JIT调试)

Scenario 1:没有调试器加载:

见到了熟悉的错误对话框,选择Debug,会调用AeDebug中设置的调试器进行Postmortem debugging

 Exception的处理过程(Windbg调试器加载,AeDebug的JIT调试) 

Microsoft (R) Windows Debugger Version 6.12.0002.633 X86

Copyright (c) Microsoft Corporation. All rights reserved.

 

*** wait with pending attach

Symbol search path is: C:\Symbols;SRV*C:\Symbols*http://msdl.microsoft.com/download/symbols

Executable search path is:

ModLoad: 01310000 0131e000   C:\Users\piy\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe

ModLoad: 04c00000 059c3000   C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\0065372201bcf95a8b7c7fc602b777e2\mscorlib.ni.dll

eax=00000000 ebx=003be8d0 ecx=00000005 edx=00000000 esi=00000002 edi=00000000

eip=77c200ed esp=003be880 ebp=003be91c iopl=0         nv up ei pl nz ac po nc

cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000212

ntdll!NtWaitForMultipleObjects+0x15:

77c200ed 83c404          add     esp,4

0:000> kn

 # ChildEBP RetAddr 

00 003be880 75f50962 ntdll!NtWaitForMultipleObjects+0x15

01 003be91c 7659162d KERNELBASE!WaitForMultipleObjectsEx+0x100

02 003be964 76591921 KERNEL32!WaitForMultipleObjectsExImplementation+0xe0

03 003be980 765b9b0d KERNEL32!WaitForMultipleObjects+0x18

04 003be9ec 765b9baa KERNEL32!WerpReportFaultInternal+0x186

05 003bea00 765b98d8 KERNEL32!WerpReportFault+0x70

06 003bea10 765b9855 KERNEL32!BasepReportFault+0x20

07 003bea9c 77c70df7 KERNEL32!UnhandledExceptionFilter+0x1af

08 003beaa4 77c70cd4 ntdll!__RtlUserThreadStart+0x62

09 003beab8 77c70b71 ntdll!_EH4_CallFilterFunc+0x12

0a 003beae0 77c46ac9 ntdll!_except_handler4+0x8e

0b 003beb04 77c46a9b ntdll!ExecuteHandler2+0x26

0c 003bebb4 77c1010f ntdll!ExecuteHandler+0x24

0d 003bebb4 75f4b727 ntdll!KiUserExceptionDispatcher+0xf

0e 003bef54 78b83970 KERNELBASE!RaiseException+0x58

0f 003befe4 78b83ba9 clr!RaiseTheExceptionInternalOnly+0x276

10 003bf0a4 00230168 clr!IL_Throw+0x14c

WARNING: Frame IP not in any known module. Following frames may be wrong.

11 003bf194 78a721bb 0x230168

12 003bf1a4 78a94be2 clr!CallDescrWorker+0x33

13 003bf220 78a94d84 clr!CallDescrWorkerWithHandler+0x8e

14 003bf358 78a94db9 clr!MethodDesc::CallDescr+0x194

15 003bf374 78a94dd9 clr!MethodDesc::CallTargetWorker+0x21

16 003bf38c 78b97df5 clr!MethodDescCallSite::Call_RetArgSlot+0x1c

17 003bf4f0 78b97f00 clr!ClassLoader::RunMain+0x24c

18 003bf758 78b97d17 clr!Assembly::ExecuteMainMethod+0xc1

19 003bfc3c 78b98109 clr!SystemDomain::ExecuteMainMethod+0x4ec

1a 003bfc90 78b9800a clr!ExecuteEXE+0x58

1b 003bfcdc 78bd6870 clr!_CorExeMainInternal+0x19f

1c 003bfd14 73bc55ab clr!_CorExeMain+0x4e

1d 003bfd20 73c37f16 mscoreei!_CorExeMain+0x38

1e 003bfd30 73c34de3 MSCOREE!ShellShim__CorExeMain+0x99

1f 003bfd38 76593677 MSCOREE!_CorExeMain_Exported+0x8

20 003bfd44 77c39f02 KERNEL32!BaseThreadInitThunk+0xe

21 003bfd84 77c39ed5 ntdll!__RtlUserThreadStart+0x70

22 003bfd9c 00000000 ntdll!_RtlUserThreadStart+0x1b

Scenario 2:调试器加载的时候:

配置Windbg,Enable CLR Exception Event并且not handled, Exception发生时会断到Windbg并且是不处理,交回程序处理

Exception的处理过程(Windbg调试器加载,AeDebug的JIT调试)

0:004> g

(1ec4.229c): CLR exception – code e0434352 (first chance)

First chance exceptions are reported before any exception handling.

This exception may be expected and handled.

eax=0014eb64 ebx=00000005 ecx=00000005 edx=00000000 esi=0014ec10 edi=00381200

eip=75f4b727 esp=0014eb64 ebp=0014ebb4 iopl=0         nv up ei pl nz ac po nc

cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000212

KERNELBASE!RaiseException+0x58:

75f4b727 c9              leave

 Exception的处理过程(Windbg调试器加载,AeDebug的JIT调试)

调试器首先收到exception的通知,g命令继续

 

0:000> g

(1f24.161c): CLR exception – code e0434352 (first chance)

First chance exceptions are reported before any exception handling.

This exception may be expected and handled.

eax=0019ee84 ebx=00000005 ecx=00000005 edx=00000000 esi=0019ef30 edi=00390ff0

eip=75f4b727 esp=0019ee84 ebp=0019eed4 iopl=0         nv up ei pl nz ac pe nc

cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000216

KERNELBASE!RaiseException+0x58:

75f4b727 c9              leave

 Exception的处理过程(Windbg调试器加载,AeDebug的JIT调试)

此时程序才catch到遗产并处理,打印之后继续抛出exception(first change),还是调试器先捕获到,g命令继续

 

0:000> g

(1f24.161c): CLR exception – code e0434352 (!!! second chance !!!)

eax=0019ee84 ebx=00000005 ecx=00000005 edx=00000000 esi=0019ef30 edi=00390ff0

eip=75f4b727 esp=0019ee84 ebp=0019eed4 iopl=0         nv up ei pl nz ac pe nc

cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000216

KERNELBASE!RaiseException+0x58:

75f4b727 c9              leave

 Exception的处理过程(Windbg调试器加载,AeDebug的JIT调试)

 

由于此异常没有找到异常处理程序,会被触发AppDomain的UnhandledException事件,这是最外层的异常处理,也是程序可以进行处理的最后机会。

因为有调试器存在,就不会进行AeDebug的JIT处理了,而是交给调试器,就是second change exception

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/33891.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信