summaryrefslogtreecommitdiffstats
blob: 42a98d8e3175d0ddcc6d2c1624a59115493bc4c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright (c) 2012 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */


#include <SwifTools/CrashReporter.h>
#include <Swiften/Base/Platform.h>

#if defined(HAVE_BREAKPAD)

#pragma GCC diagnostic ignored "-Wold-style-cast"

#include <boost/smart_ptr/make_shared.hpp>

#ifdef SWIFTEN_PLATFORM_MACOSX
#include "client/mac/handler/exception_handler.h"
#endif
#ifdef SWIFTEN_PLATFORM_WINDOWS
#include "client/windows/handler/exception_handler.h"
#endif

#if defined(SWIFTEN_PLATFORM_WINDOWS)
static bool handleDump(const wchar_t* /* dir */, const wchar_t* /* id*/, void* /* context */, EXCEPTION_POINTERS*, MDRawAssertionInfo*, bool /* succeeded */) {
	return false;
}
#else
static bool handleDump(const char* /* dir */, const char* /* id*/, void* /* context */, bool /* succeeded */) {
	return false;
}
#endif

namespace Swift {

struct CrashReporter::Private {
	boost::shared_ptr<google_breakpad::ExceptionHandler> handler;
};

CrashReporter::CrashReporter(const boost::filesystem::path& path) {
	// Create the path that will contain the crash dumps
	if (!boost::filesystem::exists(path)) {
		try {
			boost::filesystem::create_directories(path);
		}
		catch (const boost::filesystem::filesystem_error& e) {
			std::cerr << "ERROR: " << e.what() << std::endl;
		}
	}

	p = boost::make_shared<Private>();
#if defined(SWIFTEN_PLATFORM_WINDOWS)
	// FIXME: Need UTF8 conversion from string to wstring
	std::string pathString = path.string();
	p->handler = boost::shared_ptr<google_breakpad::ExceptionHandler>(
			// Not using make_shared, because 'handleDump' seems to have problems with VC2010
			new google_breakpad::ExceptionHandler(
				std::wstring(pathString.begin(), pathString.end()), 
				(google_breakpad::ExceptionHandler::FilterCallback) 0, 
				handleDump, 
				(void*) 0, 
				google_breakpad::ExceptionHandler::HANDLER_ALL));
// Turning it off for Mac, because it doesn't really help us
//#elif defined(SWIFTEN_PLATFORM_MACOSX)
//	p->handler = boost::make_shared<google_breakpad::ExceptionHandler>(path.string(), (google_breakpad::ExceptionHandler::FilterCallback) 0, handleDump, (void*) 0, true, (const char*) 0);
#endif
}

};

#else

// Dummy implementation
namespace Swift {
	CrashReporter::CrashReporter(const boost::filesystem::path&) {}
};

#endif