michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef Logging_h michael@0: #define Logging_h michael@0: michael@0: #include "mozilla/Likely.h" michael@0: michael@0: #ifdef ANDROID michael@0: #include michael@0: #define LOG(...) __android_log_print(ANDROID_LOG_ERROR, "GeckoLinker", __VA_ARGS__) michael@0: #else michael@0: #include michael@0: michael@0: /* Expand to 1 or m depending on whether there is one argument or more michael@0: * given. */ michael@0: #define MOZ_ONE_OR_MORE_ARGS_IMPL2(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) \ michael@0: N michael@0: #define MOZ_ONE_OR_MORE_ARGS_IMPL(args) MOZ_ONE_OR_MORE_ARGS_IMPL2 args michael@0: #define MOZ_ONE_OR_MORE_ARGS(...) \ michael@0: MOZ_ONE_OR_MORE_ARGS_IMPL((__VA_ARGS__, m, m, m, m, m, m, m, m, 1, 0)) michael@0: michael@0: #define MOZ_MACRO_GLUE(a, b) a b michael@0: #define MOZ_CONCAT2(a, b) a ## b michael@0: #define MOZ_CONCAT1(a, b) MOZ_CONCAT2(a, b) michael@0: #define MOZ_CONCAT(a, b) MOZ_CONCAT1(a, b) michael@0: michael@0: /* Some magic to choose between LOG1 and LOGm depending on the number of michael@0: * arguments */ michael@0: #define MOZ_CHOOSE_LOG(...) \ michael@0: MOZ_MACRO_GLUE(MOZ_CONCAT(LOG, MOZ_ONE_OR_MORE_ARGS(__VA_ARGS__)), \ michael@0: (__VA_ARGS__)) michael@0: michael@0: #define LOG1(format) fprintf(stderr, format "\n") michael@0: #define LOGm(format, ...) fprintf(stderr, format "\n", __VA_ARGS__) michael@0: #define LOG(...) MOZ_CHOOSE_LOG(__VA_ARGS__) michael@0: michael@0: #endif michael@0: michael@0: class Logging michael@0: { michael@0: public: michael@0: static bool isVerbose() michael@0: { michael@0: return Singleton.verbose; michael@0: } michael@0: michael@0: private: michael@0: bool verbose; michael@0: michael@0: public: michael@0: static void Init() michael@0: { michael@0: const char *env = getenv("MOZ_DEBUG_LINKER"); michael@0: if (env && *env == '1') michael@0: Singleton.verbose = true; michael@0: } michael@0: michael@0: private: michael@0: static Logging Singleton; michael@0: }; michael@0: michael@0: #define DEBUG_LOG(...) \ michael@0: do { \ michael@0: if (MOZ_UNLIKELY(Logging::isVerbose())) { \ michael@0: LOG(__VA_ARGS__); \ michael@0: } \ michael@0: } while(0) michael@0: michael@0: #if defined(__LP64__) michael@0: # define PRIxAddr "lx" michael@0: # define PRIxSize "lx" michael@0: # define PRIdSize "ld" michael@0: # define PRIuSize "lu" michael@0: #else michael@0: # define PRIxAddr "x" michael@0: # define PRIxSize "x" michael@0: # define PRIdSize "d" michael@0: # define PRIuSize "u" michael@0: #endif michael@0: michael@0: #endif /* Logging_h */