mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
e377c30192
* feat: crashpad on windows * feat: inline it * feat: more crashpad * chore: remove qBreakpad * fix: add mention to crashpad * refactor: version string * feat: add crashpad module * refactor: build crashpad from source * fix: minor adjustments * chore: add changelog entry * fix: formatting and include * fix: format * build: use flags similar to release profile * ci: build with crashpad on windows * ci: recurse submodules * ci: always include crashpad * fix: try 7z for some reason zstd just doesn't run * fix: wrong path for symbols * fix: copy pls don't build * ci: use new cache key * fix: missing pragma * ci: add workflow without crashpad * docs: elevate changelog entry * fix: add link to cmake issue * fix: windows include issue Someone (crashpad) includes Windows.h before winsock2.h * fix: working directory * fix: another working directory
95 lines
2.6 KiB
C++
95 lines
2.6 KiB
C++
#ifdef CHATTERINO_WITH_CRASHPAD
|
|
# include "providers/Crashpad.hpp"
|
|
|
|
# include "common/QLogging.hpp"
|
|
# include "singletons/Paths.hpp"
|
|
|
|
# include <QApplication>
|
|
# include <QDir>
|
|
# include <QString>
|
|
|
|
# include <memory>
|
|
# include <string>
|
|
|
|
namespace {
|
|
|
|
/// The name of the crashpad handler executable.
|
|
/// This varies across platforms
|
|
# if defined(Q_OS_UNIX)
|
|
const QString CRASHPAD_EXECUTABLE_NAME = QStringLiteral("crashpad_handler");
|
|
# elif defined(Q_OS_WINDOWS)
|
|
const QString CRASHPAD_EXECUTABLE_NAME = QStringLiteral("crashpad_handler.exe");
|
|
# else
|
|
# error Unsupported platform
|
|
# endif
|
|
|
|
/// Converts a QString into the platform string representation.
|
|
# if defined(Q_OS_UNIX)
|
|
std::string nativeString(const QString &s)
|
|
{
|
|
return s.toStdString();
|
|
}
|
|
# elif defined(Q_OS_WINDOWS)
|
|
std::wstring nativeString(const QString &s)
|
|
{
|
|
return s.toStdWString();
|
|
}
|
|
# else
|
|
# error Unsupported platform
|
|
# endif
|
|
|
|
} // namespace
|
|
|
|
namespace chatterino {
|
|
|
|
std::unique_ptr<crashpad::CrashpadClient> installCrashHandler()
|
|
{
|
|
// Currently, the following directory layout is assumed:
|
|
// [applicationDirPath]
|
|
// │
|
|
// ├─chatterino
|
|
// │
|
|
// ╰─[crashpad]
|
|
// │
|
|
// ╰─crashpad_handler
|
|
// TODO: The location of the binary might vary across platforms
|
|
auto crashpadBinDir = QDir(QApplication::applicationDirPath());
|
|
|
|
if (!crashpadBinDir.cd("crashpad"))
|
|
{
|
|
qCDebug(chatterinoApp) << "Cannot find crashpad directory";
|
|
return nullptr;
|
|
}
|
|
if (!crashpadBinDir.exists(CRASHPAD_EXECUTABLE_NAME))
|
|
{
|
|
qCDebug(chatterinoApp) << "Cannot find crashpad handler executable";
|
|
return nullptr;
|
|
}
|
|
|
|
const auto handlerPath = base::FilePath(nativeString(
|
|
crashpadBinDir.absoluteFilePath(CRASHPAD_EXECUTABLE_NAME)));
|
|
|
|
// Argument passed in --database
|
|
// > Crash reports are written to this database, and if uploads are enabled,
|
|
// uploaded from this database to a crash report collection server.
|
|
const auto databaseDir =
|
|
base::FilePath(nativeString(getPaths()->crashdumpDirectory));
|
|
|
|
auto client = std::make_unique<crashpad::CrashpadClient>();
|
|
|
|
// See https://chromium.googlesource.com/crashpad/crashpad/+/HEAD/handler/crashpad_handler.md
|
|
// for documentation on available options.
|
|
if (!client->StartHandler(handlerPath, databaseDir, {}, {}, {}, {}, true,
|
|
false))
|
|
{
|
|
qCDebug(chatterinoApp) << "Failed to start crashpad handler";
|
|
return nullptr;
|
|
}
|
|
|
|
qCDebug(chatterinoApp) << "Started crashpad handler";
|
|
return client;
|
|
}
|
|
|
|
} // namespace chatterino
|
|
|
|
#endif
|