From 0a3d8da61847b81dcc7ee63f848ea1430bed6ec6 Mon Sep 17 00:00:00 2001 From: Masatoshi Kimura Date: Wed, 12 Feb 2014 06:01:29 +0900 Subject: [PATCH] Backed out changeset d7d447cac91b (bug 969762) for tp5 regression. --- content/base/src/nsFrameMessageManager.cpp | 15 +++++- dom/base/nsGlobalWindow.cpp | 30 ++++++++++- dom/workers/WorkerScope.cpp | 14 +++-- js/xpconnect/loader/mozJSComponentLoader.cpp | 22 ++++++-- js/xpconnect/src/XPCShellImpl.cpp | 20 +++++-- xpcom/base/Debug.cpp | 57 +++----------------- xpcom/base/Debug.h | 36 +++---------- xpcom/base/nsConsoleService.cpp | 31 ++++++++--- 8 files changed, 124 insertions(+), 101 deletions(-) diff --git a/content/base/src/nsFrameMessageManager.cpp b/content/base/src/nsFrameMessageManager.cpp index 4ab5bfd0f94..18cc7120352 100644 --- a/content/base/src/nsFrameMessageManager.cpp +++ b/content/base/src/nsFrameMessageManager.cpp @@ -29,7 +29,6 @@ #include "nsIDOMClassInfo.h" #include "nsIDOMFile.h" #include "xpcpublic.h" -#include "mozilla/Debug.h" #include "mozilla/Preferences.h" #include "mozilla/dom/StructuredCloneUtils.h" #include "JavaScriptChild.h" @@ -38,6 +37,9 @@ #include "nsPrintfCString.h" #include +#ifdef ANDROID +#include +#endif #ifdef XP_WIN #include # if defined(SendMessage) @@ -721,7 +723,16 @@ nsFrameMessageManager::GetChildAt(uint32_t aIndex, NS_IMETHODIMP nsFrameMessageManager::Dump(const nsAString& aStr) { - PrintToDebugger(aStr, stdout); +#ifdef ANDROID + __android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", NS_ConvertUTF16toUTF8(aStr).get()); +#endif +#ifdef XP_WIN + if (IsDebuggerPresent()) { + OutputDebugStringW(PromiseFlatString(aStr).get()); + } +#endif + fputs(NS_ConvertUTF16toUTF8(aStr).get(), stdout); + fflush(stdout); return NS_OK; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 61b09b7f0c6..c1dc3af8dcd 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -232,6 +232,10 @@ class nsIScriptTimeoutHandler; #endif // check #include "AccessCheck.h" +#ifdef ANDROID +#include +#endif + #ifdef PR_LOGGING static PRLogModuleInfo* gDOMLeakPRLog; #endif @@ -5809,7 +5813,31 @@ nsGlobalWindow::Dump(const nsAString& aStr) return NS_OK; } - PrintToDebugger(aStr, gDumpFile ? gDumpFile : stdout); + char *cstr = ToNewUTF8String(aStr); + +#if defined(XP_MACOSX) + // have to convert \r to \n so that printing to the console works + char *c = cstr, *cEnd = cstr + strlen(cstr); + while (c < cEnd) { + if (*c == '\r') + *c = '\n'; + c++; + } +#endif + + if (cstr) { +#ifdef XP_WIN + PrintToDebugger(cstr); +#endif +#ifdef ANDROID + __android_log_write(ANDROID_LOG_INFO, "GeckoDump", cstr); +#endif + FILE *fp = gDumpFile ? gDumpFile : stdout; + fputs(cstr, fp); + fflush(fp); + nsMemory::Free(cstr); + } + return NS_OK; } diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index ed39af8ea41..f66f5ae2927 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -7,11 +7,14 @@ #include "WorkerScope.h" #include "jsapi.h" -#include "mozilla/Debug.h" #include "mozilla/dom/FunctionBinding.h" #include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h" #include "mozilla/dom/SharedWorkerGlobalScopeBinding.h" +#ifdef ANDROID +#include +#endif + #include "Console.h" #include "Location.h" #include "Navigator.h" @@ -258,8 +261,13 @@ WorkerGlobalScope::Dump(const Optional& aString) const return; } - PrintToDebugger(aString.Value(), stdout, kPrintToStream - | kPrintInfoLog); + NS_ConvertUTF16toUTF8 str(aString.Value()); + +#ifdef ANDROID + __android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", str.get()); +#endif + fputs(str.get(), stdout); + fflush(stdout); } DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate) diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index 5df8ad7f4f9..e954d4dbdc7 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -13,12 +13,17 @@ #include #include "prlog.h" +#ifdef ANDROID +#include +#endif +#ifdef XP_WIN +#include +#endif #include "jsapi.h" #include "nsCOMPtr.h" #include "nsAutoPtr.h" #include "nsIComponentManager.h" -#include "mozilla/Debug.h" #include "mozilla/Module.h" #include "nsIFile.h" #include "mozJSComponentLoader.h" @@ -113,9 +118,18 @@ Dump(JSContext *cx, unsigned argc, Value *vp) if (!chars) return false; - nsDependentSubstring ustr(reinterpret_cast(chars), - length); - PrintToDebugger(ustr, stdout); + NS_ConvertUTF16toUTF8 utf8str(reinterpret_cast(chars), + length); +#ifdef ANDROID + __android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", utf8str.get()); +#endif +#ifdef XP_WIN + if (IsDebuggerPresent()) { + OutputDebugStringW(reinterpret_cast(chars)); + } +#endif + fputs(utf8str.get(), stdout); + fflush(stdout); return true; } diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index 839921b2392..285b424726a 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -8,7 +8,6 @@ #include "jsfriendapi.h" #include "jsprf.h" #include "js/OldDebugAPI.h" -#include "mozilla/Debug.h" #include "nsServiceManagerUtils.h" #include "nsComponentManagerUtils.h" #include "nsIXPConnect.h" @@ -33,6 +32,10 @@ #include "nsIScriptSecurityManager.h" #include "nsIPrincipal.h" +#ifdef ANDROID +#include +#endif + #ifdef XP_WIN #include #endif @@ -297,9 +300,18 @@ Dump(JSContext *cx, unsigned argc, jsval *vp) if (!chars) return false; - nsDependentSubstring ustr(reinterpret_cast(chars), - length); - PrintToDebugger(ustr, gOutFile); + NS_ConvertUTF16toUTF8 utf8str(reinterpret_cast(chars), + length); +#ifdef ANDROID + __android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", utf8str.get()); +#endif +#ifdef XP_WIN + if (IsDebuggerPresent()) { + OutputDebugStringW(reinterpret_cast(chars)); + } +#endif + fputs(utf8str.get(), gOutFile); + fflush(gOutFile); return true; } diff --git a/xpcom/base/Debug.cpp b/xpcom/base/Debug.cpp index 4e2dd42f435..19065ab39ee 100644 --- a/xpcom/base/Debug.cpp +++ b/xpcom/base/Debug.cpp @@ -6,61 +6,16 @@ #include "mozilla/Debug.h" #ifdef XP_WIN -#include #include #endif -#ifdef ANDROID -#include -#endif - -void mozilla::PrintToDebugger(const nsAString& aStr, FILE* aStream, - LogOptions aOptions) -{ - nsString msg(aStr); - if (aOptions & kPrintNewLine) { - msg.AppendLiteral("\n"); - } - #ifdef XP_WIN - if ((aOptions & kPrintToDebugger) && ::IsDebuggerPresent()) { - ::OutputDebugStringW(msg.get()); - } - if (!(aOptions & kPrintToStream)) { - return; +void mozilla::PrintToDebugger(const char* aStr) +{ + if (::IsDebuggerPresent()) { + ::OutputDebugStringA(aStr); } - - int fd = _fileno(aStream); - if (_isatty(fd)) { - fflush(aStream); - DWORD writtenCount; - WriteConsoleW(reinterpret_cast(_get_osfhandle(fd)), - msg.BeginReading(), msg.Length(), - &writtenCount, nullptr); - return; - } -#endif - NS_ConvertUTF16toUTF8 cstr(msg); -#ifdef ANDROID - if (aOptions & (kPrintInfoLog | kPrintErrorLog)) { - __android_log_write(aOptions & kPrintErrorLog ? ANDROID_LOG_ERROR - : ANDROID_LOG_INFO, - "GeckoDump", cstr.get()); - } -#endif - -#ifndef XP_WIN - if (!(aOptions & kPrintToStream)) { - return; - } -#endif - -#if defined(XP_MACOSX) - // have to convert \r to \n so that printing to the console works - cstr.ReplaceChar('\r', '\n'); -#endif - - fputs(cstr.get(), aStream); - fflush(aStream); } + +#endif diff --git a/xpcom/base/Debug.h b/xpcom/base/Debug.h index 356cf4a8499..a70c384aacc 100644 --- a/xpcom/base/Debug.h +++ b/xpcom/base/Debug.h @@ -3,40 +3,18 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef mozilla_Debug_h -#define mozilla_Debug_h - -#include "nsString.h" -#include +#ifndef mozilla_Debug_h__ +#define mozilla_Debug_h__ namespace mozilla { -typedef uint32_t LogOptions; - -// Print a message to the specified stream. -const LogOptions kPrintToStream = 1 << 0; - -// Print a message to a debugger if the debugger is attached. -// At the moment, only meaningful on Windows. -const LogOptions kPrintToDebugger = 1 << 1; - -// Print an info-level message to the log. -// At the moment, only meaningful on Andriod. -const LogOptions kPrintInfoLog = 1 << 2; - -// Print an error-level message to the log. -// At the moment, only meaningful on Andriod. -const LogOptions kPrintErrorLog = 1 << 3; - -// Print a new line after the message. -const LogOptions kPrintNewLine = 1 << 4; +#ifdef XP_WIN // Print aStr to a debugger if the debugger is attached. -void PrintToDebugger(const nsAString& aStr, FILE* aStream, - LogOptions aOptions = kPrintToStream - | kPrintToDebugger - | kPrintInfoLog); +void PrintToDebugger(const char* aStr); + +#endif } // namespace mozilla -#endif // mozilla_Debug_h +#endif // mozilla_Debug_h__ diff --git a/xpcom/base/nsConsoleService.cpp b/xpcom/base/nsConsoleService.cpp index 3f092bad9f0..d3394f86df3 100644 --- a/xpcom/base/nsConsoleService.cpp +++ b/xpcom/base/nsConsoleService.cpp @@ -20,9 +20,15 @@ #include "nsIConsoleListener.h" #include "nsPrintfCString.h" -#include "mozilla/Debug.h" #include "mozilla/Preferences.h" +#if defined(ANDROID) +#include +#endif +#ifdef XP_WIN +#include +#endif + using namespace mozilla; NS_IMPL_ADDREF(nsConsoleService) @@ -185,13 +191,24 @@ nsConsoleService::LogMessageWithMode(nsIConsoleMessage *message, nsConsoleServic { MutexAutoLock lock(mLock); - nsString msg; - message->GetMessageMoz(getter_Copies(msg)); - LogOptions options = kPrintToDebugger | kPrintNewLine; - if (outputMode == OutputToLog) { - options |= kPrintErrorLog; +#if defined(ANDROID) + if (outputMode == OutputToLog) + { + nsXPIDLString msg; + message->GetMessageMoz(getter_Copies(msg)); + __android_log_print(ANDROID_LOG_ERROR, "GeckoConsole", + "%s", + NS_LossyConvertUTF16toASCII(msg).get()); } - PrintToDebugger(msg, nullptr, options); +#endif +#ifdef XP_WIN + if (IsDebuggerPresent()) { + nsString msg; + message->GetMessageMoz(getter_Copies(msg)); + msg.AppendLiteral("\n"); + OutputDebugStringW(msg.get()); + } +#endif /* * If there's already a message in the slot we're about to replace,