如何将google crashpad与我的应用程序集成?

时间:2014-10-04 08:19:50

标签: crash-reports crash-dumps

breakpad项目将被google crashpad项目取代。如何将新的崩溃报告器与我在Mac上的应用程序集成?

2 个答案:

答案 0 :(得分:4)

首先,您需要设置depot_tools才能构建Crashpad。

接下来,您必须获得Crashpad source的副本。

使用gnninja构建Crashpad,其中gn生成构建配置,而ninja进行实际构建。 here中提供了有关如何构建Crashpad的完整说明。

对于MacOS,如果要生成libclient.alibutil.alibbase.a.o中的所有out/Default/obj/out/Default/gen/util/mach文件,则需要链接小型转储并将其上传到远程服务器。此外,您需要将crashpad_handler与应用程序打包,并确保它在运行时可用。

通过configuring Crashpad处理程序将Crashpad与您的应用程序集成,并将其指向能够提取Crashpad崩溃报告的服务器。

#include "client/crashpad_client.h"
#include "client/crash_report_database.h"
#include "client/settings.h"

#if defined(OS_POSIX)
typedef std::string StringType;
#elif defined(OS_WIN)
typedef std::wstring StringType;
#endif

using namespace base;
using namespace crashpad;
using namespace std;

bool initializeCrashpad(void);
StringType getExecutableDir(void);

bool initializeCrashpad() {
  // Get directory where the exe lives so we can pass a full path to handler, reportsDir and metricsDir
  StringType exeDir = getExecutableDir();

  // Ensure that handler is shipped with your application
  FilePath handler(exeDir + "/path/to/crashpad_handler");

  // Directory where reports will be saved. Important! Must be writable or crashpad_handler will crash.
  FilePath reportsDir(exeDir + "/path/to/crashpad");

  // Directory where metrics will be saved. Important! Must be writable or crashpad_handler will crash.
  FilePath metricsDir(exeDir + "/path/to/crashpad");

  // Configure url with BugSplat’s public fred database. Replace 'fred' with the name of your BugSplat database.
  StringType url = "https://fred.bugsplat.com/post/bp/crash/crashpad.php";

  // Metadata that will be posted to the server with the crash report map
  map<StringType, StringType> annotations;
  annotations["format"] = "minidump";          // Required: Crashpad setting to save crash as a minidump
  annotations["product"] = "myCrashpadCrasher" // Required: BugSplat appName
  annotations["version"] = "1.0.0";            // Required: BugSplat appVersion
  annotations["key"] = "Sample key";           // Optional: BugSplat key field
  annotations["user"] = "fred@bugsplat.com";   // Optional: BugSplat user email
  annotations["list_annotations"] = "Sample comment"; // Optional: BugSplat crash description

  // Disable crashpad rate limiting so that all crashes have dmp files
  vector<StringType> arguments; 
  arguments.push_back("--no-rate-limit");

  // Initialize Crashpad database
  unique_ptr<CrashReportDatabase> database = CrashReportDatabase::Initialize(reportsDir);
  if (database == NULL) return false;

  // Enable automated crash uploads
  Settings *settings = database->GetSettings();
  if (settings == NULL) return false;
  settings->SetUploadsEnabled(true);

  // Start crash handler
  CrashpadClient *client = new CrashpadClient();
  bool status = client->StartHandler(handler, reportsDir, metricsDir, url, annotations, arguments, true, true);
  return status;
}

您还需要使用dump_syms生成符号文件。您可以使用symupload将sym文件上传到远程服务器。最后,您可以使用minidump_stackwalk象征小型转储。

答案 1 :(得分:0)

我刚从其中一位开发者那里得到消息,说它尚未准备就绪...... https://groups.google.com/a/chromium.org/forum/#!topic/crashpad-dev/GbS_HcsYzbQ