Add Crashpad Support on Windows (#4351)
* 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
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
#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
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef CHATTERINO_WITH_CRASHPAD
|
||||
# include <client/crashpad_client.h>
|
||||
|
||||
# include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
std::unique_ptr<crashpad::CrashpadClient> installCrashHandler();
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
#endif
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "common/QLogging.hpp"
|
||||
|
||||
#include <QNetworkProxy>
|
||||
#include <websocketpp/connection.hpp>
|
||||
#include <websocketpp/error.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -25,9 +25,7 @@ public:
|
||||
*/
|
||||
static void applyFromEnv(const Env &env);
|
||||
|
||||
template <class C>
|
||||
static void applyToWebSocket(
|
||||
const std::shared_ptr<websocketpp::connection<C>> &connection)
|
||||
static void applyToWebSocket(const auto &connection)
|
||||
{
|
||||
const auto applicationProxy = QNetworkProxy::applicationProxy();
|
||||
if (applicationProxy.type() != QNetworkProxy::HttpProxy)
|
||||
|
||||
Reference in New Issue
Block a user