From 007ad4e4d13e034eb20a9bdc999b761d4b61dccb Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 30 Jan 2023 09:20:16 +0100 Subject: [PATCH 1/3] Write crash log to temporary directory To make sure current user has rights to do so. --- components/crashcatcher/crashcatcher.hpp | 1 + components/debug/debugging.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/components/crashcatcher/crashcatcher.hpp b/components/crashcatcher/crashcatcher.hpp index 393a6f5bf5..a9efcaccdc 100644 --- a/components/crashcatcher/crashcatcher.hpp +++ b/components/crashcatcher/crashcatcher.hpp @@ -1,6 +1,7 @@ #ifndef CRASHCATCHER_H #define CRASHCATCHER_H +#include #include #if (defined(__APPLE__) || (defined(__linux) && !defined(ANDROID)) || (defined(__unix) && !defined(ANDROID)) \ diff --git a/components/debug/debugging.cpp b/components/debug/debugging.cpp index cfd3b75ba2..e528f148c6 100644 --- a/components/debug/debugging.cpp +++ b/components/debug/debugging.cpp @@ -329,12 +329,13 @@ int wrapApplication(int (*innerApplication)(int argc, char* argv[]), int argc, c { #if defined(_WIN32) const std::string crashLogName = Misc::StringUtils::lowerCase(appName) + "-crash.dmp"; - Crash::CrashCatcher crashy(argc, argv, Files::pathToUnicodeString(cfgMgr.getLogPath() / crashLogName)); + Crash::CrashCatcher crashy( + argc, argv, Files::pathToUnicodeString(std::filesystem::temp_directory_path() / crashLogName)); #else const std::string crashLogName = Misc::StringUtils::lowerCase(appName) + "-crash.log"; - // install the crash handler as soon as possible. note that the log path - // does not depend on config being read. - crashCatcherInstall(argc, argv, Files::pathToUnicodeString(cfgMgr.getLogPath() / crashLogName)); + // install the crash handler as soon as possible. + crashCatcherInstall( + argc, argv, Files::pathToUnicodeString(std::filesystem::temp_directory_path() / crashLogName)); #endif ret = innerApplication(argc, argv); } From 9c8a110efbee3693b93c5c05ac0877380b76b46a Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 29 Jan 2023 21:43:30 +0100 Subject: [PATCH 2/3] Print crash log in integration tests CI job --- .gitlab-ci.yml | 2 ++ CI/install_debian_deps.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1709455930..2f16c93ac4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -364,6 +364,8 @@ Ubuntu_Clang_integration_tests: - pip3 install --user numpy matplotlib termtables click script: - CI/run_integration_tests.sh + after_script: + - if [[ -f /tmp/openmw-crash.log ]]; then cat /tmp/openmw-crash.log; fi .MacOS: image: macos-11-xcode-12 diff --git a/CI/install_debian_deps.sh b/CI/install_debian_deps.sh index bad780315b..c942ce739d 100755 --- a/CI/install_debian_deps.sh +++ b/CI/install_debian_deps.sh @@ -46,6 +46,7 @@ declare -rA GROUPED_DEPS=( [openmw-integration-tests]=" ca-certificates + gdb git git-lfs libavcodec58 From c44bc5ade5ef1407bdb152181a7c1b1994c9417b Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 30 Jan 2023 09:17:56 +0100 Subject: [PATCH 3/3] Setup logging with properly initialized configuration manager Default constructed instance may provide different paths from initialized one. --- apps/bulletobjecttool/main.cpp | 9 ++++++--- apps/launcher/maindialog.cpp | 2 ++ apps/navmeshtool/main.cpp | 9 ++++++--- apps/opencs/main.cpp | 2 +- apps/openmw/main.cpp | 2 +- components/debug/debugging.cpp | 25 +++++++------------------ components/debug/debugging.hpp | 6 +++--- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/apps/bulletobjecttool/main.cpp b/apps/bulletobjecttool/main.cpp index 30ddff1c6c..1167120695 100644 --- a/apps/bulletobjecttool/main.cpp +++ b/apps/bulletobjecttool/main.cpp @@ -48,6 +48,8 @@ namespace using StringsVector = std::vector; + constexpr std::string_view applicationName = "BulletObjectTool"; + bpo::options_description makeOptionsDescription() { using Fallback::FallbackMap; @@ -177,8 +179,9 @@ namespace VFS::registerArchives(&vfs, fileCollections, archives, true); - Settings::Manager settings; - settings.load(config); + Settings::Manager::load(config); + + setupLogging(config.getLogPath(), applicationName); ESM::ReadersCache readers; EsmLoader::Query query; @@ -221,5 +224,5 @@ namespace int main(int argc, char* argv[]) { - return wrapApplication(runBulletObjectTool, argc, argv, "BulletObjectTool"); + return wrapApplication(runBulletObjectTool, argc, argv, applicationName); } diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 44c8a30be2..f8ebdb51d6 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -424,6 +425,7 @@ bool Launcher::MainDialog::setupGraphicsSettings() mCfgMgr.addCommonOptions(desc); mCfgMgr.readConfiguration(variables, desc, true); Settings::Manager::load(mCfgMgr); + setupLogging(mCfgMgr.getLogPath(), "Launcher"); return true; } catch (std::exception& e) diff --git a/apps/navmeshtool/main.cpp b/apps/navmeshtool/main.cpp index 808f393b49..b93e6cd7c8 100644 --- a/apps/navmeshtool/main.cpp +++ b/apps/navmeshtool/main.cpp @@ -57,6 +57,8 @@ namespace NavMeshTool using StringsVector = std::vector; + constexpr std::string_view applicationName = "NavMeshTool"; + bpo::options_description makeOptionsDescription() { using Fallback::FallbackMap; @@ -197,8 +199,9 @@ namespace NavMeshTool VFS::registerArchives(&vfs, fileCollections, archives, true); - Settings::Manager settings; - settings.load(config); + Settings::Manager::load(config); + + setupLogging(config.getLogPath(), applicationName); const auto agentCollisionShape = DetourNavigator::toCollisionShapeType( Settings::Manager::getInt("actor collision shape type", "Game")); @@ -263,5 +266,5 @@ namespace NavMeshTool int main(int argc, char* argv[]) { - return wrapApplication(NavMeshTool::runNavMeshTool, argc, argv, "NavMeshTool"); + return wrapApplication(NavMeshTool::runNavMeshTool, argc, argv, NavMeshTool::applicationName); } diff --git a/apps/opencs/main.cpp b/apps/opencs/main.cpp index 957987640e..28201edf7e 100644 --- a/apps/opencs/main.cpp +++ b/apps/opencs/main.cpp @@ -85,5 +85,5 @@ int runApplication(int argc, char* argv[]) int main(int argc, char* argv[]) { - return wrapApplication(&runApplication, argc, argv, "OpenMW-CS", false); + return wrapApplication(&runApplication, argc, argv, "OpenMW-CS"); } diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 3eaa3f1980..cc51462322 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -256,7 +256,7 @@ extern "C" int SDL_main(int argc, char** argv) int main(int argc, char** argv) #endif { - return wrapApplication(&runApplication, argc, argv, "OpenMW", false); + return wrapApplication(&runApplication, argc, argv, "OpenMW"); } // Platform specific for Windows when there is no console built into the executable. diff --git a/components/debug/debugging.cpp b/components/debug/debugging.cpp index e528f148c6..391ec58df4 100644 --- a/components/debug/debugging.cpp +++ b/components/debug/debugging.cpp @@ -2,13 +2,16 @@ #include #include +#include +#include #include #include #include -#include #include +#include + #ifdef _WIN32 #include #include @@ -280,7 +283,7 @@ Misc::Locked getLockedRawStderr() } // Redirect cout and cerr to the log file -void setupLogging(const std::filesystem::path& logDir, const std::string& appName, std::ios_base::openmode mode) +void setupLogging(const std::filesystem::path& logDir, std::string_view appName, std::ios_base::openmode mode) { #if defined(_WIN32) && defined(_DEBUG) // Redirect cout and cerr to VS debug output when running in debug mode @@ -299,8 +302,7 @@ void setupLogging(const std::filesystem::path& logDir, const std::string& appNam #endif } -int wrapApplication(int (*innerApplication)(int argc, char* argv[]), int argc, char* argv[], const std::string& appName, - bool autoSetupLogging) +int wrapApplication(int (*innerApplication)(int argc, char* argv[]), int argc, char* argv[], std::string_view appName) { #if defined _WIN32 (void)Debug::attachParentConsole(); @@ -312,19 +314,6 @@ int wrapApplication(int (*innerApplication)(int argc, char* argv[]), int argc, c int ret = 0; try { - Files::ConfigurationManager cfgMgr; - - if (autoSetupLogging) - { - std::ios_base::openmode mode = std::ios::out; - - // If we are collecting a stack trace, append to existing log file - if (argc == 2 && strcmp(argv[1], crash_switch) == 0) - mode |= std::ios::app; - - setupLogging(cfgMgr.getLogPath(), appName, mode); - } - if (const auto env = std::getenv("OPENMW_DISABLE_CRASH_CATCHER"); env == nullptr || std::atol(env) == 0) { #if defined(_WIN32) @@ -347,7 +336,7 @@ int wrapApplication(int (*innerApplication)(int argc, char* argv[]), int argc, c #if (defined(__APPLE__) || defined(__linux) || defined(__unix) || defined(__posix)) if (!isatty(fileno(stdin))) #endif - SDL_ShowSimpleMessageBox(0, (appName + ": Fatal error").c_str(), e.what(), nullptr); + SDL_ShowSimpleMessageBox(0, (std::string(appName) + ": Fatal error").c_str(), e.what(), nullptr); Log(Debug::Error) << "Error: " << e.what(); diff --git a/components/debug/debugging.hpp b/components/debug/debugging.hpp index 37e58696ae..6700b5b761 100644 --- a/components/debug/debugging.hpp +++ b/components/debug/debugging.hpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -35,9 +36,8 @@ std::ostream& getRawStderr(); Misc::Locked getLockedRawStderr(); void setupLogging( - const std::filesystem::path& logDir, const std::string& appName, std::ios_base::openmode mode = std::ios::out); + const std::filesystem::path& logDir, std::string_view appName, std::ios_base::openmode mode = std::ios::out); -int wrapApplication(int (*innerApplication)(int argc, char* argv[]), int argc, char* argv[], const std::string& appName, - bool autoSetupLogging = true); +int wrapApplication(int (*innerApplication)(int argc, char* argv[]), int argc, char* argv[], std::string_view appName); #endif