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/browser.h | 6 +++--- src/main.cpp | 29 ++++++++++++++++++++++++----- src/mainwindow/mainwindow.cpp | 10 ++++++++++ src/session.cpp | 16 +++++++++++++++- src/session.h | 7 ++++++- 5 files changed, 58 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/browser.h b/src/browser.h index c82afa0..694a3a7 100644 --- a/src/browser.h +++ b/src/browser.h @@ -15,6 +15,7 @@ #include #include #include +#include "session.h" QVector loadPlugins(const QString &location); @@ -48,9 +49,8 @@ public: void setup(const QString &defaultProfile); - std::shared_ptr bookmarks() - { - return m_bookmarks; + QJsonObject session() const { + return JsonSession::session(m_windows); } public slots: 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); diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 77b8ad3..cc67b3d 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -89,6 +89,16 @@ MainWindow::MainWindow(const std::unique_ptr &config, QWidget *pa } show(); +#ifdef QT_DEBUG + { + auto *debugMenu = ui->menubar->addMenu(tr("Debug")); + + debugMenu->addAction(tr("Crash"), []() { + delete reinterpret_cast(0xFEE1DEAD); + }); + }; +#endif + // connect smolbote menu { connect(ui->actionNewSubwindow, &QAction::triggered, this, [this, &config]() { diff --git a/src/session.cpp b/src/session.cpp index e1f600a..9c69088 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -14,11 +14,25 @@ #include "webengine/webview.h" #include + +QJsonObject JsonSession::session(QVector windows) +{ + QJsonObject obj; + + QJsonArray windowsArray; + for(const MainWindow *window : windows) { + windowsArray.append(Session::toJsonObject(window)); + } + obj.insert("windows", windowsArray); + + return obj; +} + Session::Session(QObject *parent) : QObject(parent) { } -QJsonObject Session::toJsonObject(MainWindow *window) +QJsonObject Session::toJsonObject(const MainWindow *window) { QJsonObject session; diff --git a/src/session.h b/src/session.h index 4d5d59b..c81b2bf 100644 --- a/src/session.h +++ b/src/session.h @@ -13,13 +13,18 @@ #include class MainWindow; + +namespace JsonSession { +QJsonObject session(QVector windows); +} + class Session : public QObject { Q_OBJECT public: explicit Session(QObject *parent = nullptr); - static QJsonObject toJsonObject(MainWindow *window); + static QJsonObject toJsonObject(const MainWindow *window); static QJsonObject toJsonObject(const QString &profile, const QStringList &urls); signals: -- cgit v1.2.1