-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: Add a mechanism to print the stacktrace on crash using qDebug.
This mechanism will only provide a stacktrace on platforms that provide glibc, thus on Windows we will only have the application log without any stacktrace. For now it should be enough. Research was done on boost::stacktrace, breakpad also. In the future, Scopy can pe upgraded to C++ 23 which will provide a mechanism for crash reporting. Signed-off-by: AlexandraTrifan <[email protected]>
- Loading branch information
1 parent
890ae2c
commit cfe1d2a
Showing
5 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef CRASHREPORT_H | ||
#define CRASHREPORT_H | ||
|
||
#include <QString> | ||
#include "scopy-core_export.h" | ||
|
||
namespace scopy | ||
{ | ||
class SCOPY_CORE_EXPORT CrashReport | ||
{ | ||
public: | ||
static void initSignalHandler(); | ||
private: | ||
static void signalHandler(int); | ||
static QString tmpFilePath_; | ||
}; | ||
} | ||
|
||
#endif // CRASHREPORT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "crashreport.h" | ||
#include <fstream> | ||
#include <signal.h> | ||
#include <stdlib.h> | ||
#include <QDebug> | ||
#include <QDateTime> | ||
#include <QDir> | ||
#include <QFileInfo> | ||
#include <common/scopyconfig.h> | ||
#include "logging_categories.h" | ||
|
||
using namespace scopy; | ||
|
||
QString CrashReport::tmpFilePath_; | ||
|
||
void CrashReport::signalHandler(int) | ||
{ | ||
::signal(SIGSEGV, SIG_DFL); | ||
::signal(SIGABRT, SIG_DFL); | ||
qSetMessagePattern( | ||
"[ " | ||
#ifdef QCRITICAL_BACKTRACE_STR | ||
QCRITICAL_BACKTRACE_STR " " | ||
#endif | ||
#ifdef QDEBUG_LOG_TIME | ||
QDEBUG_LOG_TIME_STR | ||
#endif | ||
" ] " | ||
" - " | ||
"%{message}" | ||
); | ||
|
||
qCritical("Scopy finished with error\n"); | ||
exit(EXIT_SUCCESS); | ||
} | ||
|
||
void CrashReport::initSignalHandler() | ||
{ | ||
tmpFilePath_ = scopy::config::tempLogFilePath(); | ||
QString qd = scopy::config::settingsFolderPath(); | ||
|
||
QFileInfo previousLog(tmpFilePath_); | ||
|
||
if (previousLog.exists()) { | ||
qInfo() << "Found existing crash stack trace"; | ||
QString dumpDateAndTime = previousLog.lastModified().toString(Qt::ISODate).replace("T","--").replace(":","-"); | ||
QString currentLog = QDir::cleanPath(qd + "/" + "ScopyCrashDump--" + dumpDateAndTime + ".log"); | ||
int renamed = QFile::rename(previousLog.filePath(), currentLog); | ||
if (renamed) { | ||
qInfo() << "Successfully renamed crash log to: " << currentLog; | ||
} | ||
QFile::remove(tmpFilePath_); | ||
} | ||
|
||
signal(SIGILL, &signalHandler); | ||
signal(SIGSEGV, &signalHandler); | ||
signal(SIGABRT, &signalHandler); | ||
signal(SIGFPE, &signalHandler); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters