Exception Object에 대해 살펴보기

일반적으로 .NET Framework 기반의 Application에서 Exception이 발생하면, 이 역시 Exception Object의 형태로 Memory에 저장이 된다. 결국엔 kernel32!RaiseExceptione0434f4d 파라메터로 전송하게 되면, Debugger에서 CLR Exception으로 인식되는 데, 아래의 Call Stack CLR 2.0에서의 대표적인 모습이다. 그리고, mscorwks!RaiseTheExceptionInternalOnly 1번째 파라메터의 값은 어떤 Exception이 발생했는지, Exception Object에 대한 정보가 된다.

 

ChildEBP RetAddr  Args to Child             

0012ef08 79f97065 e0434f4d 00000001 00000001 kernel32!RaiseException+0x53

0012ef68 7a0945a4 0179a680 00000000 00000000 mscorwks!RaiseTheExceptionInternalOnly+0x226

*** WARNING: Unable to verify checksum for mscorlib.ni.dll

0012f02c 7952257c 0012f000 00000000 0179a610 mscorwks!JIT_Throw+0xd0

 

상위의 경우는 아래와 같은 Exception이 발생한 것이다.

 

0:000> .loadby sos mscorwks

0:000> !do 0179a680

Name: System.UnauthorizedAccessException

MethodTable: 7915fc6c

EEClass: 791eb60c

Size: 72(0x48) bytes

 (C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)

Fields:

      MT    Field   Offset                 Type VT     Attr    Value Name

790fa3e0  40000b5        4        System.String  0 instance 00000000 _className

79109208  40000b6        8 ...ection.MethodBase  0 instance 00000000 _exceptionMethod

790fa3e0  40000b7        c        System.String  0 instance 00000000 _exceptionMethodString

790fa3e0  40000b8       10        System.String  0 instance 017a23f4 _message

79113dfc  40000b9       14 ...tions.IDictionary  0 instance 00000000 _data

790fa9e8  40000ba       18     System.Exception  0 instance 00000000 _innerException

790fa3e0  40000bb       1c        System.String  0 instance 00000000 _helpURL

790f9c18  40000bc       20        System.Object  0 instance 00000000 _stackTrace

790fa3e0  40000bd       24        System.String  0 instance 00000000 _stackTraceString

790fa3e0  40000be       28        System.String  0 instance 00000000 _remoteStackTraceString

790fed1c  40000bf       34         System.Int32  1 instance        0 _remoteStackIndex

790f9c18  40000c0       2c        System.Object  0 instance 00000000 _dynamicMethods

790fed1c  40000c1       38         System.Int32  1 instance -2147024891 _HResult

790fa3e0  40000c2       30        System.String  0 instance 00000000 _source

790fe160  40000c3       3c        System.IntPtr  1 instance        0 _xptrs

790fed1c  40000c4       40         System.Int32  1 instance -532459699 _xcode

 

해당 Exception Object는 흥미로운 정보를 가지고 있다. 예를 들어, _HResult 값을 확인해 보면, 보기에 눈에 익숙하지 않지만, 다음과 같이 변환해 보면, 다소 우리에게 익숙한 HRESULT 값을 볼 수 있다.

 

0:000> ? -0n2147024891

Evaluate expression: -2147024891 = 80070005

 

, 해당 ExceptionAccess Denied Error와 관련 있음을 알 수 있다.

그리고, _xcode 를 살펴보면, 그냥 .NET Exception임을 보여준다.

 

0:000> ? -0n532459699

Evaluate expression: -532459699 = e0434f4d

 

또 다른 다음의 Exception의 예를 들어 보면,

 

0:000> !do 0c48dfa8

Name: System.NullReferenceException

MethodTable 0x03211a3c

EEClass 0x03201590

Size 64(0x40) bytes

GC Generation: 0

mdToken: 0x020000af  (c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll)

FieldDesc*: 0x00000000

        MT      Field     Offset                 Type       Attr      Value Name

0x008d575c 0x400001d      0x4                CLASS   instance 0x00000000 _className

0x008d575c 0x400001e      0x8                CLASS   instance 0x00000000 _exceptionMethod

0x008d575c 0x400001f      0xc                CLASS   instance 0x00000000 _exceptionMethodString

0x008d575c 0x4000020     0x10                CLASS   instance 0x01066ab8 _message

0x008d575c 0x4000021     0x14                CLASS   instance 0x00000000 _innerException

0x008d575c 0x4000022     0x18                CLASS   instance 0x00000000 _helpURL

0x008d575c 0x4000023     0x1c                CLASS   instance 0x0c48dfe8 _stackTrace

0x008d575c 0x4000024     0x20                CLASS   instance 0x00000000 _stackTraceString

0x008d575c 0x4000025     0x24                CLASS   instance 0x00000000 _remoteStackTraceString

0x008d575c 0x4000026     0x2c         System.Int32   instance 0 _remoteStackIndex

0x008d575c 0x4000027     0x30         System.Int32   instance -2147467261 _HResult

0x008d575c 0x4000028     0x28                CLASS   instance 0x00000000 _source

0x008d575c 0x4000029     0x34         System.Int32   instance 83683696 _xptrs

0x008d575c 0x400002a     0x38         System.Int32   instance -1073741819 _xcode

-----------------

Exception 0c48dfa8 in MT 03211a3c: System.NullReferenceException

_message: 개체 참조가 개체의 인스턴스로 설정되지 않았습니다.

_stackTrace:

04dece25 [DEFAULT] String ttt.ttt.ttt.1(SZArray Object)

04fcee50

00fbee70

00e3c34c [DEFAULT] [hasThis] Class System.Runtime.Remoting.Messaging.IMessage ttt.ttt.ttt.cls.Invoke(Class System.Runtime.Remoting.Messaging.IMessage)

04fcee6c

00fbee20

 

흥미롭게도 _stactTrace 라는 정보는 0x0c48dfe8 addressException이 발생한 시점의 stack dumping된 것으로 보면 된다. 그에 대한 정보가 상위의 Exception Object View 할 때 하단 부분에 첨부된 것을 볼 수 있기도 하다. 해당 Callstack Managed 이기 때문에 dds (또는 ddp) 명령은 아래와 같이 의미가 없을 수 있겠다.

 

0:000> dds 0x0c48dfe8

0c48dfe8  00c40274

0c48dfec  00000018

0c48dff0  04dece25

0c48dff4  04fcee50

0c48dff8  00fbee70

0c48dffc  00e3c34c

0c48e000  04fcee6c

0c48e004  00fbee20

0c48e008  00000000

 

하지만, 필요하다면, SOS 명령의 ip2md 를 이용해서 역시 문제 발생시의 Method 정보를 일일이 추출할 수 있다.

 

0:000> !ip2md 04dece25

MethodDesc: 0x00fbee70

Jitted by normal JIT

Method Name : [DEFAULT] String ttt.ttt.ttt.1(SZArray Object)

MethodTable 0xfbeeac

Module: 0x1c3980

mdToken: 0x060000b9 (c:\windows\assembly\gac\tttxxxx\2.1.0.0__de06f536f526478c\ttt.dll)

Flags : 0x10

Method VA : 0x04decd98

 

해당 Exception _xcode 정보를 보면,

 

0:000> ? -0n1073741819

Evaluate expression: -1073741819 = c0000005

 

이는 Access Violation 에 의한 Exception이 유발되었음을 알려준다. 보통 AV Exception record keep 하기도 하는 데, 이는 _xptrs 가 가지고 있곤 한다. 이는 kernel32!EXCEPTION_POINTERS 구조체를 가리킨다.

 

0:000> ? 0n83683696

Evaluate expression: 83683696 = 04fce970

 

0:000> dc 04fce970 l2

04fce970  00000018 00000000                    ........

 

상위의 Exception에서는 Exception Records 0x18 그리고, Context NULL 로 정상적으로 Keep 되지 않았지만, 해당 Context가 유용하다면, .cxr <context address> 을 통해 AV가 발생한 Context로 이동하여 Debugging할 수 있을 것이다. 

 

by 강세윤 | 2009/10/20 17:58 | Windows debugging | 트랙백 | 덧글(0)
트랙백 주소 : http://byung.egloos.com/tb/5146904
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]

:         :

:

비공개 덧글

< 이전페이지 다음페이지 >