제목

Similar documents
제목

<4D F736F F F696E74202D204B FC7C1B7CEB1D7B7A55F F6E48616E646C6572B8A6C5EBC7D1BFA1B7AFB0CBC3E2B9D7BCF6C1A

Microsoft PowerPoint - CSharp-10-예외처리

제목

C++ Programming

제목

제목

신림프로그래머_클린코드.key

PowerPoint Template

Cluster management software

1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout << " 양수입력 : "; cin >> *p; if (*p <= 0) cout << " 양수를입력해야합니다 " << endl; return; 동적할

윤성우의 열혈 TCP/IP 소켓 프로그래밍

Chapter #01 Subject

슬라이드 1

K&R2 Reference Manual 번역본

歯JavaExceptionHandling.PDF

슬라이드 1

IT현황리포트 내지 완

Microsoft PowerPoint - 8ÀÏ°_Æ÷ÀÎÅÍ.ppt

02 C h a p t e r Java

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345])

Deok9_Exploit Technique

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx

PowerPoint 프레젠테이션

JAVA PROGRAMMING 실습 09. 예외처리

슬라이드 1

슬라이드 1

임베디드시스템설계강의자료 6 system call 2/2 (2014 년도 1 학기 ) 김영진 아주대학교전자공학과

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

PowerPoint Presentation

BACK TO THE BASIC C++ 버그 헌팅: 버그를 예방하는 11가지 코딩 습관

BMP 파일 처리

rmi_박준용_final.PDF

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

OOP 소개


Microsoft PowerPoint - Chapter 6.ppt

PowerPoint 프레젠테이션

1장 윈도우 프로그래밍 들어가기

슬라이드 1

12-file.key

PowerPoint 프레젠테이션

DCL Debugging Support

untitled

C++ Programming

PowerPoint Presentation

API - Notification 메크로를통하여어느특정상황이되었을때 SolidWorks 및보낸경로를통하여알림메시지를보낼수있습니다. 이번기술자료에서는메크로에서이벤트처리기를통하여진행할예정이며, 메크로에서작업을수행하는데유용할것입니다. 알림이벤트핸들러는응용프로그램구현하는데있어

설계란 무엇인가?

PowerPoint Template

쉽게 풀어쓴 C 프로그래밍

예외 예외정의예외발생예외처리예외전파 단정 단정의선언 단정조건검사옵션 2

13주-14주proc.PDF

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

Chapter_02-3_NativeApp

Microsoft PowerPoint - chap01-C언어개요.pptx

Microsoft PowerPoint - C++ 5 .pptx

(Microsoft PowerPoint - 07\300\345.ppt [\310\243\310\257 \270\360\265\345])

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

2014밝고고운동요부르기-수정3

2005프로그램표지

초보자를 위한 C# 21일 완성

PowerPoint 프레젠테이션

Semantic Consistency in Information Exchange

Microsoft PowerPoint - chap06-2pointer.ppt

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a

Chap 6: Graphs

쉽게 풀어쓴 C 프로그래밍

JMF3_심빈구.PDF

Microsoft PowerPoint - 9ÀÏ°_ÂüÁ¶ÀÚ.ppt

No Slide Title

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074>

10.

Microsoft PowerPoint - chap11-포인터의활용.pptx

제11장 프로세스와 쓰레드

chap7.key

Chapter 4. LISTS

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074>

Microsoft PowerPoint - chap03-변수와데이터형.pptx

Microsoft Word - KPMC-400,401 SW 사용 설명서

Frama-C/JESSIS 사용법 소개

FileMaker ODBC and JDBC Guide

Spring Boot/JDBC JdbcTemplate/CRUD 예제

9장.예외와 단정

PowerPoint Presentation

Microsoft PowerPoint - 04-UDP Programming.ppt

MasoJava4_Dongbin.PDF

ALTIBASE 사용자가이드 Templete

<322EBCF8C8AF28BFACBDC0B9AEC1A6292E687770>

C++ Programming

JMF2_심빈구.PDF

Microsoft PowerPoint - chap12-고급기능.pptx

Lab 3. 실습문제 (Single linked list)_해답.hwp

PowerPoint 프레젠테이션

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CC0E7B0EDB0FCB8AE5C53746F636B5F4D616E D656E74732E637070>

RFP

Microsoft Word - Network Programming_NewVersion_01_.docx

3장. Hello World

1

Transcription:

Development Technology Seminar 작 성 자 : 고형호 이 메 일 : hyungho.ko@gmail.com 최초작성일 : 2007.01.19 최종작성일 : 2007.02.05 버 전 : 01.05 홈 피 : www.innosigma.com

Goal Exception Handling

1. SEH vs. CEH

Exception Handling (1/2) Exception Handling SEH(Structured Exception Handling) -. 운영체제가제공하는기법. -. 메모리액세스침해, 스택오버플로우, 0으로나누기등과같이저급의문제 -. try, except, finally CEH(C++ Exception Handling) -. C++ 언어가제공하는기법 -. C++ 언어의일부분으로, 애플로케이션코드에서의문제 -. try, catch, throw

Exception Handling (2/2) CEH(C++ Exception Handling) 동기화 (Synchronous) -. 컴파일러는명확한 throw 문으로만예외를던질수있다. -. 컴파일러는객체의수명을추적할필요없다. 비동기화 (Asynchronous) -. 컴파일러는 throw 문없이도예외를던질수있다. -. 컴파일러는객체의수명을추적해야하고코드의어느시점에서예외를풀어줄수있게준비되어야한다.

Exception int _tmain(int argc, _TCHAR* argv[]) TCHAR* p = NULL; p[1] = _T('M'); return 0; [Project: 01_Crash] SEH try, except, finally HOW TO? CEH try, catch, throw

SEH vs. CEH SEH CEH int _tmain(int argc, _TCHAR* argv[]) try TCHAR* p = NULL; p[1] = _T('M'); except(exception_execute_handler) tcout << "Exception caught!" << endl; return 0; int _tmain(int argc, _TCHAR* argv[]) try TCHAR* p = NULL; p[1] = _T('M'); catch(...) tcout << "Exception caught!" << endl; return 0; [Project: 02_SEH] [Project: 03_CEH]

Exception 원인 int _tmain(int argc, _TCHAR* argv[]) TCHAR* p = NULL; p[1] = _T('M'); 메모리액세스침해 운영체제가처리하는저급의문제 SEH

C++ Exception Handling 동기화 (Synchronous) CEH 비동기화 (Asynchronous) CEH int _tmain(int argc, _TCHAR* argv[]) try TCHAR* p = NULL; p[1] = _T('M'); catch(...) tcout << "Exception caught!" << endl; return 0; int _tmain(int argc, _TCHAR* argv[]) try TCHAR* p = NULL; p[1] = _T('M'); catch(...) tcout << "Exception caught!" << endl; return 0; [Project: 03_CEH] [Project: 04_CEH_Asyn]

CEH Visual Studio 2005 Setting 동기화 (Synchronous) : /EHsc 비동기화 (Asynchronous) : /EHa

2. Exception Information

Exception Information (1/2) int _tmain(int argc, _TCHAR* argv[]) try TCHAR* p = NULL; p[1] = _T('M'); except(exception_execute_handler) tcout << _T("Exception caught!") << endl; DWORD dwexceptioncode = GetExceptionCode(); if (EXCEPTION_ACCESS_VIOLATION == dwexceptioncode) tcout << _T("Access violation!") << endl; return 0; [Project: 05_SEH_Info]

Exception Information (2/2) int _tmain(int argc, _TCHAR* argv[]) try TCHAR* p = NULL; p[1] = _T('M'); catch(...) tcout << _T("Exception caught!") << endl; DWORD dwexceptioncode = GetExceptionCode(); if (EXCEPTION_ACCESS_VIOLATION == dwexceptioncode) tcout << _T("Access violation!") << endl; return 0; [Project: 06_CEH_Info] error C2707: '_exception_code' : 내장함수의컨텍스트가잘못되었습니다. except 블록또는예외필터외부의 _exception_code() 즉, GetExceptionCode 는 SEH 예외필터와예외핸들러에서만사용가능하다.

Combining SEH and CEH (1/3) CEH 에서 SEH 정보를얻기위해서는 SEH 를 CEH 에의해다룰수있어야한다. SEH 가발생할때마다변환함수가호출되어적절한 CEH 가발생하도록변환한다. _se_translator_function _set_se_translator( _se_translator_function); typedef void (*_se_translator_function)( unsigned int ncode, struct _EXCEPTION_POINTERS* pexp); Exception Information

Combining SEH and CEH (2/3) void TransSEH(unsigned int ncode, struct _EXCEPTION_POINTERS* pexp) tcout << _T("In TransSEH") << endl; int _tmain(int argc, _TCHAR* argv[]) _set_se_translator(transseh); try TCHAR* p = NULL; p[1] = _T('M'); catch(...) tcout << _T("Exception caught!") << endl; return 0; [Project: 07_SEH_Translator]

Combining SEH and CEH (3/3) class ExceptionSEH public: ExceptionSEH(unsigned int ncode) : m_ncode(ncode) private: unsigned int m_ncode; public: void GetExceptionInfo() if (EXCEPTION_ACCESS_VIOLATION == m_ncode) tcout << _T("Access violation!") << endl; ; void TransSEH(unsigned int ncode, struct _EXCEPTION_POINTERS* pexp) tcout << _T("In TransSEH") << endl; throw new ExceptionSEH(nCode); int _tmain(int argc, _TCHAR* argv[]) _set_se_translator(transseh); try TCHAR* p = NULL; p[1] = _T('M'); catch(exceptionseh* pexp) tcout << _T("SEH Exception caught!") << endl; pexp->getexceptioninfo(); delete pexp; return 0; [Project: 08_SEH_Translator_Class]

3. Unhandled Exception

Unhandled Exception (1/9) 언제데이터를수집할까요? 어떤데이터를수집할까요?

Unhandled Exception (2/9) 언제데이터를수집할까요? LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER lptoplevelexceptionfilter); 애플리케이션에대하여마지막 except 블록에서호출될함수에대한포인터이다.

Unhandled Exception (3/9) LONG TopExceptionFilter(LPEXCEPTION_POINTERS pexp) tcout << _T("In TopExceptionFilter") << endl; return EXCEPTION_EXECUTE_HANDLER; int _tmain(int argc, _TCHAR* argv[]) SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)TopExceptionFilter); TCHAR* p = NULL; p[1] = _T('M'); return 0; [Project: 09_Unhandled]

Unhandled Exception (4/9) 어떤데이터를수집할까요? DbgHelp.dll 파일의 MinidumpWriteDump API 를이용한 Dump 파일생성

Unhandled Exception (5/9) #include "dbghelp.h" typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hprocess, DWORD dwpid, ); LONG TopExceptionFilter(LPEXCEPTION_POINTERS pexp) tcout << _T("In TopExceptionFilter") << endl; LONG retval = EXCEPTION_CONTINUE_SEARCH; HMODULE hdll = ::LoadLibrary(_T("DbgHelp.dll")); MINIDUMPWRITEDUMP pdump = (MINIDUMPWRITEDUMP)::GetProcAddress(hDll, "MiniDumpWriteDump"); HANDLE hfile = ::CreateFile(_T("Crash.dmp"), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); int _tmain(int argc, _TCHAR* argv[]) SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)TopExceptionFilter); _MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = ::GetCurrentThreadId(); ExInfo.ExceptionPointers = pexp; ExInfo.ClientPointers = NULL; BOOL bok = pdump(getcurrentprocess(), GetCurrentProcessId(), hfile, MiniDumpNormal, &ExInfo, NULL, NULL); if (bok) tcout << "Saved dump file to Crash.dmp" << endl; retval = EXCEPTION_EXECUTE_HANDLER; ::CloseHandle(hFile); ::FreeLibrary(hDll); return retval; TCHAR* p = NULL; p[1] = _T('M'); return 0; [Project: 10_MiniDump]

Unhandled Exception (6/9) Exception 결과

Unhandled Exception (7/9) Visual Studio 2005 프로젝트를이용하여덤프파일 (.dmp) 열기

Unhandled Exception (8/9) 덤프프로젝트 Debugging

Unhandled Exception (9/9) Visual Studio 2005 Debugging 정보를이용하여 Exception 원인을파악할수있게된다.

Visual C++ 6.0 PDB Setting (1/3) PDB(Program Debug Database) 파일만들기 Visual Studio 2005 컴파일러기본 release 옵션은 PDB 파일을생성한다. Visual C++ 6.0 컴파일러기본 release 옵션은 PDB 파일을생성하지않는다.

Visual C++ 6.0 PDB Setting (2/3)

Visual C++ 6.0 PDB Setting (3/3)

Summary Exception Handling SEH(Structured Exception Handling) CEH(C++ Exception Handling) 동기화 (Synchronous) : /EHsc 비동기화 (Asynchronous) : /EHa Win32 API _set_se_translator SetUnhandledExceptionFilter MinidumpWriteDump

4. Component

Unhandled Exception Component Client DIP SRP <<interface>> IBlackBox +Install() OCP void BlackBox::Install() SetUnhandledExceptionFilter( ); BlackBox +Install() SRP(Single Responsibility Principle) : 단일책임의원칙 DIP(Dependency Inversion Principle) : 의존관계역전의원칙 ISP(Interface Segregation Principle) : 인터페이스분리의원칙 LSP(Liskov Substitution Principle) : 리스코프대체원칙 OCP(Open-Closed Principle) : 개방폐쇄원칙

5. Utility

Userdump 8.1 (1/3) 관련문서 : http://support.microsoft.com/kb/241215 다운로드 : http://www.microsoft.com/downloads/ details.aspx?familyid=e089ca41-6a87-40c8-bf69-28ac08570b7e&displaylang=en

Userdump 8.1 (2/3) Monitor Program 예외가발생하여종료되거나더이상응답하지않는프로그램등록

Userdump 8.1 (3/3) Output Folder Exception Codes MiniDump