apalomer
apalomer

Reputation: 1935

Deploying application to client with debug/crash reports

I have created a Qt application that can be compiled both in Linux and Windows. Moreover, using Qt installer framework I have created installers for both OS. However, my application still has some bugs. I know how to debug them using a debugger on my computer, but when somebody installs it using the installers that I created, there is no way for me to track the segmentation faults that might happen in the end-user computer.

There are some programs that do some kind of crash-log so when they crash a log file can be sent to the developer to try to find out the problem. I could achieve something like that by adding a logging system in my application that logs (print to a file) what the user is doing at all time in my application. However, this is a pretty complicated way and involves a lot of writting in my end. To me, it looks like there should be some kind of automatic tool to "run your programs in debug mode" (i.e. create a crash report) in the computers where your application is installed. Does anybody know of a way of creating crash reports on computers where the application that you developed is only installed but not compiled? I assume I would have to compile my project in RelWithDebInfo to achieve something in this field, which is not a problem.

Upvotes: 2

Views: 1149

Answers (1)

Hubert Gruniaux
Hubert Gruniaux

Reputation: 194

For automatic crash report on the major platforms (Windows, Mac OS, Linux), you could use the open source libraries Google Breakpad (used in Firefox for example), or the more modern Google Crashpad (used in Chromium for example). These two C++ libraries will generate a MiniDump file on crash which can be send to a distant server if you want.

For example, here a basic Qt application integrating Google Crashpad:

#include <QtWidgets/qapplication.h>
#include <QtWidgets/qmainwindow.h>

#include <client/crashpad_client.h>

void initializeCrashpad()
{
    const auto dataDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
    const auto db = dataDir + "/metrics/db";
    const auto metrics = dataDir + "/crash/metrics";
    const auto url = "https://my-http-server.com/"

    QDir().mkpath(db);
    QDir().mkpath(metrics);

    crashpad::CrashpadClient::StartHandler(
        "crashpad_handler.exe", // Relative path to a Crashpad handler executable
        db.toStdWString(), // Directory to Crashpad database 
        metrics.toStdWString(), // Directory where metrics files can be stored
        url.toStdString(), // URL of the HTTP upload server
        {}, // Annonations to include in the crash report
        true, // The program will be restarted if it crash
        true);
}

int main(int argc, char* argv[])
{
    initializeCrashpad();

    QApplication app(argc, argv);
    QMainWindow window;
    window.show();
    return app.exec();
}

Then you will need to ship your application with crash_handler.exe (or whatever you have called it), or implement this little program using crashpad::HandlerMain(). For more information search on Google, or read the Crashpad documentation.

Otherwise, you can use the free/non-free service Backtrace.io or Sentry which provides tutorials to integrate Crashpad into your application, and provides also an upload server, with many tools.

Upvotes: 5

Related Questions