diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..9ad6c4012 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "extern/breakpad"] + path = extern/breakpad + url = https://chromium.googlesource.com/breakpad/breakpad diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index c5313be64..ad3ca1599 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -1,6 +1,20 @@ project(tes3mp-server) option(BUILD_WITH_PAWN "Enable Pawn language" OFF) +option(ENABLE_BREAKPAD "Enable Google Breakpad for Crash reporting" OFF) + +if(ENABLE_BREAKPAD) + +endif(ENABLE_BREAKPAD) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_BREAKPAD") + if (UNIX) + set(Breakpad_Headers "${CMAKE_SOURCE_DIR}/extern/breakpad/src/client/linux") + set(Breakpad_Library "${CMAKE_SOURCE_DIR}/extern/breakpad/src/client/linux/libbreakpad_client.a") + elseif(WIN32) + set(Breakpad_Headers "${CMAKE_SOURCE_DIR}/extern/breakpad/src/client/windows") + set(Breakpad_Library "${CMAKE_SOURCE_DIR}/extern/breakpad/src/client/windows/libbreakpad_client.a") + endif (UNIX) + include_directories(${CMAKE_SOURCE_DIR}/extern/breakpad/src ${Breakpad_Headers}) if(BUILD_WITH_PAWN) add_subdirectory(amx) @@ -90,6 +104,7 @@ target_link_libraries(tes3mp-server components ${Terra_LIBRARY} ${Pawn_LIBRARY} + ${Breakpad_Library} ) if (UNIX) diff --git a/apps/openmw-mp/main.cpp b/apps/openmw-mp/main.cpp index f5946c64d..0cbbddae6 100644 --- a/apps/openmw-mp/main.cpp +++ b/apps/openmw-mp/main.cpp @@ -17,6 +17,10 @@ #include #include +#ifdef ENABLE_BREAKPAD +#include +#endif + using namespace std; using namespace mwmp; @@ -47,6 +51,51 @@ void printVersion(string version, int protocol) cout << "------------------------------------------------------------" << endl; } +#ifdef ENABLE_BREAKPAD +google_breakpad::ExceptionHandler *pHandler = 0; +#if defined(_WIN32) +bool DumpCallback(const char* _dump_dir, const char* _minidump_id, void* context, EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion, bool success) +#elif defined(__linux) +bool DumpCallback(const google_breakpad::MinidumpDescriptor &md, void *context, bool success) +#endif +{ + // NO STACK USE, NO HEAP USE THERE !!! + return success; +} + +void breakpad(std::string pathToDump) +{ +#ifdef _WIN32 + pHandler = new google_breakpad::ExceptionHandler( + pathToDump, + /*FilterCallback*/ 0, + DumpCallback, + /*context*/ + 0, + true + ); +#else + google_breakpad::MinidumpDescriptor md(pathToDump); + pHandler = new google_breakpad::ExceptionHandler( + md, + /*FilterCallback*/ 0, + DumpCallback, + /*context*/ 0, + true, + -1 + ); +#endif +} + +void breakpad_close() +{ + delete pHandler; +} +#else +void breakpad(std::string pathToDump){} +void breakpad_close(){} +#endif + std::string loadSettings (Settings::Manager & settings) { Files::ConfigurationManager mCfgMgr; @@ -102,6 +151,8 @@ int main(int argc, char *argv[]) Settings::Manager mgr; Files::ConfigurationManager cfgMgr; + breakpad(boost::filesystem::path(cfgMgr.getLogPath()).c_str()); + loadSettings(mgr); int logLevel = mgr.getInt("loglevel", "General"); @@ -206,5 +257,6 @@ int main(int argc, char *argv[]) std::cout.rdbuf(cout_rdbuf); std::cerr.rdbuf(cerr_rdbuf); + breakpad_close(); return code; } \ No newline at end of file diff --git a/extern/breakpad b/extern/breakpad new file mode 160000 index 000000000..e6d1c032b --- /dev/null +++ b/extern/breakpad @@ -0,0 +1 @@ +Subproject commit e6d1c032baa222d8a8dc87813e9067199ec0266d