Add: use breakpad to create crash.dmp on MacOS / Linux too (#11202)

Normally only the Windows platform could create a crash.dmp, making
analysing crash-reports from MacOS / Linux rather tricky.
This commit is contained in:
Patric Stout
2023-08-20 17:16:08 +02:00
committed by GitHub
parent 8f6df242c4
commit f120d2beb8
13 changed files with 107 additions and 59 deletions

View File

@@ -9,6 +9,7 @@
#include "../../stdafx.h"
#include "../../crashlog.h"
#include "../../fileio_func.h"
#include "../../string_func.h"
#include "../../gamelog.h"
#include "../../saveload/saveload.h"
@@ -20,6 +21,10 @@
#include <dlfcn.h>
#include <cxxabi.h>
#ifdef WITH_UNOFFICIAL_BREAKPAD
# include <client/mac/handler/exception_handler.h>
#endif
#include "../../safeguards.h"
@@ -139,6 +144,22 @@ class CrashLogOSX : public CrashLog {
fmt::format_to(output_iterator, "\n");
}
#ifdef WITH_UNOFFICIAL_BREAKPAD
static bool MinidumpCallback(const char* dump_dir, const char* minidump_id, void* context, bool succeeded)
{
CrashLogOSX *crashlog = reinterpret_cast<CrashLogOSX *>(context);
crashlog->crashdump_filename = crashlog->CreateFileName(".dmp");
std::rename(fmt::format("{}/{}.dmp", dump_dir, minidump_id).c_str(), crashlog->crashdump_filename.c_str());
return succeeded;
}
int WriteCrashDump() override
{
return google_breakpad::ExceptionHandler::WriteMinidump(_personal_dir, MinidumpCallback, this) ? 1 : -1;
}
#endif
public:
/**
* A crash log is always generated by signal.
@@ -155,8 +176,8 @@ public:
std::string message = fmt::format(
"Please send the generated crash information and the last (auto)save to the developers. "
"This will greatly help debugging. The correct place to do this is https://github.com/OpenTTD/OpenTTD/issues.\n\n"
"Generated file(s):\n{}\n{}\n{}",
this->crashlog_filename, this->savegame_filename, this->screenshot_filename);
"Generated file(s):\n{}\n{}\n{}\n{}",
this->crashlog_filename, this->crashdump_filename, this->savegame_filename, this->screenshot_filename);
ShowMacDialog(crash_title, message.c_str(), "Quit");
}