Expose crash reporter start for child node processes

This commit is contained in:
Ramya Achutha Rao 2016-12-01 18:19:57 -08:00 committed by Kevin Sawicki
parent 61aff5ed35
commit d4b44d8b69
6 changed files with 77 additions and 11 deletions

View file

@ -6,10 +6,12 @@
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include "atom/common/atom_version.h"
#include "atom/common/chrome_version.h"
#include "atom/common/crash_reporter/crash_reporter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/node_includes.h"
#include "base/logging.h"
@ -23,10 +25,6 @@ namespace {
// Dummy class type that used for crashing the program.
struct DummyClass { bool crash; };
void Crash() {
static_cast<DummyClass*>(nullptr)->crash = true;
}
void Hang() {
for (;;)
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
@ -76,7 +74,7 @@ v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
// we can get the stack trace.
void FatalErrorCallback(const char* location, const char* message) {
LOG(ERROR) << "Fatal error in V8: " << location << " " << message;
Crash();
AtomBindings::Crash();
}
} // namespace
@ -95,7 +93,7 @@ void AtomBindings::BindTo(v8::Isolate* isolate,
v8::V8::SetFatalErrorHandler(FatalErrorCallback);
mate::Dictionary dict(isolate, process);
dict.SetMethod("crash", &Crash);
dict.SetMethod("crash", &AtomBindings::Crash);
dict.SetMethod("hang", &Hang);
dict.SetMethod("log", &Log);
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
@ -159,4 +157,29 @@ void AtomBindings::Log(const base::string16& message) {
std::cout << message << std::flush;
}
void AtomBindings::Crash() {
static_cast<DummyClass*>(nullptr)->crash = true;
}
void AtomBindings::StartCrashReporter(
const std::string& productName,
const std::string& companyName,
const std::string& submitUrl,
const std::string& tmpPath,
const std::map<std::string, std::string>& extra_parameters) {
std::map<std::string, std::string> allParameters;
allParameters.insert(std::make_pair("_productName", productName));
allParameters.insert(std::make_pair("_companyName", companyName));
allParameters.insert(extra_parameters.begin(), extra_parameters.end());
auto reporter = crash_reporter::CrashReporter::GetInstance();
reporter->Start(productName,
companyName,
submitUrl,
base::FilePath(tmpPath),
true,
false,
allParameters);
}
} // namespace atom

View file

@ -6,6 +6,8 @@
#define ATOM_COMMON_API_ATOM_BINDINGS_H_
#include <list>
#include <map>
#include <string>
#include "base/macros.h"
#include "base/strings/string16.h"
@ -28,6 +30,13 @@ class AtomBindings {
void BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process);
static void Log(const base::string16& message);
static void Crash();
static void StartCrashReporter(
const std::string& productName,
const std::string& companyName,
const std::string& submitUrl,
const std::string& tmpPath,
const std::map<std::string, std::string>& extra_parameters);
private:
void ActivateUVLoop(v8::Isolate* isolate);