From 04ad4da5ff4d7b3ae47774ad1941866d38183651 Mon Sep 17 00:00:00 2001 From: Tom Ritter Date: Tue, 11 Dec 2018 11:31:24 -0600 Subject: [PATCH] Bug 1512690 - Introduce a MesageManager log topic for MM topics and data r=tjr This logging topic will output the topic of MEssageManager data at log level 4 (debug); and will output the entire content of the data at level 5 (verbose). --HG-- extra : histedit_source : 7be60b456a1652f9a9985fd4a01571b207a5f9e6 --- dom/ipc/ContentChild.cpp | 2 ++ dom/ipc/MMPrinter.cpp | 54 ++++++++++++++++++++++++++++++++++++ dom/ipc/MMPrinter.h | 31 +++++++++++++++++++++ dom/ipc/SharedMap.cpp | 1 + dom/ipc/TabChild.cpp | 2 ++ dom/ipc/TabParent.cpp | 3 ++ dom/ipc/moz.build | 2 ++ dom/ipc/nsIContentChild.cpp | 2 ++ dom/ipc/nsIContentParent.cpp | 4 +++ 9 files changed, 101 insertions(+) create mode 100644 dom/ipc/MMPrinter.cpp create mode 100644 dom/ipc/MMPrinter.h diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 22f0950de460..77f4ff8f44a0 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -242,6 +242,7 @@ #include "VRManagerChild.h" #include "private/pprio.h" #include "nsString.h" +#include "MMPrinter.h" #ifdef MOZ_WIDGET_GTK #include "nsAppRunner.h" @@ -2259,6 +2260,7 @@ mozilla::ipc::IPCResult ContentChild::RecvAsyncMessage( const IPC::Principal& aPrincipal, const ClonedMessageData& aData) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING("ContentChild::RecvAsyncMessage", OTHER, aMsg); + MMPrinter::Print("ContentChild::RecvAsyncMessage", aMsg, aData); CrossProcessCpowHolder cpows(this, aCpows); RefPtr cpm = diff --git a/dom/ipc/MMPrinter.cpp b/dom/ipc/MMPrinter.cpp new file mode 100644 index 000000000000..13688e76b7c3 --- /dev/null +++ b/dom/ipc/MMPrinter.cpp @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +#include "MMPrinter.h" + +namespace mozilla { +namespace dom { + +LazyLogModule MMPrinter::sMMLog("MessageManager"); + +/* static */ +void MMPrinter::PrintImpl(char const* aLocation, const nsAString& aMsg, + ClonedMessageData const& aData) { + NS_ConvertUTF16toUTF8 charMsg(aMsg); + + MOZ_LOG(MMPrinter::sMMLog, LogLevel::Debug, + ("%s Message: %s in process type: %s", aLocation, charMsg.get(), + XRE_ChildProcessTypeToString(XRE_GetProcessType()))); + + if (!MOZ_LOG_TEST(sMMLog, LogLevel::Verbose)) { + return; + } + + ErrorResult rv; + + AutoJSAPI jsapi; + MOZ_ALWAYS_TRUE(jsapi.Init(xpc::UnprivilegedJunkScope())); + JSContext* cx = jsapi.cx(); + + ipc::StructuredCloneData data; + ipc::UnpackClonedMessageDataForChild(aData, data); + + /* Read original StructuredCloneData. */ + JS::RootedValue scdContent(cx); + data.Read(cx, &scdContent, rv); + if (NS_WARN_IF(rv.Failed())) { + rv.SuppressException(); + return; + } + + JS::RootedString unevalObj(cx, JS_ValueToSource(cx, scdContent)); + nsAutoJSString srcString; + if (!srcString.init(cx, unevalObj)) return; + + MOZ_LOG(MMPrinter::sMMLog, LogLevel::Verbose, + (" %s", NS_ConvertUTF16toUTF8(srcString).get())); + return; +} + +} // namespace dom +} // namespace mozilla \ No newline at end of file diff --git a/dom/ipc/MMPrinter.h b/dom/ipc/MMPrinter.h new file mode 100644 index 000000000000..97f2ebd13b60 --- /dev/null +++ b/dom/ipc/MMPrinter.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 MMPrinter_h +#define MMPrinter_h + +namespace mozilla { +namespace dom { + +class MMPrinter { + public: + static void Print(char const* aLocation, const nsAString& aMsg, + ClonedMessageData const& aData) { + if (MOZ_UNLIKELY(MOZ_LOG_TEST(MMPrinter::sMMLog, LogLevel::Debug))) { + MMPrinter::PrintImpl(aLocation, aMsg, aData); + } + } + + private: + static LazyLogModule sMMLog; + static void PrintImpl(char const* aLocation, const nsAString& aMsg, + ClonedMessageData const& aData); +}; + +} // namespace dom +} // namespace mozilla + +#endif /* MMPrinter_h */ \ No newline at end of file diff --git a/dom/ipc/SharedMap.cpp b/dom/ipc/SharedMap.cpp index 15e5a8e07660..240b21c60501 100644 --- a/dom/ipc/SharedMap.cpp +++ b/dom/ipc/SharedMap.cpp @@ -14,6 +14,7 @@ #include "mozilla/dom/ContentProcessMessageManager.h" #include "mozilla/dom/IPCBlobUtils.h" #include "mozilla/dom/ScriptSettings.h" +#include "mozilla/ScriptPreloader.h" using namespace mozilla::loader; diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index f1a385febeb7..5aaf96211cca 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -123,6 +123,7 @@ #include "nsDocShellLoadState.h" #include "nsWebBrowser.h" #include "mozilla/dom/WindowGlobalChild.h" +#include "MMPrinter.h" #ifdef XP_WIN #include "mozilla/plugins/PluginWidgetChild.h" @@ -2056,6 +2057,7 @@ mozilla::ipc::IPCResult TabChild::RecvAsyncMessage( const IPC::Principal& aPrincipal, const ClonedMessageData& aData) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING("TabChild::RecvAsyncMessage", OTHER, aMessage); + MMPrinter::Print("TabChild::RecvAsyncMessage", aMessage, aData); CrossProcessCpowHolder cpows(Manager(), aCpows); if (!mTabChildMessageManager) { diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index fbccac6719e0..a1659414ca5b 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -1579,6 +1579,7 @@ mozilla::ipc::IPCResult TabParent::RecvSyncMessage( nsTArray* aRetVal) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING("TabParent::RecvSyncMessage", OTHER, aMessage); + MMPrinter::Print("TabParent::RecvSyncMessage", aMessage, aData); StructuredCloneData data; ipc::UnpackClonedMessageDataForParent(aData, data); @@ -1596,6 +1597,7 @@ mozilla::ipc::IPCResult TabParent::RecvRpcMessage( nsTArray* aRetVal) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING("TabParent::RecvRpcMessage", OTHER, aMessage); + MMPrinter::Print("TabParent::RecvRpcMessage", aMessage, aData); StructuredCloneData data; ipc::UnpackClonedMessageDataForParent(aData, data); @@ -1612,6 +1614,7 @@ mozilla::ipc::IPCResult TabParent::RecvAsyncMessage( const IPC::Principal& aPrincipal, const ClonedMessageData& aData) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING("TabParent::RecvAsyncMessage", OTHER, aMessage); + MMPrinter::Print("TabParent::RecvAsyncMessage", aMessage, aData); StructuredCloneData data; ipc::UnpackClonedMessageDataForParent(aData, data); diff --git a/dom/ipc/moz.build b/dom/ipc/moz.build index a61e3f4257b4..8dc57c1bf593 100644 --- a/dom/ipc/moz.build +++ b/dom/ipc/moz.build @@ -72,6 +72,7 @@ UNIFIED_SOURCES += [ 'FilePickerParent.cpp', 'MemMapSnapshot.cpp', 'MemoryReportRequest.cpp', + 'MMPrinter.cpp', 'nsIContentChild.cpp', 'nsIContentParent.cpp', 'PermissionMessageUtils.cpp', @@ -148,6 +149,7 @@ LOCAL_INCLUDES += [ '/gfx/2d', '/hal/sandbox', '/js/xpconnect/loader', + '/js/xpconnect/src', '/layout/base', '/media/webrtc', '/netwerk/base', diff --git a/dom/ipc/nsIContentChild.cpp b/dom/ipc/nsIContentChild.cpp index 37b4c7711a3e..57b2f5c53007 100644 --- a/dom/ipc/nsIContentChild.cpp +++ b/dom/ipc/nsIContentChild.cpp @@ -23,6 +23,7 @@ #include "mozilla/ipc/PParentToChildStreamChild.h" #include "mozilla/dom/ipc/IPCBlobInputStreamChild.h" +#include "MMPrinter.h" #include "nsPrintfCString.h" #include "xpcpublic.h" @@ -147,6 +148,7 @@ mozilla::ipc::IPCResult nsIContentChild::RecvAsyncMessage( const IPC::Principal& aPrincipal, const ClonedMessageData& aData) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING( "nsIContentChild::RecvAsyncMessage", OTHER, aMsg); + MMPrinter::Print("nsIContentChild::RecvAsyncMessage", aMsg, aData); CrossProcessCpowHolder cpows(this, aCpows); RefPtr cpm = diff --git a/dom/ipc/nsIContentParent.cpp b/dom/ipc/nsIContentParent.cpp index 2bd295a514d9..2cf1be02c8ba 100644 --- a/dom/ipc/nsIContentParent.cpp +++ b/dom/ipc/nsIContentParent.cpp @@ -25,6 +25,7 @@ #include "mozilla/ipc/IPCStreamSource.h" #include "mozilla/Unused.h" +#include "MMPrinter.h" #include "nsIWebBrowserChrome.h" #include "nsPrintfCString.h" #include "xpcpublic.h" @@ -235,6 +236,7 @@ mozilla::ipc::IPCResult nsIContentParent::RecvSyncMessage( nsTArray* aRetvals) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING( "nsIContentParent::RecvSyncMessage", OTHER, aMsg); + MMPrinter::Print("nsIContentParent::RecvSyncMessage", aMsg, aData); CrossProcessCpowHolder cpows(this, aCpows); RefPtr ppm = mMessageManager; @@ -254,6 +256,7 @@ mozilla::ipc::IPCResult nsIContentParent::RecvRpcMessage( nsTArray* aRetvals) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING("nsIContentParent::RecvRpcMessage", OTHER, aMsg); + MMPrinter::Print("nsIContentParent::RecvRpcMessage", aMsg, aData); CrossProcessCpowHolder cpows(this, aCpows); RefPtr ppm = mMessageManager; @@ -305,6 +308,7 @@ mozilla::ipc::IPCResult nsIContentParent::RecvAsyncMessage( const IPC::Principal& aPrincipal, const ClonedMessageData& aData) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING( "nsIContentParent::RecvAsyncMessage", OTHER, aMsg); + MMPrinter::Print("nsIContentParent::RecvAsyncMessage", aMsg, aData); CrossProcessCpowHolder cpows(this, aCpows); RefPtr ppm = mMessageManager;