2

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.

apalomer
  • 1,895
  • 14
  • 36
  • For Windows: [Collecting User-Mode Dumps](https://learn.microsoft.com/en-us/windows/win32/wer/collecting-user-mode-dumps). – IInspectable Feb 22 '20 at 01:08

1 Answers1

5

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.

Hubert Gruniaux
  • 124
  • 2
  • 11
  • I successfully integrated crashpad. However, I cannot configure the upload server. Is there any tutorial on how to do that? – apalomer Mar 03 '20 at 18:08
  • 1
    If you want to write your own HTTP crash collect server, you can see here for an example: https://github.com/chromiumembedded/cef/blob/master/tools/crash_server.py (in Python). You could also use the Socorro system from Mozilla which permits crash collect and analyse and use one of the non-free services mentionned in the answer. – Hubert Gruniaux Mar 03 '20 at 18:24
  • 1
    Crashpad uploads the crash report with a HTTP POST and the content type 'multipart/form-data'. The upload is exactly like a file upload from a HTML field. – Hubert Gruniaux Mar 03 '20 at 18:26
  • What can I do to read the crash reports in Linux? I've [posted a question](https://stackoverflow.com/questions/60394317/google-crashpad-on-a-cross-compilation-platform-application-cannot-read-dmp-fil) about this that maybe you can have a look at. – apalomer Mar 04 '20 at 09:29