Use binary path in args to find crashpad handler

This commit is contained in:
Clement 2018-07-05 12:05:48 -07:00
parent 3f975cfa84
commit b8f821a6a6
5 changed files with 25 additions and 21 deletions

View file

@ -14,8 +14,7 @@
#include <string> #include <string>
bool startCrashHandler(); bool startCrashHandler(std::string appPath);
void setCrashAnnotation(std::string name, std::string value); void setCrashAnnotation(std::string name, std::string value);
#endif // hifi_CrashHandler_h
#endif

View file

@ -9,10 +9,10 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "CrashHandler.h"
#if HAS_BREAKPAD #if HAS_BREAKPAD
#include "CrashHandler.h"
#include <mutex> #include <mutex>
#include <client/linux/handler/exception_handler.h> #include <client/linux/handler/exception_handler.h>
@ -55,7 +55,7 @@ void flushAnnotations() {
settings.sync(); settings.sync();
} }
bool startCrashHandler() { bool startCrashHandler(std::string appPath) {
annotations["version"] = BuildInfo::VERSION; annotations["version"] = BuildInfo::VERSION;
annotations["build_number"] = BuildInfo::BUILD_NUMBER; annotations["build_number"] = BuildInfo::BUILD_NUMBER;
annotations["build_type"] = BuildInfo::BUILD_TYPE_STRING; annotations["build_type"] = BuildInfo::BUILD_TYPE_STRING;

View file

@ -9,21 +9,18 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#if HAS_CRASHPAD
#include "CrashHandler.h" #include "CrashHandler.h"
#include <assert.h> #include <assert.h>
#include <QDebug>
#if HAS_CRASHPAD
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <QStandardPaths> #include <QDebug>
#include <QDir> #include <QDir>
#include <QStandardPaths>
#include <Windows.h>
#include <client/crashpad_client.h> #include <client/crashpad_client.h>
#include <client/crash_report_database.h> #include <client/crash_report_database.h>
@ -38,12 +35,13 @@ using namespace crashpad;
static const std::string BACKTRACE_URL { CMAKE_BACKTRACE_URL }; static const std::string BACKTRACE_URL { CMAKE_BACKTRACE_URL };
static const std::string BACKTRACE_TOKEN { CMAKE_BACKTRACE_TOKEN }; static const std::string BACKTRACE_TOKEN { CMAKE_BACKTRACE_TOKEN };
extern QString qAppFileName();
CrashpadClient* client { nullptr }; CrashpadClient* client { nullptr };
std::mutex annotationMutex; std::mutex annotationMutex;
crashpad::SimpleStringDictionary* crashpadAnnotations { nullptr }; crashpad::SimpleStringDictionary* crashpadAnnotations { nullptr };
#ifdef Q_OS_WIN
#include <Windows.h>
LONG WINAPI vectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo) { LONG WINAPI vectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo) {
if (!client) { if (!client) {
return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_CONTINUE_SEARCH;
@ -56,8 +54,9 @@ LONG WINAPI vectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo) {
return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_CONTINUE_SEARCH;
} }
#endif
bool startCrashHandler() { bool startCrashHandler(std::string appPath) {
if (BACKTRACE_URL.empty() || BACKTRACE_TOKEN.empty()) { if (BACKTRACE_URL.empty() || BACKTRACE_TOKEN.empty()) {
return false; return false;
} }
@ -81,8 +80,13 @@ bool startCrashHandler() {
QDir(crashpadDbDir).mkpath(crashpadDbName); // Make sure the directory exists QDir(crashpadDbDir).mkpath(crashpadDbName); // Make sure the directory exists
const auto crashpadDbPath = crashpadDbDir.toStdString() + "/" + crashpadDbName; const auto crashpadDbPath = crashpadDbDir.toStdString() + "/" + crashpadDbName;
static const QString CRASHPAD_HANDLER_NAME { "crashpad_handler" };
// Locate Crashpad handler // Locate Crashpad handler
const std::string CRASHPAD_HANDLER_PATH = QFileInfo(qAppFileName()).absolutePath().toStdString() + "/crashpad_handler.exe"; const QFileInfo interfaceBinary { QString::fromStdString(appPath) };
const QDir interfaceDir = interfaceBinary.dir();
assert(interfaceDir.exists(CRASHPAD_HANDLER_NAME));
const std::string CRASHPAD_HANDLER_PATH = interfaceDir.filePath(CRASHPAD_HANDLER_NAME).toStdString();
qDebug() << "CRASHPAD_HANDLER_PATH:" << CRASHPAD_HANDLER_PATH.c_str();
// Setup different file paths // Setup different file paths
base::FilePath::StringType dbPath; base::FilePath::StringType dbPath;

View file

@ -9,14 +9,15 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#if !defined(HAS_CRASHPAD) && !defined(HAS_BREAKPAD)
#include "CrashHandler.h" #include "CrashHandler.h"
#include <assert.h> #include <assert.h>
#include <QDebug> #include <QDebug>
#if !defined(HAS_CRASHPAD) && !defined(HAS_BREAKPAD) bool startCrashHandler(std::string appPath) {
bool startCrashHandler() {
qDebug() << "No crash handler available."; qDebug() << "No crash handler available.";
return false; return false;
} }

View file

@ -91,7 +91,7 @@ int main(int argc, const char* argv[]) {
qDebug() << "UserActivityLogger is enabled:" << ual.isEnabled(); qDebug() << "UserActivityLogger is enabled:" << ual.isEnabled();
if (ual.isEnabled()) { if (ual.isEnabled()) {
auto crashHandlerStarted = startCrashHandler(); auto crashHandlerStarted = startCrashHandler(argv[0]);
qDebug() << "Crash handler started:" << crashHandlerStarted; qDebug() << "Crash handler started:" << crashHandlerStarted;
} }