Bug 1510574 - Remove shared memory segments from generated minidumps to cut down on the number of modules r=ted
authorGabriele Svelto <gsvelto@mozilla.com>
Fri, 11 Jan 2019 08:56:07 +0000
changeset 510549 30fd54bb80897d6139d84e6c64937a6bc182f70d
parent 510548 c908cdfffe306ae3c461c54ae24c6c9882985592
child 510550 d084d6b3b5334c8bb3e96aaa1861276f0aa26095
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1510574
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1510574 - Remove shared memory segments from generated minidumps to cut down on the number of modules r=ted Differential Revision: https://phabricator.services.mozilla.com/D16188
toolkit/crashreporter/breakpad-client/linux/minidump_writer/linux_dumper.cc
toolkit/crashreporter/breakpad-client/linux/minidump_writer/linux_dumper.h
toolkit/crashreporter/google-breakpad/src/common/linux/linux_libc_support.cc
toolkit/crashreporter/google-breakpad/src/common/linux/linux_libc_support.h
--- a/toolkit/crashreporter/breakpad-client/linux/minidump_writer/linux_dumper.cc
+++ b/toolkit/crashreporter/breakpad-client/linux/minidump_writer/linux_dumper.cc
@@ -67,16 +67,18 @@ static const int DT_ANDROID_REL = DT_LOO
 static const int DT_ANDROID_RELA = DT_LOOS + 4;
 #endif
 
 #endif  // __ANDROID __
 
 static const char kMappedFileUnsafePrefix[] = "/dev/";
 static const char kDeletedSuffix[] = " (deleted)";
 static const char kReservedFlags[] = " ---p";
+static const char kMozillaIpcPrefix[] = "org.mozilla.ipc.";
+static const char kChromiumPrefix[] = "org.chromium.";
 
 inline static bool IsMappedFileOpenUnsafe(
     const google_breakpad::MappingInfo& mapping) {
   // It is unsafe to attempt to open a mapped file that lives under /dev,
   // because the semantics of the open may be driver-specific so we'd risk
   // hanging the crash dumper. And a file in /dev/ almost certainly has no
   // ELF file identifier anyways.
   return my_strncmp(mapping.name,
@@ -567,16 +569,26 @@ bool LinuxDumper::ReadAuxv() {
       auxv_[one_aux_entry.a_type] = one_aux_entry.a_un.a_val;
       res = true;
     }
   }
   sys_close(fd);
   return res;
 }
 
+bool LinuxDumper::IsIPCSharedMemorySegment(const char* name) {
+  if ((my_strstr(name, kMozillaIpcPrefix) ||
+       my_strstr(name, kChromiumPrefix)) &&
+      my_strstr(name, kDeletedSuffix)) {
+    return true;
+  }
+
+  return false;
+}
+
 bool LinuxDumper::EnumerateMappings() {
   char maps_path[NAME_MAX];
   if (!BuildProcPath(maps_path, pid_, "maps"))
     return false;
 
   // linux_gate_loc is the beginning of the kernel's mapping of
   // linux-gate.so in the process.  It doesn't actually show up in the
   // maps list as a filename, but it can be found using the AT_SYSINFO_EHDR
@@ -612,16 +624,21 @@ bool LinuxDumper::EnumerateMappings() {
           // Only copy name if the name is a valid path name, or if
           // it's the VDSO image.
           if (((name = my_strchr(line, '/')) == NULL) &&
               linux_gate_loc &&
               reinterpret_cast<void*>(start_addr) == linux_gate_loc) {
             name = kLinuxGateLibraryName;
             offset = 0;
           }
+          // Skip shared memory segments used for IPC
+          if (name && IsIPCSharedMemorySegment(name)) {
+            line_reader->PopLine(line_len);
+            continue;
+          }
           // Merge adjacent mappings into one module, assuming they're a single
           // library mapped by the dynamic linker.
           if (name && !mappings_.empty()) {
             MappingInfo* module = mappings_.back();
             if ((start_addr == module->start_addr + module->size) &&
                 (my_strlen(name) == my_strlen(module->name)) &&
                 (my_strncmp(name, module->name, my_strlen(name)) == 0)) {
               module->system_mapping_info.end_addr = end_addr;
--- a/toolkit/crashreporter/breakpad-client/linux/minidump_writer/linux_dumper.h
+++ b/toolkit/crashreporter/breakpad-client/linux/minidump_writer/linux_dumper.h
@@ -245,18 +245,20 @@ class LinuxDumper {
   wasteful_vector<pid_t> threads_;
 
   // Info from /proc/<pid>/maps.
   wasteful_vector<MappingInfo*> mappings_;
 
   // Info from /proc/<pid>/auxv
   wasteful_vector<elf_aux_val_t> auxv_;
 
+private:
+  bool IsIPCSharedMemorySegment(const char* name);
+
 #if defined(__ANDROID__)
- private:
   // Android M and later support packed ELF relocations in shared libraries.
   // Packing relocations changes the vaddr of the LOAD segments, such that
   // the effective load bias is no longer the same as the start address of
   // the memory mapping containing the executable parts of the library. The
   // packing is applied to the stripped library run on the target, but not to
   // any other library, and in particular not to the library used to generate
   // breakpad symbols. As a result, we need to adjust the |start_addr| for
   // any mapping that results from a shared library that contains Android
--- a/toolkit/crashreporter/google-breakpad/src/common/linux/linux_libc_support.cc
+++ b/toolkit/crashreporter/google-breakpad/src/common/linux/linux_libc_support.cc
@@ -133,16 +133,27 @@ const char* my_strrchr(const char* hayst
   while (*haystack) {
     if (*haystack == needle)
       ret = haystack;
     haystack++;
   }
   return ret;
 }
 
+const char* my_strstr(const char* haystack, const char* needle) {
+  while (*haystack != 0) {
+    if((*haystack == *needle) &&
+       (my_strncmp(haystack, needle, my_strlen(needle)) == 0)) {
+      return haystack;
+    }
+    haystack++;
+  }
+  return nullptr;
+}
+
 void* my_memchr(const void* src, int needle, size_t src_len) {
   const unsigned char* p = (const unsigned char*)src;
   const unsigned char* p_end = p + src_len;
   for (; p < p_end; ++p) {
     if (*p == needle)
       return (void*)p;
   }
   return NULL;
--- a/toolkit/crashreporter/google-breakpad/src/common/linux/linux_libc_support.h
+++ b/toolkit/crashreporter/google-breakpad/src/common/linux/linux_libc_support.h
@@ -62,16 +62,18 @@ extern unsigned my_uint_len(uintmax_t i)
 //   i: the unsigned integer to serialise.
 //   i_len: the length of the integer in base 10 (see |my_uint_len|).
 extern void my_uitos(char* output, uintmax_t i, unsigned i_len);
 
 extern const char* my_strchr(const char* haystack, char needle);
 
 extern const char* my_strrchr(const char* haystack, char needle);
 
+extern const char *my_strstr(const char *haystack, const char *needle);
+
 // Read a hex value
 //   result: (output) the resulting value
 //   s: a string
 // Returns a pointer to the first invalid charactor.
 extern const char* my_read_hex_ptr(uintptr_t* result, const char* s);
 
 extern const char* my_read_decimal_ptr(uintptr_t* result, const char* s);