Bug 1417185 - Introduce MOZ_CONSOLESERVICE_DISABLE_DEBUGGER_OUTPUT env var to prevent nsConsoleService from flooding debugger's output window, r=jchen
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 16 Jan 2018 12:27:00 +0200
changeset 453960 1f3711534710096532095eb6438c362fad67a20a
parent 453959 f05239cea76cbc2634a39f5e6879989d09ea29a4
child 453961 4e3657c2c2700459447b54fa588304b8bcb69664
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1417185
milestone59.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 1417185 - Introduce MOZ_CONSOLESERVICE_DISABLE_DEBUGGER_OUTPUT env var to prevent nsConsoleService from flooding debugger's output window, r=jchen
xpcom/base/nsConsoleService.cpp
--- a/xpcom/base/nsConsoleService.cpp
+++ b/xpcom/base/nsConsoleService.cpp
@@ -49,16 +49,19 @@ NS_IMPL_RELEASE(nsConsoleService)
 NS_IMPL_CLASSINFO(nsConsoleService, nullptr,
                   nsIClassInfo::THREADSAFE | nsIClassInfo::SINGLETON,
                   NS_CONSOLESERVICE_CID)
 NS_IMPL_QUERY_INTERFACE_CI(nsConsoleService, nsIConsoleService, nsIObserver)
 NS_IMPL_CI_INTERFACE_GETTER(nsConsoleService, nsIConsoleService, nsIObserver)
 
 static const bool gLoggingEnabled = true;
 static const bool gLoggingBuffered = true;
+#ifdef XP_WIN
+static bool gLoggingToDebugger = true;
+#endif // XP_WIN
 #if defined(ANDROID)
 static bool gLoggingLogcat = false;
 #endif // defined(ANDROID)
 
 nsConsoleService::MessageElement::~MessageElement()
 {
 }
 
@@ -66,16 +69,28 @@ nsConsoleService::nsConsoleService()
   : mCurrentSize(0)
   , mDeliveringMessage(false)
   , mLock("nsConsoleService.mLock")
 {
   // XXX grab this from a pref!
   // hm, but worry about circularity, bc we want to be able to report
   // prefs errs...
   mMaximumSize = 250;
+
+#ifdef XP_WIN
+  // This environment variable controls whether the console service
+  // should be prevented from putting output to the attached debugger.
+  // It only affects the Windows platform.
+  //
+  // To disable OutputDebugString, set:
+  //   MOZ_CONSOLESERVICE_DISABLE_DEBUGGER_OUTPUT=1
+  //
+  const char* disableDebugLoggingVar = getenv("MOZ_CONSOLESERVICE_DISABLE_DEBUGGER_OUTPUT");
+  gLoggingToDebugger = !disableDebugLoggingVar || (disableDebugLoggingVar[0] == '0');
+#endif // XP_WIN
 }
 
 
 void
 nsConsoleService::ClearMessagesForWindowID(const uint64_t innerID)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MutexAutoLock lock(mLock);
@@ -281,17 +296,17 @@ nsConsoleService::LogMessageWithMode(nsI
           logPriority = ANDROID_LOG_ERROR;
           break;
       }
 
       __android_log_print(logPriority, appName.get(), "%s", msg.get());
     }
 #endif
 #ifdef XP_WIN
-    if (IsDebuggerPresent()) {
+    if (gLoggingToDebugger && IsDebuggerPresent()) {
       nsString msg;
       aMessage->GetMessageMoz(getter_Copies(msg));
       msg.Append('\n');
       OutputDebugStringW(msg.get());
     }
 #endif
 #ifdef MOZ_TASK_TRACER
     if (IsStartLogging()) {