Bug 1543501 - Make MOZ_DBG() work on Android. r=heycam
authorBotond Ballo <botond@mozilla.com>
Fri, 12 Apr 2019 16:48:51 +0000
changeset 531187 8a857aaa693aa39a762eab3acec6c4aad9506933
parent 531186 daaf43ea3783878dfb91e545949762be737acf98
child 531188 f5d3c4db8758a94eb18a89c3e542c0140acb1f76
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1543501
milestone68.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 1543501 - Make MOZ_DBG() work on Android. r=heycam stderr does not go anywhere by default on Android. Debugging output is conventionally sent to the Android log via special functions like __android_log_print. We already have logic for handling this in nsCRTGlue's printf_stderr, but I don't think we can use that in MFBT. Differential Revision: https://phabricator.services.mozilla.com/D26985
mfbt/DbgMacro.h
--- a/mfbt/DbgMacro.h
+++ b/mfbt/DbgMacro.h
@@ -13,16 +13,20 @@
 #include "mozilla/Span.h"
 
 #include <stdio.h>
 #include <sstream>
 
 template <typename T>
 class nsTSubstring;
 
+#ifdef ANDROID
+#  include <android/log.h>
+#endif
+
 namespace mozilla {
 
 namespace detail {
 
 // Predicate to check whether T can be inserted into an ostream.
 template <typename T, typename = decltype(std::declval<std::ostream&>()
                                           << std::declval<T>())>
 std::true_type supports_os_test(const T&);
@@ -87,17 +91,21 @@ namespace detail {
 // Helper function template for MOZ_DBG.
 template <typename T>
 auto&& MozDbg(const char* aFile, int aLine, const char* aExpression,
               T&& aValue) {
   std::ostringstream s;
   s << "[MozDbg] [" << aFile << ':' << aLine << "] " << aExpression << " = ";
   mozilla::DebugValue(s, std::forward<T>(aValue));
   s << '\n';
+#ifdef ANDROID
+  __android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", s.str().c_str());
+#else
   fputs(s.str().c_str(), stderr);
+#endif
   return std::forward<T>(aValue);
 }
 
 }  // namespace detail
 
 }  // namespace mozilla
 
 template <class ElementType, size_t Extent>