Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/util/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

#include <QtDebug>

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) {
Expand Down
13 changes: 12 additions & 1 deletion src/util/cmdlineargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/util/cmdlineargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand All @@ -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;
Expand Down
46 changes: 41 additions & 5 deletions src/util/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <stdio.h>
#include <iostream>
#include <signal.h>

#include <QByteArray>
#include <QFile>
Expand All @@ -15,6 +16,7 @@
#include <QtGlobal>

#include "util/cmdlineargs.h"
#include "util/assert.h"

namespace mixxx {
namespace {
Expand Down Expand Up @@ -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:
Expand Down