google break pad

C++ 2012. 5. 23. 20:22


1.break pad svn 소스 체크아웃

http://google-breakpad.googlecode.com/svn/trunk

2.python 2.7.3 설치

3. visual studio 솔루션 파일(.sln) 생성

cd src/tools/gyp  (gyp에서 python 사용)

gyp.bat ../../client/windows/breakpad_client.gyp

src/client/windows/ 폴더에 .sln 파일 생성됨.


4. 간단한 사용

컴파일해서 lib 생성하고 사용하는 곳에서 svn 받은 폴더를 추가 포함디렉토리로 설정


Main.cpp

#include "stdafx.h"

#include <string>

#include <iostream>


using namespace std;

#include "test.h"


#include "client/windows/handler/exception_handler.h"


#if defined(_DEBUG)

# pragma comment(lib, "lib/debug/common.lib")

# pragma comment(lib, "lib/debug/crash_generation_client.lib")

# pragma comment(lib, "lib/debug/exception_handler.lib")

#else

# pragma comment(lib, "lib/release/common.lib")

# pragma comment(lib, "lib/release/crash_generation_client.lib")

# pragma comment(lib, "lib/release/exception_handler.lib")

#endif


// 첫 exception 처리

bool FuncFilterCallback(void* context, EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion)

{

return false; // false : 프로그램 중단, true : 프로그램 계속 진행

}


// minidump 생성후 호출되는 콜백

bool MinidumpCallbackFunc(

const wchar_t* dump_path,

    const wchar_t* minidump_id,

    void* context, // 사용자 정의 객체

    EXCEPTION_POINTERS* exinfo,

    MDRawAssertionInfo* assertion,

    bool succeeded)

{

cout << "succeed : " << boolalpha<< succeeded << endl;

return succeeded;

}


google_breakpad::ExceptionHandler* handler = NULL;


int _tmain(int argc, _TCHAR* argv[])

{

wstring dump_path = L"d:\\Dumps\\"; // 덤프가 생성될 폴더


handler = new google_breakpad::ExceptionHandler(dump_path,

                                 NULL,

                                 NULL, //MinidumpCallbackFunc,

                                 NULL,

                                 google_breakpad::ExceptionHandler::HANDLER_ALL,

                                 MiniDumpNormal, //MiniDumpWithFullMemory, //MiniDumpNormal, //MiniDumpWithFullMemory, //MiniDumpNormal, //MiniDumpWithFullMemory

                                 NULL, //kPipeName,

                                 NULL); //&custom_info);



//1 exception - 덤프 남긴하나 추적 힘듦

//throw std::exception("exp!!");


//2 DerefZeroCrash - 덤프 남음

//int* x = 0;

//*x = 1;


//3 invalid parameter crash - 덤프 안남음

//printf(NULL);


//4 pure virtual call - 덤프 남음

Derived derived;


//5. stack overflow - 덤프 안남음

//BYTE oo[1024 * 1024];

//for (int i=0; i<1024 * 1024; ++i) {

// oo[i] = i;

//}


//3. stack overflow : 

// 리커시브 stackoverflow 테스트코드


cout << "complete " << endl;

return 0;

}



test.h

#pragma once


class Derived;

class Base {

public:

Base(Derived* derived);

virtual ~Base();

virtual void DoSomething() = 0;

private:

Derived* derived_;

};


class Derived : public Base {

public:

Derived();

virtual void DoSomething();

};





test.cpp


#include "stdafx.h"

#include "test.h"


Base::Base(Derived* derived) : derived_(derived) {}

Base::~Base()

{

derived_->DoSomething();

}


Derived::Derived() : Base(this) {  }

void Derived::DoSomething(){}