aboutsummaryrefslogtreecommitdiff
path: root/src/crashhandler.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-01-03 21:58:20 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2020-01-03 23:28:39 +0200
commit0642a0910ca0fb8e392636254684b91637a7b542 (patch)
tree4fa4328fcdf205b80103d5255ea1570439b46cce /src/crashhandler.cpp
parentMerge some QoL improvements from staging branch (diff)
downloadsmolbote-0642a0910ca0fb8e392636254684b91637a7b542.tar.xz
PKGBUILD: add install stage for debug symbols
- make toggling breakpad work properly
Diffstat (limited to 'src/crashhandler.cpp')
-rw-r--r--src/crashhandler.cpp44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/crashhandler.cpp b/src/crashhandler.cpp
index 194d04b..0c2fec7 100644
--- a/src/crashhandler.cpp
+++ b/src/crashhandler.cpp
@@ -8,31 +8,49 @@
#include "crashhandler.h"
#include "version.h"
-
-#ifdef BREAKPAD
-
-//#ifdef Q_OS_LINUX
+#include <QByteArray>
+#include <client/linux/handler/exception_handler.h>
#include <unistd.h>
-//#endif // Q_OS_LINUX
-
-bool CrashHandler::dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded)
+// bool filter_callback (void*)
+// --> true: continue processing and write a minidump
+static bool minidumpCb(const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded)
{
printf("Dump path: %s\n", descriptor.path());
- auto *ctx = static_cast<BreakpadContext *>(context);
+ auto *ctx = static_cast<CrashHandler::Context *>(context);
if(ctx != nullptr) {
- if(ctx->handler != nullptr) {
+ if(!ctx->handler.empty()) {
// fork and run 'handler master:commit path.dmp'
pid_t pid = fork();
if(pid == 0) {
- char buffer[256];
- snprintf(buffer, 256, "%s %s %s", ctx->handler, poi_Version, descriptor.path());
- execlp("/bin/sh", "/bin/sh", "-c", buffer, (char *)nullptr);
+ // pathname program argument ... nullptr
+ execlp(ctx->handler.c_str(),
+ ctx->handler.c_str(), "--crashd", ctx->dumppath.c_str(), "-c", descriptor.path(), poi_Version,
+ (char *)nullptr);
}
}
}
return succeeded;
}
-#endif
+
+bool CrashHandler::install_handler(CrashHandler::Context &ctx)
+{
+ if(ctx.dumppath.empty())
+ return false;
+
+ // Disable Chromium's crash handler so breakpad can capture crashes instead.
+ // This has to be done before QtWebEngine gets initialized.
+ const auto chromiumFlags = qgetenv("QTWEBENGINE_CHROMIUM_FLAGS");
+ if(!chromiumFlags.contains("disable-in-process-stack-traces")) {
+ qputenv("QTWEBENGINE_CHROMIUM_FLAGS", chromiumFlags + " --disable-in-process-stack-traces");
+ }
+
+ google_breakpad::MinidumpDescriptor descriptor(ctx.dumppath.c_str());
+
+ // minidump descriptor, filter callback, minidump callback, callback_context, install handler, server_fd
+ auto *eh = new google_breakpad::ExceptionHandler(descriptor, nullptr, minidumpCb, &ctx, true, -1);
+
+ return true;
+}