From e3c605a796b6f09c6b38a206fd110992ff5d1e4c Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 28 Sep 2018 16:15:01 +0200 Subject: breakpad: try to write session on crash --- src/main.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index f3ddeb9..e7fdcee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,22 +22,34 @@ #endif #ifdef BreakpadEnabled +#ifdef Q_OS_LINUX #include +// bool filter_callback (void*) +// --> true: continue processing and write a minidump + static bool dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded) { printf("Dump path: %s\n", descriptor.path()); + + if(auto *app = static_cast(context); app != nullptr) { + auto session = app->session(); + QJsonDocument doc(session); + QFile sessionFile(QString("%1.json").arg(QString::fromStdString(descriptor.path()))); + if(sessionFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + sessionFile.write(qUtf8Printable(doc.toJson())); + sessionFile.flush(); + sessionFile.close(); + } + } + return succeeded; } +#endif // Q_OS_LINUX #endif int main(int argc, char **argv) { -#ifdef BreakpadEnabled - google_breakpad::MinidumpDescriptor descriptor("/tmp"); - google_breakpad::ExceptionHandler eh(descriptor, NULL, dumpCallback, NULL, true, -1); -#endif - // a beautiful hack to be able to write to stdout on Windows #ifdef _WIN32 if(AttachConsole(ATTACH_PARENT_PROCESS)) { @@ -116,6 +128,13 @@ int main(int argc, char **argv) // set this, otherwise the webview becomes black when using a stylesheet app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); +#ifdef BreakpadEnabled + google_breakpad::MinidumpDescriptor descriptor("/tmp"); + + // minidump descriptor, filter callback, minidump callback, callback_context, install handler, server_fd + google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, &app, true, -1); +#endif + // translator if(config->exists("browser.locale")) { auto *translator = new QTranslator(&app); -- cgit v1.2.1