Bug 819839 - Part 2 - Print file name and line number if available in DMD report. r=njn
authorCatalin Iacob <iacobcatalin@gmail.com>
Fri, 29 Nov 2013 16:09:42 +0100
changeset 172794 f4bfed6175a104c64540a335de622501b9e6eab2
parent 172793 50e44ba526bdb8ca8bda75ee74defa4467bd3e71
child 172795 c120711ba3cabcd629304fa1088e93227b04c6a6
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs819839
milestone28.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 819839 - Part 2 - Print file name and line number if available in DMD report. r=njn
memory/replace/dmd/DMD.cpp
--- a/memory/replace/dmd/DMD.cpp
+++ b/memory/replace/dmd/DMD.cpp
@@ -602,44 +602,53 @@ class LocationService
   {
     static const void* const kUnused;
 
     const void* mPc;        // if mPc==kUnused, the entry is unused
     char*       mFunction;  // owned by the Entry;  may be null
     const char* mLibrary;   // owned by mLibraryStrings;  never null
                             //   in a non-empty entry is in use
     ptrdiff_t   mLOffset;
+    char*       mFileName;  // owned by the Entry; may be null
+    unsigned long mLineNo;
 
     Entry()
-      : mPc(kUnused), mFunction(nullptr), mLibrary(nullptr), mLOffset(0)
+      : mPc(kUnused), mFunction(nullptr), mLibrary(nullptr), mLOffset(0), mFileName(nullptr), mLineNo(0)
     {}
 
     ~Entry()
     {
       // We don't free mLibrary because it's externally owned.
       InfallibleAllocPolicy::free_(mFunction);
+      InfallibleAllocPolicy::free_(mFileName);
     }
 
-    void Replace(const void* aPc, const char* aFunction, const char* aLibrary,
-                 ptrdiff_t aLOffset)
+    void Replace(const void* aPc, const char* aFunction,
+                 const char* aLibrary, ptrdiff_t aLOffset,
+                 const char* aFileName, unsigned long aLineNo)
     {
       mPc = aPc;
 
       // Convert "" to nullptr.  Otherwise, make a copy of the name.
       InfallibleAllocPolicy::free_(mFunction);
       mFunction =
         !aFunction[0] ? nullptr : InfallibleAllocPolicy::strdup_(aFunction);
+      InfallibleAllocPolicy::free_(mFileName);
+      mFileName =
+        !aFileName[0] ? nullptr : InfallibleAllocPolicy::strdup_(aFileName);
+
 
       mLibrary = aLibrary;
       mLOffset = aLOffset;
+      mLineNo = aLineNo;
     }
 
     size_t SizeOfExcludingThis() {
       // Don't measure mLibrary because it's externally owned.
-      return MallocSizeOf(mFunction);
+      return MallocSizeOf(mFunction) + MallocSizeOf(mFileName);
     }
   };
 
   // A direct-mapped cache.  When doing a dump just after starting desktop
   // Firefox (which is similar to dumping after a longer-running session,
   // thanks to the limit on how many records we dump), a cache with 2^24
   // entries (which approximates an infinite-entry cache) has a ~91% hit rate.
   // A cache with 2^12 entries has a ~83% hit rate, and takes up ~85 KiB (on
@@ -686,32 +695,43 @@ public:
       StringTable::AddPtr p = mLibraryStrings.lookupForAdd(details.library);
       if (!p) {
         library = InfallibleAllocPolicy::strdup_(details.library);
         (void)mLibraryStrings.add(p, library);
       } else {
         library = *p;
       }
 
-      entry.Replace(aPc, details.function, library, details.loffset);
+      entry.Replace(aPc, details.function, library, details.loffset, details.filename, details.lineno);
 
     } else {
       mNumCacheHits++;
     }
 
     MOZ_ASSERT(entry.mPc == aPc);
 
+    uintptr_t entryPc = (uintptr_t)(entry.mPc);
     // Sometimes we get nothing useful.  Just print "???" for the entire entry
     // so that fix-linux-stack.pl doesn't complain about an empty filename.
     if (!entry.mFunction && !entry.mLibrary[0] && entry.mLOffset == 0) {
-      W("   ??? %p\n", entry.mPc);
+      W("   ??? 0x%x\n", entryPc);
     } else {
       // Use "???" for unknown functions.
-      W("   %s[%s +0x%X] %p\n", entry.mFunction ? entry.mFunction : "???",
-        entry.mLibrary, entry.mLOffset, entry.mPc);
+      char* entryFunction = entry.mFunction ? entry.mFunction : "???";
+      if (entry.mFileName) {
+        // On Windows we can get the filename and line number at runtime.
+        W("   %s (%s:%lu) 0x%x\n",
+          entryFunction, entry.mFileName, entry.mLineNo, entryPc);
+      } else {
+        // On Linux and Mac we cannot get the filename and line number at
+        // runtime, so we print the offset in a form that fix-linux-stack.pl and
+        // fix_macosx_stack.py can post-process.
+        W("   %s[%s +0x%X] 0x%x\n",
+          entryFunction, entry.mLibrary, entry.mLOffset, entryPc);
+      }
     }
   }
 
   size_t SizeOfIncludingThis()
   {
     size_t n = MallocSizeOf(this);
     for (uint32_t i = 0; i < kNumEntries; i++) {
       n += mEntries[i].SizeOfExcludingThis();