2013-07-04 07:54:34 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2013-11-14 05:42:28 +00:00
|
|
|
#include "common/crash_reporter/crash_reporter_win.h"
|
|
|
|
|
2013-11-24 14:22:08 +00:00
|
|
|
#include "base/file_util.h"
|
2013-11-19 13:37:02 +00:00
|
|
|
#include "base/logging.h"
|
2013-11-14 05:42:28 +00:00
|
|
|
#include "base/memory/singleton.h"
|
2013-11-24 14:22:08 +00:00
|
|
|
#include "base/string_util.h"
|
|
|
|
#include "base/utf_string_conversions.h"
|
2013-07-04 07:54:34 +00:00
|
|
|
|
|
|
|
namespace crash_reporter {
|
|
|
|
|
2013-11-24 14:22:08 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Minidump with stacks, PEB, TEB, and unloaded module list.
|
|
|
|
const MINIDUMP_TYPE kSmallDumpType = static_cast<MINIDUMP_TYPE>(
|
|
|
|
MiniDumpWithProcessThreadData | // Get PEB and TEB.
|
|
|
|
MiniDumpWithUnloadedModules); // Get unloaded modules when available.
|
|
|
|
|
|
|
|
const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\$1 Crash Service";
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-11-19 13:37:02 +00:00
|
|
|
CrashReporterWin::CrashReporterWin() {
|
2013-11-14 05:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CrashReporterWin::~CrashReporterWin() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CrashReporterWin::InitBreakpad(const std::string& product_name,
|
|
|
|
const std::string& version,
|
|
|
|
const std::string& company_name,
|
|
|
|
const std::string& submit_url,
|
|
|
|
bool auto_submit,
|
|
|
|
bool skip_system_crash_handler) {
|
2013-11-19 13:37:02 +00:00
|
|
|
skip_system_crash_handler_ = skip_system_crash_handler;
|
|
|
|
|
2013-11-24 14:22:08 +00:00
|
|
|
base::FilePath temp_dir;
|
|
|
|
if (!file_util::GetTempDir(&temp_dir)) {
|
|
|
|
LOG(ERROR) << "Cannot get temp directory";
|
|
|
|
return;
|
|
|
|
}
|
2013-11-19 13:37:02 +00:00
|
|
|
|
2013-11-24 14:22:08 +00:00
|
|
|
string16 pipe_name = ReplaceStringPlaceholders(kPipeNameFormat,
|
|
|
|
UTF8ToUTF16(product_name),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
// Wait until the crash service is started.
|
|
|
|
HANDLE waiting_event =
|
|
|
|
::CreateEventW(NULL, TRUE, FALSE, L"g_atom_shell_crash_service");
|
|
|
|
if (waiting_event != INVALID_HANDLE_VALUE)
|
|
|
|
WaitForSingleObject(waiting_event, 1000);
|
|
|
|
|
|
|
|
breakpad_.reset(new google_breakpad::ExceptionHandler(
|
|
|
|
temp_dir.value(),
|
2013-11-19 13:37:02 +00:00
|
|
|
FilterCallback,
|
|
|
|
MinidumpCallback,
|
|
|
|
this,
|
2013-11-24 14:22:08 +00:00
|
|
|
google_breakpad::ExceptionHandler::HANDLER_ALL,
|
|
|
|
kSmallDumpType,
|
|
|
|
pipe_name.c_str(),
|
2013-11-24 14:57:47 +00:00
|
|
|
GetCustomInfo(product_name, version, company_name)));
|
2013-11-24 14:22:08 +00:00
|
|
|
|
|
|
|
if (!breakpad_->IsOutOfProcess())
|
|
|
|
LOG(ERROR) << "Cannot initialize out-of-process crash handler";
|
2013-07-04 07:54:34 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 10:02:15 +00:00
|
|
|
void CrashReporterWin::SetUploadParameters() {
|
|
|
|
upload_parameters_["platform"] = "win32";
|
|
|
|
}
|
|
|
|
|
2013-11-19 13:37:02 +00:00
|
|
|
// static
|
|
|
|
bool CrashReporterWin::FilterCallback(void* context,
|
|
|
|
EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool CrashReporterWin::MinidumpCallback(const wchar_t* dump_path,
|
|
|
|
const wchar_t* minidump_id,
|
|
|
|
void* context,
|
|
|
|
EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion,
|
|
|
|
bool succeeded) {
|
|
|
|
CrashReporterWin* self = static_cast<CrashReporterWin*>(context);
|
|
|
|
if (succeeded && !self->skip_system_crash_handler_)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-24 14:57:47 +00:00
|
|
|
google_breakpad::CustomClientInfo* CrashReporterWin::GetCustomInfo(
|
|
|
|
const std::string& product_name,
|
|
|
|
const std::string& version,
|
|
|
|
const std::string& company_name) {
|
|
|
|
custom_info_entries_.clear();
|
|
|
|
custom_info_entries_.reserve(2 + upload_parameters_.size());
|
|
|
|
|
|
|
|
custom_info_entries_.push_back(google_breakpad::CustomInfoEntry(
|
2013-11-24 15:17:48 +00:00
|
|
|
L"prod", L"Atom-Shell"));
|
2013-11-24 14:57:47 +00:00
|
|
|
custom_info_entries_.push_back(google_breakpad::CustomInfoEntry(
|
|
|
|
L"ver", UTF8ToWide(version).c_str()));
|
|
|
|
|
|
|
|
for (StringMap::const_iterator iter = upload_parameters_.begin();
|
|
|
|
iter != upload_parameters_.end(); ++iter) {
|
|
|
|
custom_info_entries_.push_back(google_breakpad::CustomInfoEntry(
|
|
|
|
UTF8ToWide(iter->first).c_str(),
|
|
|
|
UTF8ToWide(iter->second).c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
custom_info_.entries = &custom_info_entries_.front();
|
|
|
|
custom_info_.count = custom_info_entries_.size();
|
|
|
|
return &custom_info_;
|
|
|
|
}
|
|
|
|
|
2013-07-04 07:54:34 +00:00
|
|
|
// static
|
2013-11-14 05:42:28 +00:00
|
|
|
CrashReporterWin* CrashReporterWin::GetInstance() {
|
|
|
|
return Singleton<CrashReporterWin>::get();
|
2013-07-04 07:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2013-11-14 05:42:28 +00:00
|
|
|
CrashReporter* CrashReporter::GetInstance() {
|
|
|
|
return CrashReporterWin::GetInstance();
|
2013-07-04 07:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace crash_reporter
|