Google Breakpad使用

319 阅读1分钟

参考

一 学习要点

  • .pro文件中包含.pri文件,eg:
    include($$PWD/src/third_libs/log4qt/log4qtlib.pri)
    

依赖源码的集成

二 借助pythonWindows下编译成库文件

三 在vs2017中搞CMake工程,编成静态库,主要是在上面能知道(依赖源码集成)源码是哪些

  • CMakeSettings.json

  • CMakeList.txt

  • 最简单的测试代码,如果指定路径为"./",则会保存在C:\Users\zhouqinan\AppData\Local\CrashDumps

    #include <iostream>
    #include <string>
    #include <cstdio>  
    
    // import breakpad cli
    #include "client/windows/handler/exception_handler.h" 
    #include <string>
    #include <locale>
    #include <codecvt>
    
    // convert string to wstring
    inline std::wstring to_wide_string(const std::string& input)
    {
            std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
            return converter.from_bytes(input);
    }
    
    template <typename T>
    class MONI_SP
    {
    public:
            MONI_SP(T* p_in) { p = p_in; };
            ~MONI_SP() { delete p; p = nullptr; }
    
    private:
            T* p;
    };
    
    int buggyFunc() {
            delete reinterpret_cast<char*>(0xFEE1DEAD);
            return 0;
    }
    
    int main(int argc, char* argv[])
    {
            std::string str_path = "./";
            auto wstr_path = to_wide_string(str_path);
    
            auto pHandler = new google_breakpad::ExceptionHandler(  
                    wstr_path,
                    /*FilterCallback*/ 0,
                    DumpCallback,
                    /*context*/
                    0,
                    true
            );	
    
            MONI_SP<google_breakpad::ExceptionHandler> sp_hander(pHandler);
            buggyFunc();
            return 0;
    }