diff options
author | Remko Tronçon <git@el-tramo.be> | 2012-08-17 21:07:13 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2012-08-17 21:07:13 (GMT) |
commit | 4397df6b409ca84f63838fa635fc2abe8af80b71 (patch) | |
tree | 0806d51a1aaa6a1f9ac00df318be72fbee19ec1d /SwifTools | |
parent | ead6c91f24d77de3319e77ae1354387407065ef1 (diff) | |
download | swift-4397df6b409ca84f63838fa635fc2abe8af80b71.zip swift-4397df6b409ca84f63838fa635fc2abe8af80b71.tar.bz2 |
Added Breakpad support for Windows.
Diffstat (limited to 'SwifTools')
-rw-r--r-- | SwifTools/CrashReporter.cpp | 76 | ||||
-rw-r--r-- | SwifTools/CrashReporter.h | 22 | ||||
-rw-r--r-- | SwifTools/SConscript | 7 |
3 files changed, 103 insertions, 2 deletions
diff --git a/SwifTools/CrashReporter.cpp b/SwifTools/CrashReporter.cpp new file mode 100644 index 0000000..4a07e40 --- /dev/null +++ b/SwifTools/CrashReporter.cpp @@ -0,0 +1,76 @@ +/* + * 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::make_shared<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 diff --git a/SwifTools/CrashReporter.h b/SwifTools/CrashReporter.h new file mode 100644 index 0000000..834e8af --- /dev/null +++ b/SwifTools/CrashReporter.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2012 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> +#include <boost/filesystem.hpp> +#include <string> + +namespace Swift { + class CrashReporter { + public: + CrashReporter(const boost::filesystem::path& path); + + private: + struct Private; + boost::shared_ptr<Private> p; + }; +} diff --git a/SwifTools/SConscript b/SwifTools/SConscript index 5b97bed..3b25269 100644 --- a/SwifTools/SConscript +++ b/SwifTools/SConscript @@ -16,8 +16,8 @@ if env["SCONS_STAGE"] == "flags" : if env["SCONS_STAGE"] == "build" : swiftools_env = env.Clone() - swiftools_env.MergeFlags(swiftools_env["SWIFTEN_FLAGS"]) - swiftools_env.MergeFlags(swiftools_env["BOOST_FLAGS"]) + swiftools_env.UseFlags(swiftools_env["SWIFTEN_FLAGS"]) + swiftools_env.UseFlags(swiftools_env["BOOST_FLAGS"]) sources = [ "Idle/IdleDetector.cpp", @@ -44,6 +44,9 @@ if env["SCONS_STAGE"] == "build" : elif swiftools_env["HAVE_XSS"] : swiftools_env.Append(CPPDEFINES = ["HAVE_XSS"]) sources += ["Idle/XSSIdleQuerier.cpp"] + + swiftools_env.UseFlags(swiftools_env["BREAKPAD_FLAGS"]) + sources += ["CrashReporter.cpp"] swiftools_env["SWIFTOOLS_OBJECTS"] = [] Export("swiftools_env") |