Bug 1293501 - Add some more crash annotations to dianose bug 1145613. r?mcmanus draft
authorTing-Yu Chou <janus926@gmail.com>
Fri, 26 Aug 2016 10:08:18 +0800
changeset 405919 0b46bb02b5c4d948dc07fcbdbd51375d72ad19f4
parent 405855 a551f534773cf2d6933f78ce7d82a7a33a99643e
child 410868 d6e0f08e43996e3058917e2bb5e81f3fd1e84210
push id27598
push userbmo:janus926@gmail.com
push dateFri, 26 Aug 2016 03:49:34 +0000
reviewersmcmanus
bugs1293501, 1145613
milestone51.0a1
Bug 1293501 - Add some more crash annotations to dianose bug 1145613. r?mcmanus MozReview-Commit-ID: 4hsrKYlV0ER
netwerk/protocol/http/nsHttpRequestHead.cpp
netwerk/protocol/http/nsHttpRequestHead.h
--- a/netwerk/protocol/http/nsHttpRequestHead.cpp
+++ b/netwerk/protocol/http/nsHttpRequestHead.cpp
@@ -14,23 +14,54 @@
 
 //-----------------------------------------------------------------------------
 // nsHttpRequestHead
 //-----------------------------------------------------------------------------
 
 namespace mozilla {
 namespace net {
 
+#ifdef MOZ_CRASHREPORTER
+
+void nsHttpRequestHead::DbgReentrantMonitorAutoEnter::DbgCheck(bool aIn)
+{
+    nsHttpAtom header;
+    if (!mInstance.mAnnotated && mInstance.mHeaders.Count() &&
+        !mInstance.mHeaders.PeekHeaderAt(0, header)) {
+        nsAutoCString str;
+        str.Append(nsPrintfCString("%s %s", aIn ? "in" : "out", mFunc));
+        // Output the content of the array header and the first nsEntry.
+        const uint8_t* p = reinterpret_cast<uint8_t*>
+            (mInstance.mHeaders.mHeaders.Elements()) - sizeof(nsTArrayHeader);
+        for (int i = 0; i < 28; ++i, ++p) {
+            str.Append(nsPrintfCString(" %02x", *p));
+        }
+        CrashReporter::AnnotateCrashReport(
+            NS_LITERAL_CSTRING("InvalidHttpHeaderArray"), str);
+        // Make sure we annotate only when we found it is invalid at the first
+        // time.
+        mInstance.mAnnotated = true;
+    }
+}
+
+#define ReentrantMonitorAutoEnter DbgReentrantMonitorAutoEnter
+#define mon(x) mon(*this, __func__)
+
+#endif
+
 nsHttpRequestHead::nsHttpRequestHead()
     : mMethod(NS_LITERAL_CSTRING("GET"))
     , mVersion(NS_HTTP_VERSION_1_1)
     , mParsedMethod(kMethod_Get)
     , mHTTPS(false)
     , mReentrantMonitor("nsHttpRequestHead.mReentrantMonitor")
     , mInVisitHeaders(false)
+#ifdef MOZ_CRASHREPORTER
+    , mAnnotated(false)
+#endif
 {
     MOZ_COUNT_CTOR(nsHttpRequestHead);
 }
 
 nsHttpRequestHead::~nsHttpRequestHead()
 {
     MOZ_COUNT_DTOR(nsHttpRequestHead);
 }
@@ -44,32 +75,16 @@ nsHttpRequestHead::Headers() const
     curr.mReentrantMonitor.AssertCurrentThreadIn();
     return mHeaders;
 }
 
 void
 nsHttpRequestHead::SetHeaders(const nsHttpHeaderArray& aHeaders)
 {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-#ifdef MOZ_CRASHREPORTER
-    nsHttpAtom header;
-    if (mHeaders.Count() && !mHeaders.PeekHeaderAt(0, header)) {
-      nsAutoCString str;
-      const uint8_t* p = reinterpret_cast<uint8_t*>(mHeaders.mHeaders.Elements()) -
-                         sizeof(nsTArrayHeader);
-      for (int i = 0; i < 48; ++i, ++p) {
-        str.Append(nsPrintfCString("%02x ", *p));
-      }
-      CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("HttpHeaderArray"), str);
-      if (header._val) {
-        CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("HttpHeaderArray[0].header"),
-                                           nsDependentCString(header._val));
-      }
-    }
-#endif
     mHeaders = aHeaders;
 }
 
 void
 nsHttpRequestHead::SetVersion(nsHttpVersion version)
 {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     mVersion = version;
@@ -133,17 +148,17 @@ nsHttpRequestHead::Path(nsACString &aPat
 {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     aPath = mPath.IsEmpty() ? mRequestURI : mPath;
 }
 
 void
 nsHttpRequestHead::SetHTTPS(bool val)
 {
-    ReentrantMonitorAutoEnter monk(mReentrantMonitor);
+    ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     mHTTPS = val;
 }
 
 void
 nsHttpRequestHead::Origin(nsACString &aOrigin)
 {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     aOrigin = mOrigin;
@@ -379,10 +394,15 @@ nsHttpRequestHead::Flatten(nsACString &b
         buf.AppendLiteral("1.0");
     }
 
     buf.AppendLiteral("\r\n");
 
     mHeaders.Flatten(buf, pruneProxyHeaders, false);
 }
 
+#ifdef MOZ_CRASHREPORTER
+#undef ReentrantMonitorAutoEnter
+#undef mon
+#endif
+
 } // namespace net
 } // namespace mozilla
--- a/netwerk/protocol/http/nsHttpRequestHead.h
+++ b/netwerk/protocol/http/nsHttpRequestHead.h
@@ -115,14 +115,41 @@ private:
     bool              mHTTPS;
 
     // We are using ReentrantMonitor instead of a Mutex because VisitHeader
     // function calls nsIHttpHeaderVisitor::VisitHeader while under lock.
     ReentrantMonitor  mReentrantMonitor;
 
     // During VisitHeader we sould not allow cal to SetHeader.
     bool mInVisitHeaders;
+
+#ifdef MOZ_CRASHREPORTER
+    class DbgReentrantMonitorAutoEnter : ReentrantMonitorAutoEnter
+    {
+    public:
+        explicit DbgReentrantMonitorAutoEnter(nsHttpRequestHead& aInstance,
+                                              const char* aFunc)
+            : ReentrantMonitorAutoEnter(aInstance.mReentrantMonitor),
+              mInstance(aInstance),
+              mFunc(aFunc)
+        {
+            DbgCheck(true);
+        }
+        ~DbgReentrantMonitorAutoEnter(void)
+        {
+            DbgCheck(false);
+        }
+
+    private:
+        void DbgCheck(bool aIn);
+
+        nsHttpRequestHead& mInstance;
+        const char* mFunc;
+    };
+
+    bool mAnnotated;
+#endif
 };
 
 } // namespace net
 } // namespace mozilla
 
 #endif // nsHttpRequestHead_h__