Bug 1319071 - Make crash minidumps use the same format for filenames on Linux as on other platforms; r?Ted draft
authorGabriele Svelto <gsvelto@mozilla.com>
Tue, 14 Mar 2017 14:37:26 +0100
changeset 500676 216cea3dc9162f70334a3abe3d169bf79dadf708
parent 500240 39607304b774591fa6e32c4b06158d869483c312
child 549672 7d23e80e7349d0e17756561d77b427f7509f6044
push id49758
push usergsvelto@mozilla.com
push dateFri, 17 Mar 2017 10:49:11 +0000
reviewersTed
bugs1319071
milestone55.0a1
Bug 1319071 - Make crash minidumps use the same format for filenames on Linux as on other platforms; r?Ted This patch forks the breakpad files used for GUID generation and replaces them with copies living together with the rest of the forked sources. Since other files in the breakpad sources rely on the original files being present they haven't been removed but we deliberately define their inclusion definitions in the build system to prevent them from contributing to the build. This ensures that we always use our own version of the GUID generator while not touching the non-forked sources. MozReview-Commit-ID: 5kW74yAPUDW
toolkit/crashreporter/breakpad-client/linux/crash_generation/crash_generation_server.cc
toolkit/crashreporter/breakpad-client/linux/handler/guid_generator.cc
toolkit/crashreporter/breakpad-client/linux/handler/guid_generator.h
toolkit/crashreporter/breakpad-client/linux/handler/minidump_descriptor.cc
toolkit/crashreporter/breakpad-client/linux/moz.build
toolkit/crashreporter/google-breakpad/src/common/linux/moz.build
tools/profiler/moz.build
--- a/toolkit/crashreporter/breakpad-client/linux/crash_generation/crash_generation_server.cc
+++ b/toolkit/crashreporter/breakpad-client/linux/crash_generation/crash_generation_server.cc
@@ -39,19 +39,19 @@
 #include <sys/types.h>
 #include <unistd.h>
 
 #include <vector>
 
 #include "linux/crash_generation/crash_generation_server.h"
 #include "linux/crash_generation/client_info.h"
 #include "linux/handler/exception_handler.h"
+#include "linux/handler/guid_generator.h"
 #include "linux/minidump_writer/minidump_writer.h"
 #include "common/linux/eintr_wrapper.h"
-#include "common/linux/guid_creator.h"
 #include "common/linux/safe_readlink.h"
 
 static const char kCommandQuit = 'x';
 
 namespace google_breakpad {
 
 CrashGenerationServer::CrashGenerationServer(
   const int listen_fd,
copy from toolkit/crashreporter/google-breakpad/src/common/linux/guid_creator.cc
copy to toolkit/crashreporter/breakpad-client/linux/handler/guid_generator.cc
--- a/toolkit/crashreporter/google-breakpad/src/common/linux/guid_creator.cc
+++ b/toolkit/crashreporter/breakpad-client/linux/handler/guid_generator.cc
@@ -22,17 +22,17 @@
 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#include "common/linux/guid_creator.h"
+#include "linux/handler/guid_generator.h"
 
 #include <assert.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -41,21 +41,25 @@
 //
 // This class is used to generate random GUID.
 // Currently use random number to generate a GUID since Linux has
 // no native GUID generator. This should be OK since we don't expect
 // crash to happen very offen.
 //
 class GUIDGenerator {
  public:
-  static uint32_t BytesToUInt32(const uint8_t bytes[]) {
-    return ((uint32_t) bytes[0]
-            | ((uint32_t) bytes[1] << 8)
-            | ((uint32_t) bytes[2] << 16)
-            | ((uint32_t) bytes[3] << 24));
+  static uint16_t BytesToUInt16(const uint8_t bytes[]) {
+    return ((uint16_t) bytes[1] << 8) | ((uint16_t) bytes[0]);
+  }
+
+  // The last field in a GUID is 48 bits long so we're converting only 6 bytes
+  static uint64_t BytesToUInt48(const uint8_t bytes[]) {
+    return ((uint64_t) bytes[0] << 40) | ((uint64_t) bytes[1] << 32) |
+           ((uint64_t) bytes[2] << 24) | ((uint64_t) bytes[3] << 16) |
+           ((uint64_t) bytes[4] << 8)  | (uint64_t) bytes[5];
   }
 
   static void UInt32ToBytes(uint8_t bytes[], uint32_t n) {
     bytes[0] = n & 0xff;
     bytes[1] = (n >> 8) & 0xff;
     bytes[2] = (n >> 16) & 0xff;
     bytes[3] = (n >> 24) & 0xff;
   }
@@ -84,21 +88,21 @@ class GUIDGenerator {
 
 pthread_once_t GUIDGenerator::once_control = PTHREAD_ONCE_INIT;
 
 bool CreateGUID(GUID *guid) {
   return GUIDGenerator::CreateGUID(guid);
 }
 
 // Parse guid to string.
-bool GUIDToString(const GUID *guid, char *buf, int buf_len) {
+bool GUIDToString(const GUID *guid, char *buf, size_t buf_len) {
   // Should allow more space the the max length of GUID.
   assert(buf_len > kGUIDStringLength);
   int num = snprintf(buf, buf_len, kGUIDFormatString,
                      guid->data1, guid->data2, guid->data3,
-                     GUIDGenerator::BytesToUInt32(&(guid->data4[0])),
-                     GUIDGenerator::BytesToUInt32(&(guid->data4[4])));
+                     GUIDGenerator::BytesToUInt16(&(guid->data4[0])),
+                     GUIDGenerator::BytesToUInt48(&(guid->data4[2])));
   if (num != kGUIDStringLength)
     return false;
 
   buf[num] = '\0';
   return true;
 }
copy from toolkit/crashreporter/google-breakpad/src/common/linux/guid_creator.h
copy to toolkit/crashreporter/breakpad-client/linux/handler/guid_generator.h
--- a/toolkit/crashreporter/google-breakpad/src/common/linux/guid_creator.h
+++ b/toolkit/crashreporter/breakpad-client/linux/handler/guid_generator.h
@@ -22,27 +22,27 @@
 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifndef COMMON_LINUX_GUID_CREATOR_H__
-#define COMMON_LINUX_GUID_CREATOR_H__
+#ifndef LINUX_HANDLER_GUID_GENERATOR_H__
+#define LINUX_HANDLER_GUID_GENERATOR_H__
 
 #include "google_breakpad/common/minidump_format.h"
 
 typedef MDGUID GUID;
 
 // Format string for parsing GUID.
-#define kGUIDFormatString "%08x-%04x-%04x-%08x-%08x"
+const char kGUIDFormatString[] = "%08x-%04x-%04x-%04x-%012" PRIx64;
 // Length of GUID string. Don't count the ending '\0'.
-#define kGUIDStringLength 36
+const size_t kGUIDStringLength = 36;
 
 // Create a guid.
 bool CreateGUID(GUID *guid);
 
 // Get the string from guid.
-bool GUIDToString(const GUID *guid, char *buf, int buf_len);
+bool GUIDToString(const GUID *guid, char *buf, size_t buf_len);
 
 #endif
--- a/toolkit/crashreporter/breakpad-client/linux/handler/minidump_descriptor.cc
+++ b/toolkit/crashreporter/breakpad-client/linux/handler/minidump_descriptor.cc
@@ -24,20 +24,19 @@
 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <stdio.h>
 
+#include "linux/handler/guid_generator.h"
 #include "linux/handler/minidump_descriptor.h"
 
-#include "common/linux/guid_creator.h"
-
 namespace google_breakpad {
 
 //static
 const MinidumpDescriptor::MicrodumpOnConsole
     MinidumpDescriptor::kMicrodumpOnConsole = {};
 
 MinidumpDescriptor::MinidumpDescriptor(const MinidumpDescriptor& descriptor)
     : mode_(descriptor.mode_),
--- a/toolkit/crashreporter/breakpad-client/linux/moz.build
+++ b/toolkit/crashreporter/breakpad-client/linux/moz.build
@@ -5,24 +5,29 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 UNIFIED_SOURCES += [
     'crash_generation/crash_generation_client.cc',
     'crash_generation/crash_generation_server.cc',
     'dump_writer_common/thread_info.cc',
     'dump_writer_common/ucontext_reader.cc',
     'handler/exception_handler.cc',
+    'handler/guid_generator.cc',
     'handler/minidump_descriptor.cc',
     'log/log.cc',
     'microdump_writer/microdump_writer.cc',
     'minidump_writer/linux_dumper.cc',
     'minidump_writer/linux_ptrace_dumper.cc',
     'minidump_writer/minidump_writer.cc',
 ]
 
+# On Linux we override the guid_creator.h header and use our own instead
+if CONFIG['OS_TARGET'] == 'Linux' or CONFIG['OS_TARGET'] == 'Android':
+    DEFINES['COMMON_LINUX_GUID_CREATOR_H__'] = 1
+
 if CONFIG['OS_TARGET'] == 'Android':
     LOCAL_INCLUDES += [
         '/toolkit/crashreporter/google-breakpad/src/common/android/include',
     ]
 
 # We allow warnings for third-party code that can be updated from upstream.
 ALLOW_COMPILER_WARNINGS = True
 
--- a/toolkit/crashreporter/google-breakpad/src/common/linux/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/common/linux/moz.build
@@ -1,17 +1,16 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 UNIFIED_SOURCES += [
     'elfutils.cc',
-    'guid_creator.cc',
     'linux_libc_support.cc',
     'memory_mapped_file.cc',
     'safe_readlink.cc',
 ]
 
 # file_id.cc cannot be built in unified mode because it uses a custom DISABLE_STL_WRAPPING
 SOURCES += [
     'file_id.cc',
@@ -24,17 +23,16 @@ if CONFIG['OS_TARGET'] != 'Android':
 
 HostLibrary('host_breakpad_linux_common_s')
 HOST_SOURCES += [
     'crc32.cc',
     'dump_symbols.cc',
     'elf_symbols_to_module.cc',
     'elfutils.cc',
     'file_id.cc',
-    'guid_creator.cc',
     'linux_libc_support.cc',
     'memory_mapped_file.cc',
 ]
 
 HOST_CXXFLAGS += [
     '-O2',
     '-g',
 ]
--- a/tools/profiler/moz.build
+++ b/tools/profiler/moz.build
@@ -55,17 +55,16 @@ if CONFIG['MOZ_GECKO_PROFILER']:
         # These files cannot be built in unified mode because of name clashes with mozglue headers on Android.
         SOURCES += [
             'core/shared-libraries-linux.cc',
         ]
         if not CONFIG['MOZ_CRASHREPORTER']:
             SOURCES += [
                 '/toolkit/crashreporter/google-breakpad/src/common/linux/elfutils.cc',
                 '/toolkit/crashreporter/google-breakpad/src/common/linux/file_id.cc',
-                '/toolkit/crashreporter/google-breakpad/src/common/linux/guid_creator.cc',
                 '/toolkit/crashreporter/google-breakpad/src/common/linux/linux_libc_support.cc',
                 '/toolkit/crashreporter/google-breakpad/src/common/linux/memory_mapped_file.cc',
             ]
         if CONFIG['CPU_ARCH'] == 'arm':
             SOURCES += [
                 'core/EHABIStackWalk.cpp',
             ]
     elif CONFIG['OS_TARGET'] == 'Darwin':