]> khamidou — GitHub mirrors - electron.git/commitdiff
linux: Remove global variables in crash reporter.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 26 Feb 2014 13:33:14 +0000 (21:33 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 26 Feb 2014 13:33:14 +0000 (21:33 +0800)
common/crash_reporter/crash_reporter_linux.cc
common/crash_reporter/crash_reporter_linux.h
common/crash_reporter/linux/crash_dump_handler.cc
common/crash_reporter/linux/crash_dump_handler.h

index 2fab44a81fc31ddc120ca72eaa66892def9f764e..ded879a42141ce874fd6b9c0794f7f0f2f30423c 100644 (file)
@@ -32,55 +32,19 @@ static const size_t kDistroSize = 128;
 // no limit.
 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;
-}
+}  // namespace
 
-void SetProcessStartTime() {
+CrashReporterLinux::CrashReporterLinux()
+    : process_start_time_(0),
+      pid_(getpid()) {
   // 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
-
-CrashReporterLinux::CrashReporterLinux() {
-  SetProcessStartTime();
-  g_pid = getpid();
+  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.
   base::SetLinuxDistro(base::GetLinuxDistro());
@@ -97,10 +61,9 @@ void CrashReporterLinux::InitBreakpad(const std::string& product_name,
                                       bool skip_system_crash_handler) {
   EnableCrashDumping();
 
-#if defined(ADDRESS_SANITIZER)
-  // Register the callback for AddressSanitizer error reporting.
-  __asan_set_error_report_callback(AsanLinuxBreakpadCallback);
-#endif
+  crash_keys_.SetKeyValue("prod", "Atom-Shell");
+  crash_keys_.SetKeyValue("ver", version.c_str());
+  upload_url_ = submit_url;
 
   for (StringMap::const_iterator iter = upload_parameters_.begin();
        iter != upload_parameters_.end(); ++iter)
@@ -116,17 +79,16 @@ void CrashReporterLinux::EnableCrashDumping() {
   PathService::Get(base::DIR_TEMP, &tmp_path);
 
   base::FilePath dumps_path(tmp_path);
-  DCHECK(!g_breakpad);
   MinidumpDescriptor minidump_descriptor(dumps_path.value());
   minidump_descriptor.set_size_limit(kMaxMinidumpFileSize);
 
-  g_breakpad = new ExceptionHandler(
+  breakpad_.reset(new ExceptionHandler(
       minidump_descriptor,
       NULL,
       CrashDone,
       this,
       true,  // Install handlers.
-      -1);   // Server file descriptor. -1 for in-process.
+      -1));
 }
 
 bool CrashReporterLinux::CrashDone(const MinidumpDescriptor& minidump,
@@ -147,22 +109,13 @@ bool CrashReporterLinux::CrashDone(const MinidumpDescriptor& minidump,
   BreakpadInfo info = {0};
   info.filename = minidump.path();
   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_length = my_strlen(base::g_linux_distro);
   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.pid = g_pid;
+  info.pid = self->pid_;
+  info.upload_url = self->upload_url_.c_str();
   info.crash_keys = &self->crash_keys_;
   HandleCrashDump(info);
   return true;
index 094aebfd9d726616a074e208e1e3208a29403dd0..e2349bbe5debdfbb59886fe01965548f5f74bec0 100644 (file)
@@ -6,12 +6,14 @@
 #define ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_LINUX_H_
 
 #include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
 #include "common/crash_reporter/crash_reporter.h"
 #include "common/crash_reporter/linux/crash_dump_handler.h"
 
 template <typename T> struct DefaultSingletonTraits;
 
 namespace google_breakpad {
+class ExceptionHandler;
 class MinidumpDescriptor;
 }
 
@@ -41,8 +43,13 @@ class CrashReporterLinux : public CrashReporter {
                         void* context,
                         const bool succeeded);
 
+  scoped_ptr<google_breakpad::ExceptionHandler> breakpad_;
   CrashKeyStorage crash_keys_;
 
+  uint64_t process_start_time_;
+  pid_t pid_;
+  std::string upload_url_;
+
   DISALLOW_COPY_AND_ASSIGN(CrashReporterLinux);
 };
 }  // namespace crash_reporter
index 425560826ff69a9c00fdde22b0888a9db750e062..255797ca3abcc63e4240bc81c8961c9ba8725b2f 100644 (file)
@@ -29,8 +29,6 @@ namespace crash_reporter {
 
 namespace {
 
-const char kUploadURL[] = "https://clients2.google.com/cr/report";
-
 // String buffer size to use to convert a uint64_t to string.
 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_dashdash_msg[] = "--";
 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";
 
 // MimeWriter manages an iovec for writing MIMEs to a file.
@@ -352,7 +347,7 @@ void ExecUploadProcessOrTerminate(const BreakpadInfo& info,
     header,
     post_file,
     // TODO(zcbenz): Enabling custom upload url.
-    kUploadURL,
+    info.upload_url,
     "--timeout=10",  // Set a timeout so we don't hang forever.
     "--tries=1",     // Don't retry if the upload fails.
     "-O",  // output reply to fd 3
@@ -397,15 +392,6 @@ void HandleCrashDump(const BreakpadInfo& info) {
     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
   // 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);
@@ -512,14 +498,6 @@ void HandleCrashDump(const BreakpadInfo& info) {
 
   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();
     if (info.pid > 0) {
       char pid_value_buf[kUint64StringSize];
@@ -581,11 +559,6 @@ void HandleCrashDump(const BreakpadInfo& info) {
   }
 
   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.Flush();
 
@@ -678,9 +651,6 @@ void HandleCrashDump(const BreakpadInfo& info) {
 
     // Helper process.
     IGNORE_RET(sys_unlink(info.filename));
-#if defined(ADDRESS_SANITIZER)
-    IGNORE_RET(sys_unlink(info.log_filename));
-#endif
     IGNORE_RET(sys_unlink(temp_file));
     sys__exit(0);
   }
index a91a3c385579b9baadbd2f9bc7272605831527d4..58f4fe8851835743c28a79784530dfa9a0cf72e7 100644 (file)
@@ -19,17 +19,13 @@ typedef google_breakpad::NonAllocatingMap<256, 256, 64> CrashKeyStorage;
 struct BreakpadInfo {
   int fd;                          // File descriptor 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.
   unsigned distro_length;          // Length of |distro|.
   bool upload;                     // Whether to upload or save crash dump.
   uint64_t process_start_time;     // Uptime of the crashing process.
   size_t oom_size;                 // Amount of memory requested if OOM.
   uint64_t pid;                    // PID where applicable.
+  const char* upload_url;          // URL to upload the minidump.
   CrashKeyStorage* crash_keys;
 };