From 590be3f8ffed0b61cf1d4ba12658796acbd777bf Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 18 Jan 2014 14:50:31 +0000 Subject: [PATCH] Initial integration of CrashRpt for Windows. --- CMakeLists.txt | 9 +++++++ CMakeModules/FindCrashRpt.cmake | 31 ++++++++++++++++++++++ src/Include/config_cmake.h.in | 3 +++ src/Main/CMakeLists.txt | 1 + src/Main/bootstrap.cxx | 47 +++++++++++++++++++++++++++++++-- src/Main/main.cxx | 8 ++++++ 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 CMakeModules/FindCrashRpt.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f3540fbb6..510d779cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,6 +203,15 @@ find_package(OpenGL REQUIRED) find_package(OpenAL REQUIRED) find_package(OpenSceneGraph 3.0.0 REQUIRED osgText osgSim osgDB osgParticle osgFX osgUtil osgViewer osgGA) +if (MSVC) + find_package(CrashRpt) + if (CRASHRPT_FOUND) + set(HAVE_CRASHRPT 1) + message(STATUS "Using CrashRpt") + include_directories( ${CRASHRPT_INCLUDE_DIR}) + endif() +endif() + if(ENABLE_FGADMIN) find_package(FLTK) diff --git a/CMakeModules/FindCrashRpt.cmake b/CMakeModules/FindCrashRpt.cmake new file mode 100644 index 000000000..c7730a4bb --- /dev/null +++ b/CMakeModules/FindCrashRpt.cmake @@ -0,0 +1,31 @@ +# Find CrashRpt +# ~~~~~~~~~~~~ +# Copyright (c) 2014, James Turner +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# +# CMake module to search for CrashRpt library +# +# If it's found it sets CRASHRPT_FOUND to TRUE +# and following variables are set: +# CRASHRPT_FOUND_INCLUDE_DIR +# CRASHRPT_FOUND_LIBRARY + +FIND_PATH(CRASHRPT_INCLUDE_DIR CrashRpt.h + PATH_SUFFIXES include + HINTS $ENV{CRASHRPTDIR} + PATHS + ${ADDITIONAL_LIBRARY_PATHS} + ) + +set(CRASHRPPT_LIBRARIES "") + +FIND_LIBRARY(CRASHRPT_LIBRARY NAMES CrashRpt1402 + HINTS $ENV{CRASHRPTDIR} + PATH_SUFFIXES lib + PATHS ${ADDITIONAL_LIBRARY_PATHS} + ) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CRASHRPT DEFAULT_MSG + CRASHRPT_LIBRARY CRASHRPT_INCLUDE_DIR) diff --git a/src/Include/config_cmake.h.in b/src/Include/config_cmake.h.in index 1485016ce..3c8295f65 100644 --- a/src/Include/config_cmake.h.in +++ b/src/Include/config_cmake.h.in @@ -42,3 +42,6 @@ #cmakedefine ENABLE_IAX #cmakedefine HAVE_DBUS + +#cmakedefine HAVE_CRASHRPT + diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt index 9167ec960..eb072b47d 100644 --- a/src/Main/CMakeLists.txt +++ b/src/Main/CMakeLists.txt @@ -109,6 +109,7 @@ target_link_libraries(fgfs ${JPEG_LIBRARY} ${HLA_LIBRARIES} ${EVENT_INPUT_LIBRARIES} + ${CRASHRPT_LIBRARY} ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} ${SIMGEAR_SCENE_LIBRARY_DEPENDENCIES} ${PLATFORM_LIBS} diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index fe988d7e3..96b053b61 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -60,6 +60,7 @@ using std::endl; #include #include "main.hxx" +#include #include
#include
#include @@ -70,6 +71,10 @@ using std::endl; #include // for transformToForegroundApp #endif +#if defined(HAVE_CRASHRPT) + #include +#endif + std::string homedir; std::string hostname; @@ -176,6 +181,41 @@ int main ( int argc, char **argv ) #endif _bootstrap_OSInit = 0; +#if defined(HAVE_CRASHRPT) + // Define CrashRpt configuration parameters + CR_INSTALL_INFO info; + memset(&info, 0, sizeof(CR_INSTALL_INFO)); + info.cb = sizeof(CR_INSTALL_INFO); + info.pszAppName = "FlightGear"; + info.pszAppVersion = FLIGHTGEAR_VERSION; + info.pszEmailSubject = "FlightGear " FLIGHTGEAR_VERSION " crash report"; + info.pszEmailTo = "fgcrash@goneabitbursar.com"; + info.pszUrl = "http://fgfs.goneabitbursar.com/crashreporter/crashrpt.php"; + info.uPriorities[CR_HTTP] = 3; + info.uPriorities[CR_SMTP] = 2; + info.uPriorities[CR_SMAPI] = 1; + + // Install all available exception handlers + info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; + + // Restart the app on crash + info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS; + + // autoamticallty install handlers for all threads + info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS; + + // Define the Privacy Policy URL + info.pszPrivacyPolicyURL = "http://flightgear.org/crash-privacypolicy.html"; + + // Install crash reporting + int nResult = crInstall(&info); + if(nResult!=0) { + std::cerr << "failed to install crash reporting engine" << std::endl; + } else { + crAddProperty("hudson-build-id", HUDSON_BUILD_ID); + } +#endif + #if defined(__FreeBSD__) // Ignore floating-point exceptions on FreeBSD signal(SIGFPE, SIG_IGN); @@ -224,8 +264,7 @@ int main ( int argc, char **argv ) fgviewerMain(argc, argv); else fgMainInit(argc, argv); - - + } catch (const sg_throwable &t) { std::string info; if (std::strlen(t.getOrigin()) != 0) @@ -245,6 +284,10 @@ int main ( int argc, char **argv ) perror("Possible cause"); } +#if defined(HAVE_CRASHRPT) + crUninstall(); +#endif + return 0; } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index a3b1338b3..2062a3796 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -33,6 +33,10 @@ #include #include +#if defined(HAVE_CRASHRPT) + #include +#endif + // Class references #include #include @@ -339,6 +343,10 @@ static void logToFile() logPath.append("fgfs.log"); } sglog().logToFile(logPath, SG_ALL, SG_INFO); + +#if defined(HAVE_CRASHRPT) + crAddFile2(logPath.c_str(), NULL, "FlightGear Log File", CR_AF_MAKE_FILE_COPY); +#endif } // Main top level initialization -- 2.39.5