source: branches/work_320/CrashHandler.cpp @ 679

Revision 679, 3.1 KB checked in by jls17, 5 years ago (diff)
  • fixed some memory leaks in case memory allocation fails in ARFieldList.cpp and ARSchemaList.cpp
  • small changes to the initialization of the crash handler
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        cout.flush();
80#ifdef WIN32
81  wcout << dump_path << minidump_id << L".dmp";
82#else
83  cout << descriptor.path();
84#endif
85  cout << endl;
86        return true;
87}
88
89/*
90###############################################################################
91      CrashHandler implementation
92*/
93
94CrashHandler::CrashHandler()
95{
96        handler = NULL;
97#ifdef WIN32
98        wstring path = GetWinTempPath();
99        if (path.empty()) return;
100        handler = new ExceptionHandler(path, NULL, BreakpadMinidumpCallback, NULL, ExceptionHandler::HANDLER_ALL);
101#elif __linux__
102        MinidumpDescriptor descriptor("/tmp");
103        handler = new ExceptionHandler(descriptor, NULL, BreakpadMinidumpCallback, NULL, true, -1);
104#endif
105}
106
107CrashHandler::~CrashHandler()
108{
109        delete handler;
110}
111
112#endif // ARINSIDE_BREAKPAD_SUPPORT
Note: See TracBrowser for help on using the repository browser.