diff --git a/src/util/assert.h b/src/util/assert.h index 2ffec2edfea3..245ed6c3ad41 100644 --- a/src/util/assert.h +++ b/src/util/assert.h @@ -3,14 +3,12 @@ #include +static constexpr const char* kDebugAssertPrefix = "DEBUG ASSERT"; + inline void mixxx_noop(void) {} inline void mixxx_debug_assert(const char* assertion, const char* file, int line, const char* function) { -#ifdef MIXXX_DEBUG_ASSERTIONS_FATAL - qFatal("DEBUG ASSERT: \"%s\" in function %s at %s:%d", assertion, function, file, line); -#else - qWarning("DEBUG ASSERT: \"%s\" in function %s at %s:%d", assertion, function, file, line); -#endif + qCritical("%s: \"%s\" in function %s at %s:%d", kDebugAssertPrefix, assertion, function, file, line); } inline bool mixxx_maybe_debug_assert_return_true(const char* assertion, const char* file, int line, const char* function) { diff --git a/src/util/cmdlineargs.cpp b/src/util/cmdlineargs.cpp index 79421e2ca977..1f944cbb46f6 100644 --- a/src/util/cmdlineargs.cpp +++ b/src/util/cmdlineargs.cpp @@ -11,6 +11,7 @@ CmdlineArgs::CmdlineArgs() m_midiDebug(false), m_developer(false), m_safeMode(false), + m_debugAssertBreak(false), m_settingsPathSet(false), m_logLevel(mixxx::Logging::kLogLevelDefault), // We are not ready to switch to XDG folders under Linux, so keeping $HOME/.mixxx as preferences folder. see lp:1463273 @@ -77,6 +78,8 @@ warnings and errors to the console unless this is set properly.\n", stdout); m_developer = true; } else if (QString::fromLocal8Bit(argv[i]).contains("--safeMode", Qt::CaseInsensitive)) { m_safeMode = true; + } else if (QString::fromLocal8Bit(argv[i]).contains("--debugAssertBreak", Qt::CaseInsensitive)) { + m_debugAssertBreak = true; } else { m_musicFiles += QString::fromLocal8Bit(argv[i]); } @@ -142,7 +145,15 @@ void CmdlineArgs::printUsage() { warning - Above + Warnings\n\ info - Above + Informational messages\n\ debug - Above + Debug/Developer messages\n\ -\n\ +\n" +#ifdef MIXXX_BUILD_DEBUG +"\ +--debugAssertBreak Breaks (SIGINT) Mixxx, if a DEBUG_ASSERT\n\ + evaluates to false. Under a debugger you can\n\ + continue afterwards.\ +\n" +#endif +"\ -h, --help Display this help message and exit", stdout); fputs("\n\n(For more information, see http://mixxx.org/wiki/doku.php/command_line_options)\n",stdout); diff --git a/src/util/cmdlineargs.h b/src/util/cmdlineargs.h index 32d42b68d978..8c5ca1beed41 100644 --- a/src/util/cmdlineargs.h +++ b/src/util/cmdlineargs.h @@ -24,6 +24,7 @@ class CmdlineArgs final { bool getMidiDebug() const { return m_midiDebug; } bool getDeveloper() const { return m_developer; } bool getSafeMode() const { return m_safeMode; } + bool getDebugAssertBreak() const { return m_debugAssertBreak; } bool getSettingsPathSet() const { return m_settingsPathSet; } mixxx::Logging::LogLevel getLogLevel() const { return m_logLevel; } bool getTimelineEnabled() const { return !m_timelinePath.isEmpty(); } @@ -44,6 +45,7 @@ class CmdlineArgs final { bool m_midiDebug; bool m_developer; // Developer Mode bool m_safeMode; + bool m_debugAssertBreak; bool m_settingsPathSet; // has --settingsPath been set on command line ? mixxx::Logging::LogLevel m_logLevel; // Level of logging message verbosity QString m_locale; diff --git a/src/util/logging.cpp b/src/util/logging.cpp index 95f304218ed0..4311b46870e8 100644 --- a/src/util/logging.cpp +++ b/src/util/logging.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -15,6 +16,7 @@ #include #include "util/cmdlineargs.h" +#include "util/assert.h" namespace mixxx { namespace { @@ -132,11 +134,45 @@ void MessageHandler(QtMsgType type, } break; case QtCriticalMsg: - // Critical errors are always shown on the console. - fprintf(stderr, "Critical %s", ba.constData()); - if (Logfile.isOpen()) { - Logfile.write("Critical "); - Logfile.write(ba); + { +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + bool debugAssert = strncmp(input, kDebugAssertPrefix, + strlen(kDebugAssertPrefix)) == 0; +#else + bool debugAssert = input.startsWith(QLatin1String(kDebugAssertPrefix)); +#endif + if (debugAssert) { + if (CmdlineArgs::Instance().getDebugAssertBreak()) { + fprintf(stderr, ba.constData()); + if (Logfile.isOpen()) { + Logfile.write(ba); + } + raise(SIGINT); + } else { +#ifdef MIXXX_DEBUG_ASSERTIONS_FATAL + // re-send as fatal + locker.unlock(); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + qFatal(input); +#else + qFatal(input.toLocal8Bit()); +#endif + return; +#else + fprintf(stderr, ba.constData()); + if (Logfile.isOpen()) { + Logfile.write(ba); + } +#endif + } + } else { + // Critical errors are always shown on the console. + fprintf(stderr, "Critical %s", ba.constData()); + if (Logfile.isOpen()) { + Logfile.write("Critical "); + Logfile.write(ba); + } + } } break; case QtFatalMsg: