kyuseo의 게임 프로그래밍

릴리즈(Release) 버전 게임서버에서 Crash 발생시 프로그램 오류 검출하는 방법 본문

C++ 개발

릴리즈(Release) 버전 게임서버에서 Crash 발생시 프로그램 오류 검출하는 방법

kyuseo 2008. 10. 28. 18:34

개요..

 

릴리즈 버전의 프로그램 특히 게임 서버 프로그램이 가끔 죽는(다운되는) 현상은 버그를 찾기가 매우 어렵지만, 다행히 SEH 관련 프로그래밍 기능을 활용하면 Call Stack 가 검출되어 프로그램의 오류를 검출하기가 조금은 쉬워집니다.

 

아주 오래된 프로그램인 닥터 왓슨(drwtsn32.exe)은 콜스택을 남겨서 오류가 발생한 함수의 위치는 알 수 있지만 조금 더 정확한 디버깅 정보가 남으면 오류를 잡기가 훨씬 쉬워지겠지요.

 

이번에 개발한 PMango Game Engine / Fungrep Framework SEHVisual C++ Runtime Error 오류 및 액세스 위반이 발생한 프로그램 소스코드의 함수뿐만 아니라 파일의 라인까지 기록이 남기 때문에 조금 더 쉽고 정확하게 오류를 추적하고 디버그를 할 수 있습니다.

 

프로그램 문의 : ks@tk.co.kr

 

라인 정보까지 검출된 모습의 예)

 

CCHServerRoom::NextTurn

( d:\fungrepproject\holdem\holdemserver\holdemserver\chserverroomgameprocess.cpp:1095 )

 

 

 

SEH 클래스의 모습

 

/**

    @class    CSSeTranslator

    @date    2008/10/24

    @author    채경석(kyuseo99@chol.com)

    @brief    서버에서사용하는SeTranslator

            닥터왓슨과ppd 파일을이용하면Call Stack 를저장이가능하지만Visual C++ Runtime Error 발생시

            메세지박스가발생하여서버가죽지도않고닥터왓슨로그도기록되지않는현상을대처하기위한클래스

            기본저장위치는C:\\PMangoSEH.log 파일로저장된다.

*/

class CSSeTranslator : public CPSeTranslator

{

public:

    CSSeTranslator();

    virtual ~CSSeTranslator();

 

    void Set( LPCSTR szPpd, LPCSTR szFileName = "C:\\PMangoSEH.log" ); ///< 로그파일및ppd 정보를설정한다.

 

protected:

    virtual void OnSeTranslatorProc( DWORD dwExceptionCode, EXCEPTION_POINTERS* pException );

 

public:

    int m_n[10];

    CString m_str[10];

 

protected:

    CTime m_tmStart;

    CString m_strPpd;

    CString m_strFileName;

};

 

inline CSSeTranslator& GetSeTranslator()

{

    static CSSeTranslator SSeTranslator;

 

    return SSeTranslator;

}

 

 

PMango Game Engine / Fungrep Framework SEH 에서 남은 오류로그의 예

 

>>>>> PMango Game Engine / Fungrep Framework SEH Start ( ks@tk.co.kr ) >>>>>

 

응용 프로그램 예외 발생:

    오류내용 :    Exception : ACCESS_VIOLATION (0xc0000005), Address : 0x0040aa81

    현재시간 :    2008/10/28, 18:16:43

 

*----> 실행 파일 정보 <----*

    실행파일 :    ClubGostopServerApp.exe

    PPD 파일 :    ppd.ppd

    현재경로 :    D:\FungrepProject\ClubGostop\ClubGostopServer\App\release\

 

    실행시간 :    2008/10/28, 18:16:42

    경과시간 :    0일 00:00:01

 

    빌드번호 :    1138

    빌드시간 :    2008/10/28, 18:16:19

 

*----> 디버그 변수 <----*

숫자변수 : ( 0, 0, 0, 0, 0 )

: ( 0, 0, 0, 0, 0 )

문자변수 0|1: ( | )

문자변수 2|3: ( | )

문자변수 4|5: ( | )

문자변수 6|7: ( | )

문자변수 8|9: ( | )

 

*----> 스택 역 추적 <----*

Module : D:\FungrepProject\ClubGostop\ClubGostopServer\App\release\ClubGostopServerApp.exe (Base Address : 0x00400000, Exception Address : 0x0040aa81)

FramePtr ReturnAd Param#1 Param#2 Param#3 Param#4             Function Name

00 00409C5F 00409F7D 037EFE80 010848CC 0108497C 00000003         CCHServerRoom::GameResult ( d:\fungrepproject\holdem\holdemserver\holdemserver\chserverroomgameprocess.cpp:1218 )

01 00409F7D 00407BD4 00000001 7C95A360 01076C64 004C3424         CCHServerRoom::NextTurn ( d:\fungrepproject\holdem\holdemserver\holdemserver\chserverroomgameprocess.cpp:1095 )

02 00407BD4 0040515E 00000001 00000003 00000000 00EA50F8         CCHServerRoom::BetGame ( d:\fungrepproject\holdem\holdemserver\holdemserver\chserverroomgameprocess.cpp:976 )

03 0040515E 0041AE2F 01076C64 02E7C978 00EA50F8 037EFF30         CCHServer::OnBetGame ( d:\fungrepproject\holdem\holdemserver\holdemserver\chserveronpacket.cpp:235 )

04 0041AE2F 0041A865 01076C64 02E7C978 02E7C898 00499FA8         CServer::OnReceive ( d:\fungrepproject\commonmultiserver\serveronpacket.cpp:625 )

05 0041A865 00498403 030F4068 0049A0D9 02E7C928 00000008         CServer::OnReceive ( d:\fungrepproject\commonmultiserver\serveronpacket.cpp:123 )

06 00498403 00468F7A 00000026 128FED4F 00000000 0116F880         CPServerUser::QueuedComplete ( :0 )

07 00468F7A 0046901F 00000000 7C824829 0116F880 00000000         _callthreadstartex ( f:\sp\vctools\crt_bld\self_x86\crt\src\threadex.c:348 )

08 0046901F 00000000 00468FA0 0116F880 00000000 00000000         _threadstartex ( f:\sp\vctools\crt_bld\self_x86\crt\src\threadex.c:326 )

 

>>>>> PMango Game Engine / Fungrep Framework SEH End ( ks@tk.co.kr ) >>>>>

 

 

닥터왓슨 (drwtsn32.exe) 에서 남은 오류로그의 예

 

*----> 스레드 Id 0x1884의 상태 덤프 <----*

 

eax=00000002 ebx=00f14f54 ecx=00000001 edx=02ec322c esi=00f14ee4 edi=00000000

eip=00418f61 esp=02abfe20 ebp=02abfe28 iopl=0 nv up ei pl nz na pe nc

cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010202

 

함수: ClubGostopServerApp_lv0_1!CMission::Reset

00418f3c 0fb64608 movzx eax,byte ptr [esi+0x8]

00418f40 6bc02c imul eax,eax,0x2c

00418f43 8d5c3044 lea ebx,[eax+esi+0x44]

00418f47 e860020000 call ClubGostopServerApp_lv0_1!CPRater<unsigned char>::Lottery (004191ac)

00418f4c 83f801 cmp eax,0x1

00418f4f 75eb jnz ClubGostopServerApp_lv0_1!CMission::Reset+0x5e (00418f3c)

00418f51 0fb64608 movzx eax,byte ptr [esi+0x8]

00418f55 6bc02c imul eax,eax,0x2c

00418f58 8d443044 lea eax,[eax+esi+0x44]

00418f5c e8a0020000 call ClubGostopServerApp_lv0_1!CPRater<unsigned char>::GetLucky (00419201)

오류 -> 00418f61 8a00 mov al,[eax] ds:0023:00000002=??

00418f63 88443709 mov [edi+esi+0x9],al

00418f67 47 inc edi

00418f68 83ff04 cmp edi,0x4

00418f6b 7ccf jl ClubGostopServerApp_lv0_1!CMission::Reset+0x5e (00418f3c)

00418f6d 8d5e0f lea ebx,[esi+0xf]

00418f70 33c0 xor eax,eax

00418f72 8bfb mov edi,ebx

00418f74 ab stosd

00418f75 8a4608 mov al,[esi+0x8]

00418f78 84c0 test al,al

 

*----> 스택 역 추적 <----*

*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\WINDOWS\system32\kernel32.dll -

ChildEBP RetAddr Args to Child

02abfe28 00406362 00000000 00000001 00f05f6c ClubGostopServerApp_lv0_1!CMission::Reset+0x83

02abfeb0 0040628e 00f149ac 00f149ac 02abfee8 ClubGostopServerApp_lv0_1!CCGServerRoom::ProcessStartGame+0x81

02abfec0 00405747 00000000 00f149ac 00000000 ClubGostopServerApp_lv0_1!CCGServerRoom::ProcessGame+0x18

02abfee8 004091b4 00000002 0325ed1c 00483974 ClubGostopServerApp_lv0_1!CCGServerRoom::StartGame+0x139

02abff28 004133fe 247068d8 1fc46cc4 76994f60 ClubGostopServerApp_lv0_1!CCGServerRoom::OnGameLoop+0x338

02abff58 0041303c 0044fd66 00d35138 00000000 ClubGostopServerApp_lv0_1!CServer::OnGameLoopTimerThread+0x5b

02abff5c 0044fd66 00d35138 00000000 00f3e090 ClubGostopServerApp_lv0_1!CServer::GameLoopTimerThreadProc+0xc (FPO: [1,0,0])

02abff78 0043c8b5 00d35204 1fc46c2c 00000000 ClubGostopServerApp_lv0_1!CPTimerThread::ThreadProc+0x54

02abffb0 0043c95a 00000000 7c824829 00f3e090 ClubGostopServerApp_lv0_1!_callthreadstartex+0x1b

02abffb8 7c824829 00f3e090 00000000 00000000 ClubGostopServerApp_lv0_1!_threadstartex+0x7f

WARNING: Stack unwind information not available. Following frames may be wrong.

02abffec 00000000 0043c8db 00f3e090 00000000 kernel32!GetModuleHandleA+0xdf