[WinDbg] first-chance, second-chance Exception
First-chance Exception 이란 디버거에서 프로그램이 실행 중일 때 SEH 같은 Exception
처리 구문이 들어가 있는 코드를 실행 하다가 어떠한 이유에서 던지 Exception 이 일어 났고
그 Exception 에 대한 처리 코드가 존재 하여 처리가 되었음을 디버거에 알리는 것입니다.
이 Exception이 꼭 프로그램에 심각한 오류가 있음을 말하는 것은 아니며 Exception 처리
코드에 의해 해당 Exception이 안전하게 처리가 되었고 계속 실행할 수 있음을 의미 할 수
있습니다.(대개는 대부분 별 문제 없는 경우입니다.)
만약 그런 Exception에 대한 처리가 없는 경우 디버거는 이를 인지 하고 사용자에게 직접
Exception이 났음 을 알리는데 이를 Second Chance Exception 이라고 하고 이것이
우리가 프로그램 디버깅 중 흔히 보는 에러 상황이 되겠습니다.
http://support.microsoft.com/kb/105675
bReturn = IsBadReadPtr(p, 4); <- 이때 다음과 같이 first chance 발생됨
(e84.b8c): Access violation - code c0000005 (first chance)First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=08c0e043 ebx=7ffda000 ecx=08c0e040 edx=08c0e040 esi=00001000 edi=00000000
eip=76fcdf2b esp=0012fc94 ebp=0012fcc0 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246
kernel32!IsBadReadPtr+0x39:
76fcdf2b 8a01 mov al,byte ptr [ecx] ds:0023:08c0e040=??
*p = 10; <- 이때 다음과 같이 first chance 발생됨
(e84.b8c): Access violation - code c0000005 (first chance)First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0012fa08 ebx=7ffda000 ecx=08c0e040 edx=00000000 esi=00000000 edi=00000000
eip=00401174 esp=0012fcd0 ebp=0012ff0c iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246
WinDbgTest!Example10+0xcc:
00401174 c6010a mov byte ptr [ecx],0Ah ds:0023:08c0e040=??
모두다 SEH안에서 예외가 발생했기 때문에 first가 되는 것이다.
처리 구문이 들어가 있는 코드를 실행 하다가 어떠한 이유에서 던지 Exception 이 일어 났고
그 Exception 에 대한 처리 코드가 존재 하여 처리가 되었음을 디버거에 알리는 것입니다.
이 Exception이 꼭 프로그램에 심각한 오류가 있음을 말하는 것은 아니며 Exception 처리
코드에 의해 해당 Exception이 안전하게 처리가 되었고 계속 실행할 수 있음을 의미 할 수
있습니다.(대개는 대부분 별 문제 없는 경우입니다.)
만약 그런 Exception에 대한 처리가 없는 경우 디버거는 이를 인지 하고 사용자에게 직접
Exception이 났음 을 알리는데 이를 Second Chance Exception 이라고 하고 이것이
우리가 프로그램 디버깅 중 흔히 보는 에러 상황이 되겠습니다.
http://support.microsoft.com/kb/105675
|
__try
{
bReturn = IsBadReadPtr(buffer, sizeof(buffer));
sprintf( bufDebug, _T("Example10() buffer = %08X, bReturn = %d\n"), buffer, bReturn );
OutputDebugString( bufDebug );
//
// 아래의 주소를 검사할때 EXCEPTION_ACCESS_VIOLATION이 발생하는데
// 구조화된 예외처리를 사용하지 않으면 WinDbg로 step-by-step로 볼때 더이상 진행할 수 없다.
// 그래서 구조화된 예외처리를 반드시 사용을 적극 추천한다.
//
// 릴리즈로 돌릴때 보면 예외는 발생하지만(AV) __except()구문은 호출되지 않는다
//
p = (TCHAR*)0x08c0e040;
bReturn = IsBadReadPtr(p, 4);
sprintf( bufDebug, _T("Example10() p = %08X, bReturn = %d\n"), p, bReturn );
OutputDebugString( bufDebug );
*p = 10; // 0xC0000005 예외 발생한다
}
__except(RunExceptionCode(GetExceptionCode()))
{
OutputDebugString( "액세스 오류\n" );
}
|
bReturn = IsBadReadPtr(p, 4); <- 이때 다음과 같이 first chance 발생됨
(e84.b8c): Access violation - code c0000005 (first chance)First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=08c0e043 ebx=7ffda000 ecx=08c0e040 edx=08c0e040 esi=00001000 edi=00000000
eip=76fcdf2b esp=0012fc94 ebp=0012fcc0 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246
kernel32!IsBadReadPtr+0x39:
76fcdf2b 8a01 mov al,byte ptr [ecx] ds:0023:08c0e040=??
*p = 10; <- 이때 다음과 같이 first chance 발생됨
(e84.b8c): Access violation - code c0000005 (first chance)First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0012fa08 ebx=7ffda000 ecx=08c0e040 edx=00000000 esi=00000000 edi=00000000
eip=00401174 esp=0012fcd0 ebp=0012ff0c iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246
WinDbgTest!Example10+0xcc:
00401174 c6010a mov byte ptr [ecx],0Ah ds:0023:08c0e040=??
모두다 SEH안에서 예외가 발생했기 때문에 first가 되는 것이다.
댓글
댓글 쓰기