Bug 1329111 - Supply SharedLibraryInfo with the absolute module path and debug path on all platforms. r?marco draft
authorMarkus Stange <mstange@themasta.com>
Tue, 14 Mar 2017 17:09:10 -0400
changeset 498492 383cb5a14c513bc1da1ddb04b2841c9767bca1bb
parent 498491 55874a3790c8fef7aa258add63e6f8636b2dd837
child 498493 b6054b54356373652ed01b95bdad48d52590e637
push id49211
push userbmo:mstange@themasta.com
push dateTue, 14 Mar 2017 21:26:46 +0000
reviewersmarco
bugs1329111
milestone55.0a1
Bug 1329111 - Supply SharedLibraryInfo with the absolute module path and debug path on all platforms. r?marco MozReview-Commit-ID: 9R3ecPxGoMr
tools/profiler/core/shared-libraries-linux.cc
tools/profiler/core/shared-libraries-macos.cc
tools/profiler/core/shared-libraries-win32.cc
tools/profiler/public/shared-libraries.h
--- a/tools/profiler/core/shared-libraries-linux.cc
+++ b/tools/profiler/core/shared-libraries-linux.cc
@@ -78,25 +78,28 @@ dl_iterate_callback(struct dl_phdr_info 
     unsigned long end = start + dl_info->dlpi_phdr[i].p_memsz;
     if (start < libStart)
       libStart = start;
     if (end > libEnd)
       libEnd = end;
   }
   const char *path = dl_info->dlpi_name;
 
-  nsAutoString nameStr;
-  mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(path), nameStr)));
+  nsAutoString pathStr;
+  mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(path), pathStr)));
 
+  nsAutoString nameStr = pathStr;
   int32_t pos = nameStr.RFindChar('/');
   if (pos != kNotFound) {
     nameStr.Cut(0, pos + 1);
   }
 
-  SharedLibrary shlib(libStart, libEnd, 0, getId(path), nameStr, nameStr, "");
+  SharedLibrary shlib(libStart, libEnd, 0, getId(path),
+                      nameStr, pathStr, nameStr, pathStr,
+                      "");
   info.AddSharedLibrary(shlib);
 
   return 0;
 }
 
 #endif // !MOZ_WIDGET_GONK
 
 SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
@@ -153,25 +156,28 @@ SharedLibraryInfo SharedLibraryInfo::Get
     if (strcmp(perm, "r-xp") != 0) {
       // Ignore entries that are writable and/or shared.
       // At least one graphics driver uses short-lived "rwxs" mappings
       // (see bug 926734 comment 5), so just checking for 'x' isn't enough.
       continue;
     }
 #endif
 
-    nsAutoString nameStr;
-    mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(modulePath), nameStr)));
+    nsAutoString pathStr;
+    mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(modulePath), pathStr)));
 
+    nsAutoString nameStr = pathStr;
     int32_t pos = nameStr.RFindChar('/');
     if (pos != kNotFound) {
       nameStr.Cut(0, pos + 1);
     }
 
-    SharedLibrary shlib(start, end, offset, getId(name), nameStr, nameStr, "");
+    SharedLibrary shlib(start, end, offset, getId(path),
+                        nameStr, pathStr, nameStr, pathStr,
+                        "");
     info.AddSharedLibrary(shlib);
     if (count > 10000) {
       LOG("Get maps failed");
       break;
     }
     count++;
   }
 #endif // defined(GP_OS_android) || defined(MOZ_WIDGET_GONK)
--- a/tools/profiler/core/shared-libraries-macos.cc
+++ b/tools/profiler/core/shared-libraries-macos.cc
@@ -67,26 +67,28 @@ void addSharedLibrary(const platform_mac
   if (uuid_bytes != nullptr) {
     for (int i = 0; i < 16; ++i) {
       uuid << ((uuid_bytes[i] & 0xf0) >> 4);
       uuid << (uuid_bytes[i] & 0xf);
     }
     uuid << '0';
   }
 
-  nsAutoString nameStr;
-  mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(path), nameStr)));
+  nsAutoString pathStr;
+  mozilla::Unused << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(nsDependentCString(path), pathStr)));
 
+  nsAutoString nameStr = pathStr;
   int32_t pos = nameStr.RFindChar('/');
   if (pos != kNotFound) {
     nameStr.Cut(0, pos + 1);
   }
 
   info.AddSharedLibrary(SharedLibrary(start, start + size, 0, uuid.str(),
-                                      nameStr, nameStr, ""));
+                                      nameStr, pathStr, nameStr, pathStr,
+                                      ""));
 }
 
 // Use dyld to inspect the macho image information. We can build the SharedLibraryEntry structure
 // giving us roughtly the same info as /proc/PID/maps in Linux.
 SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
 {
   SharedLibraryInfo sharedLibraryInfo;
 
--- a/tools/profiler/core/shared-libraries-win32.cc
+++ b/tools/profiler/core/shared-libraries-win32.cc
@@ -130,16 +130,17 @@ SharedLibraryInfo SharedLibraryInfo::Get
     if (modulesSize / sizeof(HMODULE) < modulesNum) {
       modulesNum = modulesSize / sizeof(HMODULE);
     }
   }
 
   for (unsigned int i = 0; i < modulesNum; i++) {
     nsID pdbSig;
     uint32_t pdbAge;
+    nsAutoString pdbPathStr;
     nsAutoString pdbNameStr;
     char *pdbName = NULL;
     std::string breakpadId;
     WCHAR modulePath[MAX_PATH + 1];
 
     if (!GetModuleFileNameEx(hProcess, hMods[i], modulePath, sizeof(modulePath) / sizeof(WCHAR))) {
       continue;
     }
@@ -170,35 +171,39 @@ SharedLibraryInfo SharedLibraryInfo::Get
       stream << pdbSig.ToString() << std::hex << pdbAge;
       breakpadId = stream.str();
       std::string::iterator end =
         std::remove_if(breakpadId.begin(), breakpadId.end(), IsDashOrBraces);
       breakpadId.erase(end, breakpadId.end());
       std::transform(breakpadId.begin(), breakpadId.end(),
         breakpadId.begin(), toupper);
 
-      pdbNameStr = NS_ConvertUTF8toUTF16(pdbName);
+      pdbPathStr = NS_ConvertUTF8toUTF16(pdbName);
+      pdbNameStr = pdbPathStr;
       int32_t pos = pdbNameStr.RFindChar('\\');
       if (pos != kNotFound) {
         pdbNameStr.Cut(0, pos + 1);
       }
     }
 
-    nsAutoString moduleNameStr(modulePath);
+    nsAutoString modulePathStr(modulePath);
+    nsAutoString moduleNameStr = modulePathStr;
     int32_t pos = moduleNameStr.RFindChar('\\');
     if (pos != kNotFound) {
       moduleNameStr.Cut(0, pos + 1);
     }
 
     SharedLibrary shlib((uintptr_t)module.lpBaseOfDll,
       (uintptr_t)module.lpBaseOfDll + module.SizeOfImage,
       0, // DLLs are always mapped at offset 0 on Windows
       breakpadId,
       moduleNameStr,
+      modulePathStr,
       pdbNameStr,
+      pdbPathStr,
       GetVersion(modulePath));
     sharedLibraryInfo.AddSharedLibrary(shlib);
 
     FreeLibrary(handleLock); // ok to free null handles
   }
 
   return sharedLibraryInfo;
 }
--- a/tools/profiler/public/shared-libraries.h
+++ b/tools/profiler/public/shared-libraries.h
@@ -23,87 +23,101 @@
 class SharedLibrary {
 public:
 
   SharedLibrary(uintptr_t aStart,
                 uintptr_t aEnd,
                 uintptr_t aOffset,
                 const std::string& aBreakpadId,
                 const nsString& aModuleName,
+                const nsString& aModulePath,
                 const nsString& aDebugName,
+                const nsString& aDebugPath,
                 const std::string& aVersion)
     : mStart(aStart)
     , mEnd(aEnd)
     , mOffset(aOffset)
     , mBreakpadId(aBreakpadId)
     , mModuleName(aModuleName)
+    , mModulePath(aModulePath)
     , mDebugName(aDebugName)
+    , mDebugPath(aDebugPath)
     , mVersion(aVersion)
   {}
 
   SharedLibrary(const SharedLibrary& aEntry)
     : mStart(aEntry.mStart)
     , mEnd(aEntry.mEnd)
     , mOffset(aEntry.mOffset)
     , mBreakpadId(aEntry.mBreakpadId)
     , mModuleName(aEntry.mModuleName)
+    , mModulePath(aEntry.mModulePath)
     , mDebugName(aEntry.mDebugName)
+    , mDebugPath(aEntry.mDebugPath)
     , mVersion(aEntry.mVersion)
   {}
 
   SharedLibrary& operator=(const SharedLibrary& aEntry)
   {
     // Gracefully handle self assignment
     if (this == &aEntry) return *this;
 
     mStart = aEntry.mStart;
     mEnd = aEntry.mEnd;
     mOffset = aEntry.mOffset;
     mBreakpadId = aEntry.mBreakpadId;
     mModuleName = aEntry.mModuleName;
+    mModulePath = aEntry.mModulePath;
     mDebugName = aEntry.mDebugName;
+    mDebugPath = aEntry.mDebugPath;
     mVersion = aEntry.mVersion;
     return *this;
   }
 
   bool operator==(const SharedLibrary& other) const
   {
     return (mStart == other.mStart) &&
            (mEnd == other.mEnd) &&
            (mOffset == other.mOffset) &&
            (mModuleName == other.mModuleName) &&
+           (mModulePath == other.mModulePath) &&
            (mDebugName == other.mDebugName) &&
+           (mDebugPath == other.mDebugPath) &&
            (mBreakpadId == other.mBreakpadId) &&
            (mVersion == other.mVersion);
   }
 
   uintptr_t GetStart() const { return mStart; }
   uintptr_t GetEnd() const { return mEnd; }
   uintptr_t GetOffset() const { return mOffset; }
   const std::string &GetBreakpadId() const { return mBreakpadId; }
   const nsString &GetModuleName() const { return mModuleName; }
+  const nsString &GetModulePath() const { return mModulePath; }
   const std::string GetNativeDebugName() const {
     nsAutoCString debugNameStr;
 
     NS_CopyUnicodeToNative(mDebugName, debugNameStr);
 
     return debugNameStr.get();
   }
   const nsString &GetDebugName() const { return mDebugName; }
+  const nsString &GetDebugPath() const { return mDebugPath; }
   const std::string &GetVersion() const { return mVersion; }
 
 private:
   SharedLibrary() {}
 
   uintptr_t mStart;
   uintptr_t mEnd;
   uintptr_t mOffset;
   std::string mBreakpadId;
   nsString mModuleName;
+  nsString mModulePath;
   nsString mDebugName;
+  nsString mDebugPath;
   std::string mVersion;
 };
 
 static bool
 CompareAddresses(const SharedLibrary& first, const SharedLibrary& second)
 {
   return first.GetStart() < second.GetStart();
 }