KCrash
kcrash.cpp
114static std::unique_ptr<char[]> s_appFilePath; // this is the actual QCoreApplication::applicationFilePath
116static std::unique_ptr<char[]> s_appPath; // the binary dir path (may be altered by the application)
150 return QString::fromUtf8(reinterpret_cast<const char *>(context.functions()->glGetString(GL_RENDERER)));
158 qCWarning(LOG_KCRASH) << "Failed to read /proc/sys/kernel/random/boot_id" << file.errorString();
172 static QStringList list = QFile::decodeName(qgetenv("LIBEXEC_PATH")).split(QLatin1Char(':'), Qt::SkipEmptyParts) // env var is used first
175 QLibraryInfo::path(QLibraryInfo::LibraryExecutablesPath), // look where libexec path is (can be set in qt.conf)
194 // NB: The daemon being currently running must not be a condition here. If something crashes during logout
197 const bool drkonqiCoredumpHelper = !QStandardPaths::findExecutable(QStringLiteral("drkonqi-coredump-processor"), libexecPaths()).isEmpty();
198 return s_coreConfig.isCoredumpd() && drkonqiCoredumpHelper && !qEnvironmentVariableIsSet("KCRASH_NO_METADATA");
211 if (qEnvironmentVariableIsSet("KCRASH_AUTO_RESTARTED") || qEnvironmentVariableIntValue("RUNNING_UNDER_RR") == 1
217 // Default to core dumping whenever a process is set. When not or when explicitly opting into just in time debugging
218 // we enable drkonqi. This causes the signal handler to directly fork drkonqi opening us to race conditions.
219 // NOTE: depending on the specific signal other threads are running while the signal handler runs and may trip over
221 if (enableDrKonqi && (!s_coreConfig.isProcess() || qEnvironmentVariableIntValue("KCRASH_JIT_DRKONQI") == 1)) {
224 // Don't qDebug here, it loads qtlogging.ini very early which prevents unittests from doing QStandardPaths::setTestModeEnabled(true) in initTestCase()
231 s_appFilePath.reset(qstrdup(qPrintable(path))); // This intentionally cannot be changed by the application!
241 // We do not actively clean up metadata via KCrash but some other service. This potentially means we litter
244 const QString metadataDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/kcrash-metadata");
253 // Always enable the default handler. We cannot create the metadata ahead of time since we do not know
255 // TODO: kf6 maybe change the way init works and have the users run it when their done with kaboutdata etc.?
256 // the problem with delayed writing is that our crash handler (or any crash handler really) introduces a delay
257 // in dumping and this in turn increases the risk of another stepping into a puddle (SEGV only runs on the
334 if (args.isEmpty()) { // edge case: tst_QX11Info::startupId does QApplication app(argc, nullptr)...
469 startProcess(s_autoRestartCommandLine.argc, const_cast<const char **>(s_autoRestartCommandLine.argv), false);
478 // NB: all metadata writing ought to happen before closing FDs to reduce synchronization problems with dbus.
480 // WARNING: do not forget to increase Metadata::argv's size when adding more potential arguments!
483 // The ini is required to be scoped here, as opposed to the conditional scope, so its lifetime is the same as
491 // Add the canonical exe path so the coredump daemon has more data points to map metadata to journald entry.
497 if (auto optionalExceptionMetadata = KCrash::exceptionMetadata(); optionalExceptionMetadata.has_value()) {
518 if (strcmp(platformName.constData(), "wayland-org.kde.kwin.qpa") == 0) { // redirect kwin's internal QPA to wayland proper
591 fprintf(stderr, "KCrash: Application '%s' crashing... crashRecursionCounter = %d\n", s_appName ? s_appName.get() : "<unknown>", crashRecursionCounter);
603 // This tries to prevent problems where applications fail to release resources that drkonqi might need.
604 // Specifically this was introduced to ensure that an application that had grabbed the X11 cursor would
605 // forcefully have it removed upon crash to ensure it is ungrabbed by the time drkonqi makes an appearance.
606 // This is also the point in time when, for example, dbus services are lost. Closing the socket indicates
607 // to dbus-daemon that the process has disappeared and it will forcefully reclaim the registered service names.
609 // Once we close our socket we lose potential dbus names and if we were running as a systemd service anchored to a name,
610 // the daemon may decide to jump at us with a TERM signal. We'll want to have finished the metadata by now and
615 else if (auto display = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display()) {
664 {sizeof(STARTUPINFO), 0, 0, 0, (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
666 bool success = CreateProcess(0, (wchar_t *)cmdLine.utf16(), NULL, NULL, false, CREATE_UNICODE_ENVIRONMENT, NULL, NULL, &startupInfo, &procInfo);
683 hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(CONTEXT), TEXT("Local\\KCrashShared"));
const char * internalBugAddress() const
const char * internalProductName() const
const char * internalVersion() const
const char * internalProgramName() const
KCRASH_EXPORT void setCrashHandler(HandlerType handler=defaultCrashHandler)
Install a function to be called when a crash occurs.
Definition kcrash.cpp:374
KCRASH_EXPORT void setErrorMessage(const QString &message)
Allows providing information to be included in the bug report.
Definition kcrash.cpp:772
KCRASH_EXPORT HandlerType crashHandler()
Returns the installed crash handler.
Definition kcrash.cpp:427
KCRASH_EXPORT void defaultCrashHandler(int signal)
The default crash handler.
Definition kcrash.cpp:450
KCRASH_EXPORT void setDrKonqiEnabled(bool enabled)
Enables or disables launching DrKonqi from the crash handler.
Definition kcrash.cpp:346
KCRASH_EXPORT void setFlags(KCrash::CrashFlags flags)
Set options to determine how the default crash handler should behave.
Definition kcrash.cpp:308
KCRASH_EXPORT HandlerType emergencySaveFunction()
Returns the currently set emergency save function.
Definition kcrash.cpp:278
KCRASH_EXPORT bool isDrKonqiEnabled()
Returns true if DrKonqi is set to be launched from the crash handler or false otherwise.
Definition kcrash.cpp:369
@ AutoRestart
autorestart this application. Only sensible for KUniqueApplications.
Definition kcrash.h:112
KCRASH_EXPORT void setEmergencySaveFunction(HandlerType saveFunction=nullptr)
Installs a function which should try to save the application's data.
Definition kcrash.cpp:265
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const QList< QKeySequence > & close()
const QList< QKeySequence > & end()
const char * constData() const const
bool isEmpty() const const
QString applicationDirPath()
QString applicationFilePath()
qint64 applicationPid()
QStringList arguments()
QCoreApplication * instance()
QString decodeName(const QByteArray &localFileName)
QByteArray encodeName(const QString &fileName)
platformName
ReadOnly
LibraryExecutablesPath
QString path(LibraryPath p)
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
int * display() const const
void deleteLater()
virtual bool event(QEvent *e)
void killTimer(int id)
int startTimer(int interval, Qt::TimerType timerType)
void create()
bool create()
void doneCurrent()
QOpenGLFunctions * functions() const const
bool makeCurrent(QSurface *surface)
const GLubyte * glGetString(GLenum name)
GenericCacheLocation
QString findExecutable(const QString &executableName, const QStringList &paths)
QString writableLocation(StandardLocation type)
QString & append(QChar ch)
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
QString left(qsizetype n) const const
QString mid(qsizetype position, qsizetype n) const const
QString number(double n, char format, int precision)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QByteArray toUtf8() const const
const ushort * utf16() const const
typedef HANDLE
SkipEmptyParts
void sleep(std::chrono::nanoseconds nsecs)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.