Bug 818626 - More debugging for crashes at the end of printing. r=roc
authorCameron McCormack <cam@mcc.id.au>
Mon, 07 Jan 2013 14:29:47 +1100
changeset 126997 fc560784e6cd519b432189aa89bdc9227304547f
parent 126996 29fd39e0dde66646b0688c87b82d44aed79ca1ed
child 126998 d86f67959794702f4fa90cea6bbb54731029a2e3
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs818626
milestone20.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 818626 - More debugging for crashes at the end of printing. r=roc
layout/printing/nsPrintData.cpp
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintObject.cpp
--- a/layout/printing/nsPrintData.cpp
+++ b/layout/printing/nsPrintData.cpp
@@ -111,16 +111,76 @@ AssertPresShellsAndContextsSane(nsPrintO
     ASSERT_AND_NOTE("print object has mismatching pres shell and pres context");
   }
 
   for (uint32_t i = 0; i < aPO->mKids.Length(); i++) {
     AssertPresShellsAndContextsSane(aPO->mKids[i], aPresShells, aPresContexts);
   }
 }
 
+#ifdef MOZ_CRASHREPORTER
+static void
+AppendBoolean(nsCString& aString, bool aValue)
+{
+  if (aValue) {
+    aString.AppendLiteral("true");
+  } else {
+    aString.AppendLiteral("false");
+  }
+}
+
+static void
+NotePrintObjectTree(nsPrintObject* aPO, int32_t aDepth)
+{
+  nsCString note;
+  for (int32_t i = 0; i < aDepth; i++) {
+    note.AppendLiteral("  ");
+  }
+  note.AppendInt(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(aPO)), 16);
+  note.AppendLiteral(" = { mFrameType = ");
+  note.AppendInt(aPO->mFrameType);
+  note.AppendLiteral(", mHasBeenPrinted = ");
+  AppendBoolean(note, aPO->mHasBeenPrinted);
+  note.AppendLiteral(", mDontPrint = ");
+  AppendBoolean(note, aPO->mDontPrint);
+  note.AppendLiteral(", mPrintAsIs = ");
+  AppendBoolean(note, aPO->mPrintAsIs);
+  note.AppendLiteral(", mInvisible = ");
+  AppendBoolean(note, aPO->mInvisible);
+  note.AppendLiteral(", mPrintPreview = ");
+  AppendBoolean(note, aPO->mPrintPreview);
+  note.AppendLiteral(", mDidCreateDocShell = ");
+  AppendBoolean(note, aPO->mDidCreateDocShell);
+  note.AppendLiteral(", mShrinkRatio = ");
+  note.AppendFloat(aPO->mShrinkRatio);
+  note.AppendLiteral(", mZoomRatio = ");
+  note.AppendFloat(aPO->mZoomRatio);
+  note.AppendLiteral(", mContent = ");
+  if (aPO->mContent) {
+    nsString tag;
+    aPO->mContent->Tag()->ToString(tag);
+    LossyAppendUTF16toASCII(tag, note);
+  } else {
+    note.AppendLiteral("null");
+  }
+  note.AppendLiteral(" }\n");
+  CrashReporter::AppendAppNotesToCrashReport(note);
+  for (uint32_t i = 0; i < aPO->mKids.Length(); i++) {
+    NotePrintObjectTree(aPO->mKids[i], aDepth + 1);
+  }
+}
+
+static void
+NotePrintObjectTree(nsPrintObject* aPO)
+{
+  CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("Print object tree:\n"));
+  NotePrintObjectTree(aPO, 1);
+}
+#endif
+
 #undef ASSERT_AND_NOTE
 
 static void
 AssertPresShellsAndContextsSane(nsPrintObject* aPO)
 {
   nsTArray<nsIPresShell*> presShells;
   nsTArray<nsPresContext*> presContexts;
   AssertPresShellsAndContextsSane(aPO, presShells, presContexts);
@@ -155,16 +215,19 @@ nsPrintData::~nsPrintData()
       }
       if (NS_FAILED(rv)) {
         // XXX nsPrintData::ShowPrintErrorDialog(rv);
       }
     }
   }
 
   AssertPresShellsAndContextsSane(mPrintObject);
+#ifdef MOZ_CRASHREPORTER
+  NotePrintObjectTree(mPrintObject);
+#endif
   delete mPrintObject;
 
   if (mBrandName) {
     NS_Free(mBrandName);
   }
 }
 
 void nsPrintData::OnStartPrinting()
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -119,16 +119,20 @@ static const char kPrintingPromptService
 
 #include "nsFocusManager.h"
 #include "nsRange.h"
 #include "nsCDefaultURIFixup.h"
 #include "nsIURIFixup.h"
 #include "mozilla/dom/Element.h"
 #include "nsContentList.h"
 
+#ifdef MOZ_CRASHREPORTER
+#include "nsExceptionHandler.h"
+#endif
+
 using namespace mozilla;
 using namespace mozilla::dom;
 
 //-----------------------------------------------------
 // PR LOGGING
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #endif
@@ -1525,16 +1529,19 @@ nsresult nsPrintEngine::CleanupOnFailure
    * 
    * When rv == NS_ERROR_ABORT, it means we want out of the 
    * print job without displaying any error messages
    */
   if (aResult != NS_ERROR_ABORT) {
     ShowPrintErrorDialog(aResult, aIsPrinting);
   }
 
+#ifdef MOZ_CRASHREPORTER
+  CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("Unsuccessful print.\n"));
+#endif
   FirePrintCompletionEvent();
 
   return aResult;
 
 }
 
 //---------------------------------------------------------------------
 void
@@ -3165,16 +3172,19 @@ nsPrintEngine::DonePrintingPages(nsPrint
     bool didPrint = PrintDocContent(mPrt->mPrintObject, rv);
     if (NS_SUCCEEDED(rv) && didPrint) {
       PR_PL(("****** In DV::DonePrintingPages PO: %p (%s) didPrint:%s (Not Done Printing)\n", aPO, gFrameTypesStr[aPO->mFrameType], PRT_YESNO(didPrint)));
       return false;
     }
   }
 
   if (NS_SUCCEEDED(aResult)) {
+#ifdef MOZ_CRASHREPORTER
+    CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("Successful print.\n"));
+#endif
     FirePrintCompletionEvent();
   }
 
   TurnScriptingOn(true);
   SetIsPrinting(false);
 
   // Release reference to mPagePrintTimer; the timer object destroys itself
   // after this returns true
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -9,16 +9,20 @@
 #include "nsContentUtils.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsGkAtoms.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIBaseWindow.h"
                                                    
+#ifdef MOZ_CRASHREPORTER
+#include "nsExceptionHandler.h"
+#endif
+
 //---------------------------------------------------
 //-- nsPrintObject Class Impl
 //---------------------------------------------------
 nsPrintObject::nsPrintObject() :
   mContent(nullptr), mFrameType(eFrame), mParent(nullptr),
   mHasBeenPrinted(false), mDontPrint(true), mPrintAsIs(false),
   mInvisible(false), mDidCreateDocShell(false),
   mShrinkRatio(1.0), mZoomRatio(1.0)
@@ -96,16 +100,22 @@ nsPrintObject::Init(nsIDocShell* aDocShe
 }
 
 //------------------------------------------------------------------
 // Resets PO by destroying the presentation
 void 
 nsPrintObject::DestroyPresentation()
 {
   if (mPresShell) {
+#ifdef MOZ_CRASHREPORTER
+    if (mPresShell->GetPresContext() && !mPresShell->GetPresContext()->GetPresShell()) {
+      NS_ASSERTION(false, "about to destroy print object's PresShell when its pres context no longer has it");
+      CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("about to destroy print object's PresShell when its pres context no longer has it\n"));
+    }
+#endif
     mPresShell->EndObservingDocument();
     nsAutoScriptBlocker scriptBlocker;
     mPresShell->Destroy();
   }
   mPresContext = nullptr;
   mPresShell   = nullptr;
   mViewManager = nullptr;
 }