source: branches/work_320/CrashHandler.cpp @ 666

Revision 666, 3.1 KB checked in by jls17, 5 years ago (diff)
  • added crash dump support by using breakpad (for now only on windows/linux; solaris will follow)
Line 
1//Copyright (C) 2014 John Luthgers | jls17
2//
3//This file is part of ARInside.
4//
5//    ARInside is free software: you can redistribute it and/or modify
6//    it under the terms of the GNU General Public License as published by
7//    the Free Software Foundation, version 2 of the License.
8//
9//    ARInside is distributed in the hope that it will be useful,
10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12//    GNU General Public License for more details.
13//
14//    You should have received a copy of the GNU General Public License
15//    along with ARInside. If not, see <http://www.gnu.org/licenses/>.
16
17#include "ARInsideMain.h"
18#include "CrashHandler.h"
19
20#ifdef ARINSIDE_BREAKPAD_SUPPORT
21
22// we need to include platform specific header file, because
23// each platform has it's own solution and implementation
24
25#ifdef WIN32
26#include <client/windows/handler/exception_handler.h>
27#elif __linux__
28#include <client/linux/handler/exception_handler.h>
29#else
30#error CrashHandler not supported/tested on this platform! Please disabled breakpad-support in CMakeList.txt
31#endif
32
33using namespace google_breakpad;
34
35#ifdef WIN32
36std::wstring GetWinTempPath()
37{
38        // get length of temp path
39        DWORD nPathSize = GetTempPath(0, NULL);
40        if (nPathSize == 0) 
41        {
42                cerr << "error " << GetLastError() << ": failed to get size of temp path! Crash dump support disabled!";
43                return L"";
44        }
45
46        // get the temp path
47        std::vector<TCHAR> buffer(nPathSize);
48        LPTSTR path = &buffer[0];
49        DWORD result = GetTempPath(nPathSize, path);
50        if (result == 0 || result > nPathSize)
51        {
52                cerr << "error " << GetLastError() << ": failed to get temp path! Crash dump support disabled!";
53                return L"";
54        }
55       
56        return std::wstring(path);
57}
58#endif
59
60/*
61###############################################################################
62      Implementation of the callback function
63*/
64#ifdef WIN32
65bool BreakpadMinidumpCallback(
66                                const wchar_t* dump_path,
67                                const wchar_t* minidump_id,
68                                void* context, EXCEPTION_POINTERS* exinfo,
69                                MDRawAssertionInfo* assertion,
70                                bool succeeded)
71#elif __linux__
72bool BreakpadMinidumpCallback(
73                                const MinidumpDescriptor &descriptor, 
74                                void *context, 
75                                bool succeeded)
76#endif
77{
78        cout << "Application crash! Mini dump written to: ";
79#ifdef WIN32
80  wcout << dump_path << minidump_id << L".dmp";
81#else
82  cout << descriptor.path();
83#endif
84  cout << endl;
85        return true;
86}
87
88/*
89###############################################################################
90      CrashHandler implementation
91*/
92
93CrashHandler::CrashHandler()
94{
95        handler = NULL;
96#ifdef WIN32
97        wstring path = GetWinTempPath();
98        if (path.empty()) return;
99        handler = new ExceptionHandler(path, NULL, BreakpadMinidumpCallback, NULL, ExceptionHandler::HANDLER_ALL);
100#elif __linux__
101        MinidumpDescriptor descriptor("/tmp");
102        handler = new ExceptionHandler(descriptor, NULL, BreakpadMinidumpCallback, NULL, true, -1);
103#endif
104}
105
106CrashHandler::~CrashHandler()
107{
108        delete handler;
109}
110
111#endif // ARINSIDE_BREAKPAD_SUPPORT
Note: See TracBrowser for help on using the repository browser.