Bug 855823 - Rely on breakpad finding file ids itself instead of relying on AddLibraryMapping caller to provide them. r=ted
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 09 Apr 2013 14:04:53 +0200
changeset 128500 39902799d11b6d81cee51ce5c8d9a8f899970130
parent 128499 a12537d6776557bae9ca76ccd4218bbc0c96af36
child 128501 2cc258f94ac011c3b8e911599d9b0ee745f3304f
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersted
bugs855823
milestone23.0a1
Bug 855823 - Rely on breakpad finding file ids itself instead of relying on AddLibraryMapping caller to provide them. r=ted
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/crashreporter/nsExceptionHandler.h
toolkit/xre/nsAndroidStartup.cpp
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -85,16 +85,19 @@ using mozilla::InjectCrashRunnable;
 #include <vector>
 
 #include "mozilla/mozalloc_oom.h"
 #include "mozilla/mozPoisonWrite.h"
 
 #if defined(XP_MACOSX)
 CFStringRef reporterClientAppID = CFSTR("org.mozilla.crashreporter");
 #endif
+#if defined(MOZ_WIDGET_ANDROID)
+#include "common/linux/file_id.h"
+#endif
 
 #include "nsIUUIDGenerator.h"
 
 using google_breakpad::CrashGenerationServer;
 using google_breakpad::ClientInfo;
 #ifdef XP_LINUX
 using google_breakpad::MinidumpDescriptor;
 #endif
@@ -342,40 +345,22 @@ static posix_spawnattr_t spawnattr;
 #endif
 
 #if defined(MOZ_WIDGET_ANDROID)
 // Android builds use a custom library loader,
 // so the embedding will provide a list of shared
 // libraries that are mapped into anonymous mappings.
 typedef struct {
   std::string name;
-  std::string debug_id;
   uintptr_t   start_address;
   size_t      length;
   size_t      file_offset;
 } mapping_info;
 static std::vector<mapping_info> library_mappings;
 typedef std::map<uint32_t,google_breakpad::MappingList> MappingMap;
-
-void FileIDToGUID(const char* file_id, u_int8_t guid[sizeof(MDGUID)])
-{
-  for (int i = 0; i < sizeof(MDGUID); i++) {
-    int c;
-    sscanf(file_id, "%02X", &c);
-    guid[i] = (u_int8_t)(c & 0xFF);
-    file_id += 2;
-  }
-  // GUIDs are stored in network byte order.
-  uint32_t* data1 = reinterpret_cast<uint32_t*>(guid);
-  *data1 = htonl(*data1);
-  uint16_t* data2 = reinterpret_cast<uint16_t*>(guid + 4);
-  *data2 = htons(*data2);
-  uint16_t* data3 = reinterpret_cast<uint16_t*>(guid + 6);
-  *data3 = htons(*data3);
-}
 #endif
 
 #ifdef XP_LINUX
 inline void
 my_inttostring(intmax_t t, char* buffer, size_t buffer_length)
 {
   my_memset(buffer, 0, buffer_length);
   my_uitos(buffer, t, my_uint_len(t));
@@ -1023,17 +1008,17 @@ nsresult SetExceptionHandler(nsIFile* aX
                                                         &keyExistsAndHasValidFormat);
   if (keyExistsAndHasValidFormat)
     showOSCrashReporter = prefValue;
 #endif
 
 #if defined(MOZ_WIDGET_ANDROID)
   for (unsigned int i = 0; i < library_mappings.size(); i++) {
     u_int8_t guid[sizeof(MDGUID)];
-    FileIDToGUID(library_mappings[i].debug_id.c_str(), guid);
+    google_breakpad::FileID::ElfFileIdentifierFromMappedFile((void const *)library_mappings[i].start_address, guid);
     gExceptionHandler->AddMappingInfo(library_mappings[i].name,
                                       guid,
                                       library_mappings[i].start_address,
                                       library_mappings[i].length,
                                       library_mappings[i].file_offset);
   }
 #endif
 
@@ -2819,33 +2804,31 @@ UnsetRemoteExceptionHandler()
 {
   delete gExceptionHandler;
   gExceptionHandler = NULL;
   return true;
 }
 
 #if defined(MOZ_WIDGET_ANDROID)
 void AddLibraryMapping(const char* library_name,
-                       const char* file_id,
                        uintptr_t   start_address,
                        size_t      mapping_length,
                        size_t      file_offset)
 {
   if (!gExceptionHandler) {
     mapping_info info;
     info.name = library_name;
-    info.debug_id = file_id;
     info.start_address = start_address;
     info.length = mapping_length;
     info.file_offset = file_offset;
     library_mappings.push_back(info);
   }
   else {
     u_int8_t guid[sizeof(MDGUID)];
-    FileIDToGUID(file_id, guid);
+    google_breakpad::FileID::ElfFileIdentifierFromMappedFile((void const *)start_address, guid);
     gExceptionHandler->AddMappingInfo(library_name,
                                       guid,
                                       start_address,
                                       mapping_length,
                                       file_offset);
   }
 }
 #endif
--- a/toolkit/crashreporter/nsExceptionHandler.h
+++ b/toolkit/crashreporter/nsExceptionHandler.h
@@ -181,17 +181,16 @@ bool UnsetRemoteExceptionHandler();
 
 #if defined(MOZ_WIDGET_ANDROID)
 // Android builds use a custom library loader, so /proc/<pid>/maps
 // will just show anonymous mappings for all the non-system
 // shared libraries. This API is to work around that by providing
 // info about the shared libraries that are mapped into these anonymous
 // mappings.
 void AddLibraryMapping(const char* library_name,
-                       const char* file_id,
                        uintptr_t   start_address,
                        size_t      mapping_length,
                        size_t      file_offset);
 
 #endif
 }
 
 #endif /* nsExceptionHandler_h__ */
--- a/toolkit/xre/nsAndroidStartup.cpp
+++ b/toolkit/xre/nsAndroidStartup.cpp
@@ -42,17 +42,17 @@ struct AutoAttachJavaThread {
 };
 
 extern "C" NS_EXPORT void
 GeckoStart(void *data, const nsXREAppData *appData)
 {
 #ifdef MOZ_CRASHREPORTER
     const struct mapping_info *info = getLibraryMapping();
     while (info->name) {
-      CrashReporter::AddLibraryMapping(info->name, info->file_id, info->base,
+      CrashReporter::AddLibraryMapping(info->name, info->base,
                                        info->len, info->offset);
       info++;
     }
 #endif
 
     AutoAttachJavaThread attacher;
     if (!attacher.attached)
         return;