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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Botond Ballo 2019-04-12 16:48:51 +00:00
parent 422903589d
commit 55b741f5f7

View file

@ -18,6 +18,10 @@
template <typename T>
class nsTSubstring;
#ifdef ANDROID
# include <android/log.h>
#endif
namespace mozilla {
namespace detail {
@ -92,7 +96,11 @@ auto&& MozDbg(const char* aFile, int aLine, const char* aExpression,
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);
}