Merge pull request #13553 from Atlante45/feat/crashpad-mac

Add Crashpad to Mac
This commit is contained in:
John Conklin II 2018-07-11 19:16:24 -07:00 committed by GitHub
commit de33ca512f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 110 additions and 42 deletions

View file

@ -66,6 +66,13 @@ elseif ((NOT MSVC12) AND (NOT MSVC14))
endif() endif()
endif () endif ()
if (CMAKE_GENERATOR STREQUAL "Xcode")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS[variant=Release] "YES")
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT[variant=Release] "dwarf-with-dsym")
set(CMAKE_XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING[variant=Release] "YES")
endif()
if (APPLE) if (APPLE)
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11") set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")

View file

@ -16,19 +16,46 @@ if (WIN32)
ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR)
set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include CACHE PATH "List of Crashpad include directories") set(BIN_RELEASE_PATH "${SOURCE_DIR}/out/Release_x64")
set(BIN_EXT ".exe")
set(LIB_RELEASE_PATH "${SOURCE_DIR}/out/Release_x64/lib_MD")
set(LIB_DEBUG_PATH "${SOURCE_DIR}/out/Debug_x64/lib_MD")
set(LIB_PREFIX "")
set(LIB_EXT "lib") set(LIB_EXT "lib")
elseif (APPLE)
ExternalProject_Add(
${EXTERNAL_NAME}
URL http://public.highfidelity.com/dependencies/crashpad_mac_070318.zip
URL_MD5 ba1501dc163591ac2d1be74946967e2a
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD 1
)
set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${SOURCE_DIR}/out/Release_x64/lib_MD/${LIB_PREFIX}crashpad_client.${LIB_EXT} CACHE FILEPATH "Path to Crashpad release library") ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR)
set(${EXTERNAL_NAME_UPPER}_BASE_LIBRARY_RELEASE ${SOURCE_DIR}/out/Release_x64/lib_MD/${LIB_PREFIX}base.${LIB_EXT} CACHE FILEPATH "Path to Crashpad base release library")
set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY_RELEASE ${SOURCE_DIR}/out/Release_x64/lib_MD/${LIB_PREFIX}crashpad_util.${LIB_EXT} CACHE FILEPATH "Path to Crashpad util release library")
set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${SOURCE_DIR}/out/Debug_x64/lib_MD/${LIB_PREFIX}crashpad_client.${LIB_EXT} CACHE FILEPATH "Path to Crashpad debug library") set(BIN_RELEASE_PATH "${SOURCE_DIR}/out/Release")
set(${EXTERNAL_NAME_UPPER}_BASE_LIBRARY_DEBUG ${SOURCE_DIR}/out/Debug_x64/lib_MD/${LIB_PREFIX}base.${LIB_EXT} CACHE FILEPATH "Path to Crashpad base debug library") set(BIN_EXT "")
set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY_DEBUG ${SOURCE_DIR}/out/Debug_x64/lib_MD/${LIB_PREFIX}crashpad_util.${LIB_EXT} CACHE FILEPATH "Path to Crashpad util debug library") set(LIB_RELEASE_PATH "${SOURCE_DIR}/out/Release/lib")
set(LIB_DEBUG_PATH "${SOURCE_DIR}/out/Debug/lib")
set(LIB_PREFIX "lib")
set(LIB_EXT "a")
endif ()
set(CRASHPAD_HANDLER_EXE_PATH ${SOURCE_DIR}/out/Release_x64/crashpad_handler.exe CACHE FILEPATH "Path to the Crashpad handler executable") if (WIN32 OR APPLE)
set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include CACHE PATH "List of Crashpad include directories")
set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${LIB_RELEASE_PATH}/${LIB_PREFIX}crashpad_client.${LIB_EXT} CACHE FILEPATH "Path to Crashpad release library")
set(${EXTERNAL_NAME_UPPER}_BASE_LIBRARY_RELEASE ${LIB_RELEASE_PATH}/${LIB_PREFIX}base.${LIB_EXT} CACHE FILEPATH "Path to Crashpad base release library")
set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY_RELEASE ${LIB_RELEASE_PATH}/${LIB_PREFIX}crashpad_util.${LIB_EXT} CACHE FILEPATH "Path to Crashpad util release library")
set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${LIB_DEBUG_PATH}/${LIB_PREFIX}crashpad_client.${LIB_EXT} CACHE FILEPATH "Path to Crashpad debug library")
set(${EXTERNAL_NAME_UPPER}_BASE_LIBRARY_DEBUG ${LIB_DEBUG_PATH}/${LIB_PREFIX}base.${LIB_EXT} CACHE FILEPATH "Path to Crashpad base debug library")
set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY_DEBUG ${LIB_DEBUG_PATH}/${LIB_PREFIX}crashpad_util.${LIB_EXT} CACHE FILEPATH "Path to Crashpad util debug library")
set(CRASHPAD_HANDLER_EXE_PATH ${BIN_RELEASE_PATH}/crashpad_handler${BIN_EXT} CACHE FILEPATH "Path to the Crashpad handler binary")
endif () endif ()
# Hide this external target (for ide users) # Hide this external target (for ide users)

View file

@ -23,7 +23,7 @@ macro(add_crashpad)
set(CMAKE_BACKTRACE_TOKEN $ENV{CMAKE_BACKTRACE_TOKEN}) set(CMAKE_BACKTRACE_TOKEN $ENV{CMAKE_BACKTRACE_TOKEN})
endif() endif()
if (WIN32 AND USE_CRASHPAD) if ((WIN32 OR APPLE) AND USE_CRASHPAD)
get_property(CRASHPAD_CHECKED GLOBAL PROPERTY CHECKED_FOR_CRASHPAD_ONCE) get_property(CRASHPAD_CHECKED GLOBAL PROPERTY CHECKED_FOR_CRASHPAD_ONCE)
if (NOT CRASHPAD_CHECKED) if (NOT CRASHPAD_CHECKED)
@ -42,6 +42,10 @@ macro(add_crashpad)
if (WIN32) if (WIN32)
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "/ignore:4099") set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "/ignore:4099")
elseif (APPLE)
find_library(Security Security)
target_link_libraries(${TARGET_NAME} ${Security})
target_link_libraries(${TARGET_NAME} "-lbsm")
endif() endif()
add_custom_command( add_custom_command(

View file

@ -1448,8 +1448,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
// add firstRun flag from settings to launch event // add firstRun flag from settings to launch event
Setting::Handle<bool> firstRun { Settings::firstRun, true }; Setting::Handle<bool> firstRun { Settings::firstRun, true };
QString machineFingerPrint = uuidStringWithoutCurlyBraces(FingerprintUtils::getMachineFingerprint());
auto& userActivityLogger = UserActivityLogger::getInstance(); auto& userActivityLogger = UserActivityLogger::getInstance();
if (userActivityLogger.isEnabled()) { if (userActivityLogger.isEnabled()) {
// sessionRunTime will be reset soon by loadSettings. Grab it now to get previous session value. // sessionRunTime will be reset soon by loadSettings. Grab it now to get previous session value.
@ -1501,13 +1499,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
properties["first_run"] = firstRun.get(); properties["first_run"] = firstRun.get();
// add the user's machine ID to the launch event // add the user's machine ID to the launch event
QString machineFingerPrint = uuidStringWithoutCurlyBraces(FingerprintUtils::getMachineFingerprint());
properties["machine_fingerprint"] = machineFingerPrint; properties["machine_fingerprint"] = machineFingerPrint;
userActivityLogger.logAction("launch", properties); userActivityLogger.logAction("launch", properties);
} }
setCrashAnnotation("machine_fingerprint", machineFingerPrint.toStdString());
_entityEditSender.setMyAvatar(myAvatar.get()); _entityEditSender.setMyAvatar(myAvatar.get());
// The entity octree will have to know about MyAvatar for the parentJointName import // The entity octree will have to know about MyAvatar for the parentJointName import

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>
@ -23,8 +23,10 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtAndroidExtras/QAndroidJniObject> #include <QtAndroidExtras/QAndroidJniObject>
#include <SettingHelpers.h>
#include <BuildInfo.h> #include <BuildInfo.h>
#include <FingerprintUtils.h>
#include <SettingHelpers.h>
#include <UUID.h>
google_breakpad::ExceptionHandler* gBreakpadHandler; google_breakpad::ExceptionHandler* gBreakpadHandler;
@ -55,11 +57,14 @@ 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;
auto machineFingerPrint = uuidStringWithoutCurlyBraces(FingerprintUtils::getMachineFingerprint());
annotations["machine_fingerprint"] = machineFingerPrint;
flushAnnotations(); flushAnnotations();
gBreakpadHandler = new google_breakpad::ExceptionHandler( gBreakpadHandler = new google_breakpad::ExceptionHandler(

View file

@ -9,21 +9,24 @@
// 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>
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++14-extensions"
#endif
#include <client/crashpad_client.h> #include <client/crashpad_client.h>
#include <client/crash_report_database.h> #include <client/crash_report_database.h>
@ -31,19 +34,32 @@
#include <client/annotation_list.h> #include <client/annotation_list.h>
#include <client/crashpad_info.h> #include <client/crashpad_info.h>
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#include <BuildInfo.h> #include <BuildInfo.h>
#include <FingerprintUtils.h>
#include <UUID.h>
using namespace crashpad; 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 };
#if defined(Q_OS_WIN)
static const QString CRASHPAD_HANDLER_NAME { "crashpad_handler.exe" };
#else
static const QString CRASHPAD_HANDLER_NAME { "crashpad_handler" };
#endif
#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 +72,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;
} }
@ -73,6 +90,10 @@ bool startCrashHandler() {
annotations["build_number"] = BuildInfo::BUILD_NUMBER.toStdString(); annotations["build_number"] = BuildInfo::BUILD_NUMBER.toStdString();
annotations["build_type"] = BuildInfo::BUILD_TYPE_STRING.toStdString(); annotations["build_type"] = BuildInfo::BUILD_TYPE_STRING.toStdString();
auto machineFingerPrint = uuidStringWithoutCurlyBraces(FingerprintUtils::getMachineFingerprint());
annotations["machine_fingerprint"] = machineFingerPrint.toStdString();
arguments.push_back("--no-rate-limit"); arguments.push_back("--no-rate-limit");
// Setup Crashpad DB directory // Setup Crashpad DB directory
@ -82,7 +103,10 @@ bool startCrashHandler() {
const auto crashpadDbPath = crashpadDbDir.toStdString() + "/" + crashpadDbName; const auto crashpadDbPath = crashpadDbDir.toStdString() + "/" + crashpadDbName;
// 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();
// Setup different file paths // Setup different file paths
base::FilePath::StringType dbPath; base::FilePath::StringType dbPath;
@ -101,20 +125,24 @@ bool startCrashHandler() {
// Enable automated uploads. // Enable automated uploads.
database->GetSettings()->SetUploadsEnabled(true); database->GetSettings()->SetUploadsEnabled(true);
#ifdef Q_OS_WIN
AddVectoredExceptionHandler(0, vectoredExceptionHandler); AddVectoredExceptionHandler(0, vectoredExceptionHandler);
#endif
return client->StartHandler(handler, db, db, BACKTRACE_URL, annotations, arguments, true, true); return client->StartHandler(handler, db, db, BACKTRACE_URL, annotations, arguments, true, true);
} }
void setCrashAnnotation(std::string name, std::string value) { void setCrashAnnotation(std::string name, std::string value) {
std::lock_guard<std::mutex> guard(annotationMutex); if (client) {
if (!crashpadAnnotations) { std::lock_guard<std::mutex> guard(annotationMutex);
crashpadAnnotations = new crashpad::SimpleStringDictionary(); // don't free this, let it leak if (!crashpadAnnotations) {
crashpad::CrashpadInfo* crashpad_info = crashpad::CrashpadInfo::GetCrashpadInfo(); crashpadAnnotations = new crashpad::SimpleStringDictionary(); // don't free this, let it leak
crashpad_info->set_simple_annotations(crashpadAnnotations); crashpad::CrashpadInfo* crashpad_info = crashpad::CrashpadInfo::GetCrashpadInfo();
crashpad_info->set_simple_annotations(crashpadAnnotations);
}
std::replace(value.begin(), value.end(), ',', ';');
crashpadAnnotations->SetKeyValue(name, value);
} }
std::replace(value.begin(), value.end(), ',', ';');
crashpadAnnotations->SetKeyValue(name, value);
} }
#endif #endif

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;
} }