Add log breakpoint system

This commit is contained in:
Dale Glass 2022-06-20 16:39:22 +02:00
parent 95ebe6bab0
commit d323be22df
2 changed files with 34 additions and 0 deletions

View file

@ -11,6 +11,7 @@
//
#include "LogHandler.h"
#include "Breakpoint.h"
#include <mutex>
@ -216,6 +217,13 @@ QString LogHandler::printMessage(LogMsgType type, const QMessageLogContext& cont
_repeatCount++;
}
if ( !_breakMessages.empty() ) {
for(const auto &str : _breakMessages) {
if (logMessage.contains(str)) {
BREAKPOINT
}
}
}
_previousMessage = message;
#ifdef Q_OS_WIN
// On windows, this will output log lines into the Visual Studio "output" tab
@ -262,3 +270,9 @@ void LogHandler::printRepeatedMessage(int messageID, LogMsgType type, const QMes
++_repeatedMessageRecords[messageID].repeatCount;
}
void LogHandler::breakOnMessage(const char *message) {
QMutexLocker lock(&_mutex);
LogHandler::getInstance()._breakMessages.append(QString::fromUtf8(message));
}

View file

@ -56,6 +56,24 @@ public:
void setupRepeatedMessageFlusher();
/**
* @brief Break when a message that contains the specified string is logged
*
* This is a function intended to be invoked from inside a debugger. It should be of help when it's hard to put a breakpoint
* on the generating line because it comes from inlined code, or the interesting text is generated at runtime.
*
* Example usage:
*
* @code {.cpp}
* LogHandler::breakOnMessage("No instance available for");
* @endcode
*
* Then the debugger should be triggered as soon as a message containing that string is logged. Backtracking
* through the call stack should lead back to the source.
*
* @param str Text to match
*/
static void breakOnMessage(const char *str);
private:
LogHandler();
~LogHandler() = default;
@ -79,6 +97,8 @@ private:
QString repeatString;
};
std::vector<RepeatedMessageRecord> _repeatedMessageRecords;
QStringList _breakMessages;
static QRecursiveMutex _mutex;
};