linux: Remove global variables in crash reporter.
This commit is contained in:
parent
ce6f9f20bf
commit
6134b9ed38
4 changed files with 28 additions and 102 deletions
|
@ -32,55 +32,19 @@ static const size_t kDistroSize = 128;
|
||||||
// no limit.
|
// no limit.
|
||||||
static const off_t kMaxMinidumpFileSize = 1258291;
|
static const off_t kMaxMinidumpFileSize = 1258291;
|
||||||
|
|
||||||
uint64_t g_process_start_time = 0;
|
|
||||||
pid_t g_pid = 0;
|
|
||||||
ExceptionHandler* g_breakpad = NULL;
|
|
||||||
|
|
||||||
// The following helper functions are for calculating uptime.
|
|
||||||
|
|
||||||
// Converts a struct timeval to milliseconds.
|
|
||||||
uint64_t timeval_to_ms(struct timeval *tv) {
|
|
||||||
uint64_t ret = tv->tv_sec; // Avoid overflow by explicitly using a uint64_t.
|
|
||||||
ret *= 1000;
|
|
||||||
ret += tv->tv_usec / 1000;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetProcessStartTime() {
|
|
||||||
// Set the base process start time value.
|
|
||||||
struct timeval tv;
|
|
||||||
if (!gettimeofday(&tv, NULL))
|
|
||||||
g_process_start_time = timeval_to_ms(&tv);
|
|
||||||
else
|
|
||||||
g_process_start_time = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Populates the passed in allocated string and its size with the distro of
|
|
||||||
// the crashing process.
|
|
||||||
// The passed string is expected to be at least kDistroSize bytes long.
|
|
||||||
void PopulateDistro(char* distro, size_t* distro_len_param) {
|
|
||||||
size_t distro_len = std::min(my_strlen(base::g_linux_distro), kDistroSize);
|
|
||||||
memcpy(distro, base::g_linux_distro, distro_len);
|
|
||||||
if (distro_len_param)
|
|
||||||
*distro_len_param = distro_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ADDRESS_SANITIZER)
|
|
||||||
extern "C"
|
|
||||||
void __asan_set_error_report_callback(void (*cb)(const char*));
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
void AsanLinuxBreakpadCallback(const char* report) {
|
|
||||||
// Send minidump here.
|
|
||||||
g_breakpad->SimulateSignalDelivery(SIGKILL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
CrashReporterLinux::CrashReporterLinux() {
|
CrashReporterLinux::CrashReporterLinux()
|
||||||
SetProcessStartTime();
|
: process_start_time_(0),
|
||||||
g_pid = getpid();
|
pid_(getpid()) {
|
||||||
|
// Set the base process start time value.
|
||||||
|
struct timeval tv;
|
||||||
|
if (!gettimeofday(&tv, NULL)) {
|
||||||
|
uint64_t ret = tv.tv_sec;
|
||||||
|
ret *= 1000;
|
||||||
|
ret += tv.tv_usec / 1000;
|
||||||
|
process_start_time_ = ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Make base::g_linux_distro work.
|
// Make base::g_linux_distro work.
|
||||||
base::SetLinuxDistro(base::GetLinuxDistro());
|
base::SetLinuxDistro(base::GetLinuxDistro());
|
||||||
|
@ -97,10 +61,9 @@ void CrashReporterLinux::InitBreakpad(const std::string& product_name,
|
||||||
bool skip_system_crash_handler) {
|
bool skip_system_crash_handler) {
|
||||||
EnableCrashDumping();
|
EnableCrashDumping();
|
||||||
|
|
||||||
#if defined(ADDRESS_SANITIZER)
|
crash_keys_.SetKeyValue("prod", "Atom-Shell");
|
||||||
// Register the callback for AddressSanitizer error reporting.
|
crash_keys_.SetKeyValue("ver", version.c_str());
|
||||||
__asan_set_error_report_callback(AsanLinuxBreakpadCallback);
|
upload_url_ = submit_url;
|
||||||
#endif
|
|
||||||
|
|
||||||
for (StringMap::const_iterator iter = upload_parameters_.begin();
|
for (StringMap::const_iterator iter = upload_parameters_.begin();
|
||||||
iter != upload_parameters_.end(); ++iter)
|
iter != upload_parameters_.end(); ++iter)
|
||||||
|
@ -116,17 +79,16 @@ void CrashReporterLinux::EnableCrashDumping() {
|
||||||
PathService::Get(base::DIR_TEMP, &tmp_path);
|
PathService::Get(base::DIR_TEMP, &tmp_path);
|
||||||
|
|
||||||
base::FilePath dumps_path(tmp_path);
|
base::FilePath dumps_path(tmp_path);
|
||||||
DCHECK(!g_breakpad);
|
|
||||||
MinidumpDescriptor minidump_descriptor(dumps_path.value());
|
MinidumpDescriptor minidump_descriptor(dumps_path.value());
|
||||||
minidump_descriptor.set_size_limit(kMaxMinidumpFileSize);
|
minidump_descriptor.set_size_limit(kMaxMinidumpFileSize);
|
||||||
|
|
||||||
g_breakpad = new ExceptionHandler(
|
breakpad_.reset(new ExceptionHandler(
|
||||||
minidump_descriptor,
|
minidump_descriptor,
|
||||||
NULL,
|
NULL,
|
||||||
CrashDone,
|
CrashDone,
|
||||||
this,
|
this,
|
||||||
true, // Install handlers.
|
true, // Install handlers.
|
||||||
-1); // Server file descriptor. -1 for in-process.
|
-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CrashReporterLinux::CrashDone(const MinidumpDescriptor& minidump,
|
bool CrashReporterLinux::CrashDone(const MinidumpDescriptor& minidump,
|
||||||
|
@ -147,22 +109,13 @@ bool CrashReporterLinux::CrashDone(const MinidumpDescriptor& minidump,
|
||||||
BreakpadInfo info = {0};
|
BreakpadInfo info = {0};
|
||||||
info.filename = minidump.path();
|
info.filename = minidump.path();
|
||||||
info.fd = minidump.fd();
|
info.fd = minidump.fd();
|
||||||
#if defined(ADDRESS_SANITIZER)
|
|
||||||
google_breakpad::PageAllocator allocator;
|
|
||||||
const size_t log_path_len = my_strlen(minidump.path());
|
|
||||||
char* log_path = reinterpret_cast<char*>(allocator.Alloc(log_path_len + 1));
|
|
||||||
my_memcpy(log_path, minidump.path(), log_path_len);
|
|
||||||
my_memcpy(log_path + log_path_len - 4, ".log", 4);
|
|
||||||
log_path[log_path_len] = '\0';
|
|
||||||
info.log_filename = log_path;
|
|
||||||
#endif
|
|
||||||
// TODO(zcbenz): Set the correct process_type here.
|
|
||||||
info.distro = base::g_linux_distro;
|
info.distro = base::g_linux_distro;
|
||||||
info.distro_length = my_strlen(base::g_linux_distro);
|
info.distro_length = my_strlen(base::g_linux_distro);
|
||||||
info.upload = true;
|
info.upload = true;
|
||||||
info.process_start_time = g_process_start_time;
|
info.process_start_time = self->process_start_time_;
|
||||||
info.oom_size = base::g_oom_size;
|
info.oom_size = base::g_oom_size;
|
||||||
info.pid = g_pid;
|
info.pid = self->pid_;
|
||||||
|
info.upload_url = self->upload_url_.c_str();
|
||||||
info.crash_keys = &self->crash_keys_;
|
info.crash_keys = &self->crash_keys_;
|
||||||
HandleCrashDump(info);
|
HandleCrashDump(info);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -6,12 +6,14 @@
|
||||||
#define ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_LINUX_H_
|
#define ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_LINUX_H_
|
||||||
|
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "common/crash_reporter/crash_reporter.h"
|
#include "common/crash_reporter/crash_reporter.h"
|
||||||
#include "common/crash_reporter/linux/crash_dump_handler.h"
|
#include "common/crash_reporter/linux/crash_dump_handler.h"
|
||||||
|
|
||||||
template <typename T> struct DefaultSingletonTraits;
|
template <typename T> struct DefaultSingletonTraits;
|
||||||
|
|
||||||
namespace google_breakpad {
|
namespace google_breakpad {
|
||||||
|
class ExceptionHandler;
|
||||||
class MinidumpDescriptor;
|
class MinidumpDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +43,13 @@ class CrashReporterLinux : public CrashReporter {
|
||||||
void* context,
|
void* context,
|
||||||
const bool succeeded);
|
const bool succeeded);
|
||||||
|
|
||||||
|
scoped_ptr<google_breakpad::ExceptionHandler> breakpad_;
|
||||||
CrashKeyStorage crash_keys_;
|
CrashKeyStorage crash_keys_;
|
||||||
|
|
||||||
|
uint64_t process_start_time_;
|
||||||
|
pid_t pid_;
|
||||||
|
std::string upload_url_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CrashReporterLinux);
|
DISALLOW_COPY_AND_ASSIGN(CrashReporterLinux);
|
||||||
};
|
};
|
||||||
} // namespace crash_reporter
|
} // namespace crash_reporter
|
||||||
|
|
|
@ -29,8 +29,6 @@ namespace crash_reporter {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const char kUploadURL[] = "https://clients2.google.com/cr/report";
|
|
||||||
|
|
||||||
// String buffer size to use to convert a uint64_t to string.
|
// String buffer size to use to convert a uint64_t to string.
|
||||||
const size_t kUint64StringSize = 21;
|
const size_t kUint64StringSize = 21;
|
||||||
|
|
||||||
|
@ -90,9 +88,6 @@ const char g_form_data_msg[] = "Content-Disposition: form-data; name=\"";
|
||||||
const char g_quote_msg[] = "\"";
|
const char g_quote_msg[] = "\"";
|
||||||
const char g_dashdash_msg[] = "--";
|
const char g_dashdash_msg[] = "--";
|
||||||
const char g_dump_msg[] = "upload_file_minidump\"; filename=\"dump\"";
|
const char g_dump_msg[] = "upload_file_minidump\"; filename=\"dump\"";
|
||||||
#if defined(ADDRESS_SANITIZER)
|
|
||||||
const char g_log_msg[] = "upload_file_log\"; filename=\"log\"";
|
|
||||||
#endif
|
|
||||||
const char g_content_type_msg[] = "Content-Type: application/octet-stream";
|
const char g_content_type_msg[] = "Content-Type: application/octet-stream";
|
||||||
|
|
||||||
// MimeWriter manages an iovec for writing MIMEs to a file.
|
// MimeWriter manages an iovec for writing MIMEs to a file.
|
||||||
|
@ -352,7 +347,7 @@ void ExecUploadProcessOrTerminate(const BreakpadInfo& info,
|
||||||
header,
|
header,
|
||||||
post_file,
|
post_file,
|
||||||
// TODO(zcbenz): Enabling custom upload url.
|
// TODO(zcbenz): Enabling custom upload url.
|
||||||
kUploadURL,
|
info.upload_url,
|
||||||
"--timeout=10", // Set a timeout so we don't hang forever.
|
"--timeout=10", // Set a timeout so we don't hang forever.
|
||||||
"--tries=1", // Don't retry if the upload fails.
|
"--tries=1", // Don't retry if the upload fails.
|
||||||
"-O", // output reply to fd 3
|
"-O", // output reply to fd 3
|
||||||
|
@ -397,15 +392,6 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
||||||
LoadDataFromFile(allocator, info.filename, &dumpfd, &dump_data, &dump_size);
|
LoadDataFromFile(allocator, info.filename, &dumpfd, &dump_data, &dump_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jcivelli): make log work when using FDs.
|
|
||||||
#if defined(ADDRESS_SANITIZER)
|
|
||||||
int logfd;
|
|
||||||
size_t log_size;
|
|
||||||
uint8_t* log_data;
|
|
||||||
// Load the AddressSanitizer log into log_data.
|
|
||||||
LoadDataFromFile(allocator, info.log_filename, &logfd, &log_data, &log_size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// We need to build a MIME block for uploading to the server. Since we are
|
// We need to build a MIME block for uploading to the server. Since we are
|
||||||
// going to fork and run wget, it needs to be written to a temp file.
|
// going to fork and run wget, it needs to be written to a temp file.
|
||||||
const int ufd = sys_open("/dev/urandom", O_RDONLY, 0);
|
const int ufd = sys_open("/dev/urandom", O_RDONLY, 0);
|
||||||
|
@ -512,14 +498,6 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
||||||
|
|
||||||
MimeWriter writer(temp_file_fd, mime_boundary);
|
MimeWriter writer(temp_file_fd, mime_boundary);
|
||||||
{
|
{
|
||||||
// TODO(zcbenz): Set version and product_name from JS API.
|
|
||||||
std::string product_name("Atom-Shell");
|
|
||||||
std::string version("0.1.0");
|
|
||||||
|
|
||||||
writer.AddBoundary();
|
|
||||||
writer.AddPairString("prod", product_name.c_str());
|
|
||||||
writer.AddBoundary();
|
|
||||||
writer.AddPairString("ver", version.c_str());
|
|
||||||
writer.AddBoundary();
|
writer.AddBoundary();
|
||||||
if (info.pid > 0) {
|
if (info.pid > 0) {
|
||||||
char pid_value_buf[kUint64StringSize];
|
char pid_value_buf[kUint64StringSize];
|
||||||
|
@ -581,11 +559,6 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.AddFileContents(g_dump_msg, dump_data, dump_size);
|
writer.AddFileContents(g_dump_msg, dump_data, dump_size);
|
||||||
#if defined(ADDRESS_SANITIZER)
|
|
||||||
// Append a multipart boundary and the contents of the AddressSanitizer log.
|
|
||||||
writer.AddBoundary();
|
|
||||||
writer.AddFileContents(g_log_msg, log_data, log_size);
|
|
||||||
#endif
|
|
||||||
writer.AddEnd();
|
writer.AddEnd();
|
||||||
writer.Flush();
|
writer.Flush();
|
||||||
|
|
||||||
|
@ -678,9 +651,6 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
||||||
|
|
||||||
// Helper process.
|
// Helper process.
|
||||||
IGNORE_RET(sys_unlink(info.filename));
|
IGNORE_RET(sys_unlink(info.filename));
|
||||||
#if defined(ADDRESS_SANITIZER)
|
|
||||||
IGNORE_RET(sys_unlink(info.log_filename));
|
|
||||||
#endif
|
|
||||||
IGNORE_RET(sys_unlink(temp_file));
|
IGNORE_RET(sys_unlink(temp_file));
|
||||||
sys__exit(0);
|
sys__exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,13 @@ typedef google_breakpad::NonAllocatingMap<256, 256, 64> CrashKeyStorage;
|
||||||
struct BreakpadInfo {
|
struct BreakpadInfo {
|
||||||
int fd; // File descriptor to the Breakpad dump data.
|
int fd; // File descriptor to the Breakpad dump data.
|
||||||
const char* filename; // Path to the Breakpad dump data.
|
const char* filename; // Path to the Breakpad dump data.
|
||||||
#if defined(ADDRESS_SANITIZER)
|
|
||||||
const char* log_filename; // Path to the ASan log file.
|
|
||||||
const char* asan_report_str; // ASan report.
|
|
||||||
unsigned asan_report_length; // Length of |asan_report_length|.
|
|
||||||
#endif
|
|
||||||
const char* distro; // Linux distro string.
|
const char* distro; // Linux distro string.
|
||||||
unsigned distro_length; // Length of |distro|.
|
unsigned distro_length; // Length of |distro|.
|
||||||
bool upload; // Whether to upload or save crash dump.
|
bool upload; // Whether to upload or save crash dump.
|
||||||
uint64_t process_start_time; // Uptime of the crashing process.
|
uint64_t process_start_time; // Uptime of the crashing process.
|
||||||
size_t oom_size; // Amount of memory requested if OOM.
|
size_t oom_size; // Amount of memory requested if OOM.
|
||||||
uint64_t pid; // PID where applicable.
|
uint64_t pid; // PID where applicable.
|
||||||
|
const char* upload_url; // URL to upload the minidump.
|
||||||
CrashKeyStorage* crash_keys;
|
CrashKeyStorage* crash_keys;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue