Bug 724072 - If using a content process, display the pid and "parent"/"child" along with each NS_WARNING. r=bsmedberg
authorJustin Lebar <justin.lebar@gmail.com>
Tue, 10 Apr 2012 15:57:20 -0400
changeset 94664 91bbeb1c518702477e5a456474fe8ef5991f4a91
parent 94663 43cd822084b3e681cf81abf972b1f6457235d4a4
child 94665 0fd099d86cc1398e9f4cf9b88ea5b29e44cb0c54
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs724072
milestone14.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 724072 - If using a content process, display the pid and "parent"/"child" along with each NS_WARNING. r=bsmedberg
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
xpcom/base/nsDebugImpl.cpp
xpcom/base/nsDebugImpl.h
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -71,16 +71,17 @@
 #include "nsIObserver.h"
 #include "nsServiceManagerUtils.h"
 #include "nsXULAppAPI.h"
 #include "nsWeakReference.h"
 #include "nsIScriptError.h"
 #include "nsIConsoleService.h"
 #include "nsJSEnvironment.h"
 #include "SandboxHal.h"
+#include "nsDebugImpl.h"
 
 #include "History.h"
 #include "nsDocShellCID.h"
 #include "nsNetUtil.h"
 
 #include "base/message_loop.h"
 #include "base/task.h"
 
@@ -232,16 +233,19 @@ ConsoleListener::Observe(nsIConsoleMessa
 ContentChild* ContentChild::sSingleton;
 
 ContentChild::ContentChild()
 #ifdef ANDROID
  : mScreenSize(0, 0)
  , mID(PRUint64(-1))
 #endif
 {
+    // This process is a content process, so it's clearly running in
+    // multiprocess mode!
+    nsDebugImpl::SetMultiprocessMode("Child");
 }
 
 ContentChild::~ContentChild()
 {
     delete gIndexedDBPath;
     gIndexedDBPath = nsnull;
 }
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -106,16 +106,17 @@
 #ifdef MOZ_WIDGET_ANDROID
 #include "AndroidBridge.h"
 #endif
 
 #include "nsIClipboard.h"
 #include "nsWidgetsCID.h"
 #include "nsISupportsPrimitives.h"
 #include "mozilla/dom/sms/SmsParent.h"
+#include "nsDebugImpl.h"
 
 static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
 static const char* sClipboardTextFlavors[] = { kUnicodeMime };
 
 using mozilla::Preferences;
 using namespace mozilla::ipc;
 using namespace mozilla::hal_sandbox;
 using namespace mozilla::net;
@@ -405,16 +406,20 @@ ContentParent::GetTestShellSingleton()
 
 ContentParent::ContentParent()
     : mGeolocationWatchID(-1)
     , mRunToCompletionDepth(0)
     , mShouldCallUnblockChild(false)
     , mIsAlive(true)
     , mSendPermissionUpdates(false)
 {
+    // From this point on, NS_WARNING, NS_ASSERTION, etc. should print out the
+    // PID along with the warning.
+    nsDebugImpl::SetMultiprocessMode("Parent");
+
     NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
     mSubprocess = new GeckoChildProcessHost(GeckoProcessType_Content);
     mSubprocess->AsyncLaunch();
     Open(mSubprocess->GetChannel(), mSubprocess->GetChildProcessHandle());
     unused << SendSetID(gContentChildID++);
 
     nsCOMPtr<nsIChromeRegistry> registrySvc = nsChromeRegistry::GetService();
     nsChromeRegistryChrome* chromeRegistry =
--- a/xpcom/base/nsDebugImpl.cpp
+++ b/xpcom/base/nsDebugImpl.cpp
@@ -33,16 +33,19 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+// Chromium headers must come before Mozilla headers.
+#include "base/process_util.h"
+
 #include "nsDebugImpl.h"
 #include "nsDebug.h"
 #ifdef MOZ_CRASHREPORTER
 # include "nsExceptionHandler.h"
 #endif
 #include "nsStringGlue.h"
 #include "prprf.h"
 #include "prlog.h"
@@ -95,16 +98,21 @@ Break(const char *aMsg);
 #if defined(_WIN32)
 #include <windows.h>
 #include <signal.h>
 #include <malloc.h> // for _alloca
 #elif defined(XP_UNIX)
 #include <stdlib.h>
 #endif
 
+using namespace mozilla;
+
+static bool sIsMultiprocess = false;
+static const char *sMultiprocessDescription = NULL;
+
 static PRInt32 gAssertionCount = 0;
 
 NS_IMPL_QUERY_INTERFACE2(nsDebugImpl, nsIDebug, nsIDebug2)
 
 NS_IMETHODIMP_(nsrefcnt)
 nsDebugImpl::AddRef()
 {
   return 2;
@@ -158,16 +166,23 @@ nsDebugImpl::GetIsDebugBuild(bool* aResu
 
 NS_IMETHODIMP
 nsDebugImpl::GetAssertionCount(PRInt32* aResult)
 {
   *aResult = gAssertionCount;
   return NS_OK;
 }
 
+/* static */ void
+nsDebugImpl::SetMultiprocessMode(const char *aDesc)
+{
+  sIsMultiprocess = true;
+  sMultiprocessDescription = aDesc;
+}
+
 /**
  * Implementation of the nsDebug methods. Note that this code is
  * always compiled in, in case some other module that uses it is
  * compiled with debugging even if this library is not.
  */
 static PRLogModuleInfo* gDebugLog;
 
 static void InitLog(void)
@@ -283,29 +298,43 @@ NS_DebugBreak(PRUint32 aSeverity, const 
      sevString = "###!!! ABORT";
      ll = PR_LOG_ALWAYS;
      break;
 
    default:
      aSeverity = NS_DEBUG_WARNING;
    };
 
-   PR_sxprintf(StuffFixedBuffer, &buf, "%s: ", sevString);
+#  define PrintToBuffer(...) PR_sxprintf(StuffFixedBuffer, &buf, __VA_ARGS__)
+
+   // If we're multiprocess, print "[PID]" or "[Desc PID]" at the beginning of
+   // the message.
+   if (sIsMultiprocess) {
+     PrintToBuffer("[");
+     if (sMultiprocessDescription) {
+       PrintToBuffer("%s ", sMultiprocessDescription);
+     }
+     PrintToBuffer("%d] ", base::GetCurrentProcId());
+   }
+
+   PrintToBuffer("%s: ", sevString);
 
    if (aStr)
-     PR_sxprintf(StuffFixedBuffer, &buf, "%s: ", aStr);
+     PrintToBuffer("%s: ", aStr);
 
    if (aExpr)
-     PR_sxprintf(StuffFixedBuffer, &buf, "'%s', ", aExpr);
+     PrintToBuffer("'%s', ", aExpr);
 
    if (aFile)
-     PR_sxprintf(StuffFixedBuffer, &buf, "file %s, ", aFile);
+     PrintToBuffer("file %s, ", aFile);
 
    if (aLine != -1)
-     PR_sxprintf(StuffFixedBuffer, &buf, "line %d", aLine);
+     PrintToBuffer("line %d", aLine);
+
+#  undef PrintToBuffer
 
    // Write out the message to the debug log
    PR_LOG(gDebugLog, ll, ("%s", buf.buffer));
    PR_LogFlush();
 
    // errors on platforms without a debugdlg ring a bell on stderr
 #if !defined(XP_WIN) && !defined(XP_OS2)
    if (ll != PR_LOG_WARNING)
--- a/xpcom/base/nsDebugImpl.h
+++ b/xpcom/base/nsDebugImpl.h
@@ -41,16 +41,24 @@ class nsDebugImpl : public nsIDebug2
 {
 public:
     nsDebugImpl() {}
     NS_DECL_ISUPPORTS
     NS_DECL_NSIDEBUG
     NS_DECL_NSIDEBUG2
     
     static nsresult Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
+
+    /*
+     * Inform nsDebugImpl that we're in multiprocess mode.
+     *
+     * If aDesc is not NULL, the string it points to must be
+     * statically-allocated (i.e., it must be a string literal).
+     */
+    static void SetMultiprocessMode(const char *aDesc);
 };
 
 
 #define NS_DEBUG_CONTRACTID "@mozilla.org/xpcom/debug;1"
 #define NS_DEBUG_CLASSNAME  "nsDebug Interface"
 #define NS_DEBUG_CID                                 \
 { /* a80b1fb3-aaf6-4852-b678-c27eb7a518af */         \
   0xa80b1fb3,                                        \