Bug 1350500 - Compute the breakpadId for Firefox libraries on Android by mapping them into memory. r?glandium draft
authorMarkus Stange <mstange@themasta.com>
Wed, 10 May 2017 16:40:53 -0400
changeset 575779 81b3327241c778fbdc1b5cf9903015281073d31d
parent 575778 446db90c41bd7c0fd640bcebca3aeb9084072b58
child 575780 0b19326cb7c45b3c3f561e42bc5722ecdfec1c08
push id58162
push userbmo:mstange@themasta.com
push dateWed, 10 May 2017 21:00:27 +0000
reviewersglandium
bugs1350500
milestone55.0a1
Bug 1350500 - Compute the breakpadId for Firefox libraries on Android by mapping them into memory. r?glandium MozReview-Commit-ID: 6OevthY6uWk
tools/profiler/core/shared-libraries-linux.cc
tools/profiler/moz.build
--- a/tools/profiler/core/shared-libraries-linux.cc
+++ b/tools/profiler/core/shared-libraries-linux.cc
@@ -25,16 +25,17 @@
 #include <algorithm>
 #include <dlfcn.h>
 #include <features.h>
 #include <sys/types.h>
 
 #if defined(GP_OS_linux)
 # include <link.h>      // dl_phdr_info
 #elif defined(GP_OS_android)
+# include "AutoObjectMapper.h"
 # include "ElfLoader.h" // dl_phdr_info
 extern "C" MOZ_EXPORT __attribute__((weak))
 int dl_iterate_phdr(
           int (*callback)(struct dl_phdr_info *info, size_t size, void *data),
           void *data);
 #else
 # error "Unexpected configuration"
 #endif
@@ -43,16 +44,29 @@ int dl_iterate_phdr(
 static std::string getId(const char *bin_name)
 {
   using namespace google_breakpad;
   using namespace std;
 
   PageAllocator allocator;
   auto_wasteful_vector<uint8_t, sizeof(MDGUID)> identifier(&allocator);
 
+#if defined(GP_OS_android)
+  if (nsCString(bin_name).Find("!/") != kNotFound) {
+    AutoObjectMapperFaultyLib mapper(nullptr);
+    void* image = nullptr;
+    size_t size = 0;
+    if (mapper.Map(&image, &size, bin_name) && image && size) {
+      if (FileID::ElfFileIdentifierFromMappedFile(image, identifier)) {
+        return FileID::ConvertIdentifierToUUIDString(identifier) + "0";
+      }
+    }
+  }
+#endif
+
   FileID file_id(bin_name);
   if (file_id.ElfFileIdentifier(identifier)) {
     return FileID::ConvertIdentifierToUUIDString(identifier) + "0";
   }
 
   return "";
 }
 
--- a/tools/profiler/moz.build
+++ b/tools/profiler/moz.build
@@ -91,16 +91,17 @@ if CONFIG['MOZ_GECKO_PROFILER']:
     ]
 
     if CONFIG['OS_TARGET'] == 'Android':
         DEFINES['ANDROID_NDK_MAJOR_VERSION'] = CONFIG['ANDROID_NDK_MAJOR_VERSION']
         DEFINES['ANDROID_NDK_MINOR_VERSION'] = CONFIG['ANDROID_NDK_MINOR_VERSION']
         LOCAL_INCLUDES += [
             # We need access to Breakpad's getcontext(3) which is suitable for Android
             '/toolkit/crashreporter/google-breakpad/src/common/android/include',
+            'lul',
         ]
 
     if not CONFIG['MOZ_CRASHREPORTER'] and CONFIG['OS_TARGET'] == 'Android':
         SOURCES += ['/toolkit/crashreporter/google-breakpad/src/common/android/breakpad_getcontext.S']
 
     if CONFIG['ANDROID_CPU_ARCH'] == 'armeabi':
         DEFINES['ARCH_ARMV6'] = True