Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef Logging_h |
michael@0 | 6 | #define Logging_h |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/Likely.h" |
michael@0 | 9 | |
michael@0 | 10 | #ifdef ANDROID |
michael@0 | 11 | #include <android/log.h> |
michael@0 | 12 | #define LOG(...) __android_log_print(ANDROID_LOG_ERROR, "GeckoLinker", __VA_ARGS__) |
michael@0 | 13 | #else |
michael@0 | 14 | #include <cstdio> |
michael@0 | 15 | |
michael@0 | 16 | /* Expand to 1 or m depending on whether there is one argument or more |
michael@0 | 17 | * given. */ |
michael@0 | 18 | #define MOZ_ONE_OR_MORE_ARGS_IMPL2(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) \ |
michael@0 | 19 | N |
michael@0 | 20 | #define MOZ_ONE_OR_MORE_ARGS_IMPL(args) MOZ_ONE_OR_MORE_ARGS_IMPL2 args |
michael@0 | 21 | #define MOZ_ONE_OR_MORE_ARGS(...) \ |
michael@0 | 22 | MOZ_ONE_OR_MORE_ARGS_IMPL((__VA_ARGS__, m, m, m, m, m, m, m, m, 1, 0)) |
michael@0 | 23 | |
michael@0 | 24 | #define MOZ_MACRO_GLUE(a, b) a b |
michael@0 | 25 | #define MOZ_CONCAT2(a, b) a ## b |
michael@0 | 26 | #define MOZ_CONCAT1(a, b) MOZ_CONCAT2(a, b) |
michael@0 | 27 | #define MOZ_CONCAT(a, b) MOZ_CONCAT1(a, b) |
michael@0 | 28 | |
michael@0 | 29 | /* Some magic to choose between LOG1 and LOGm depending on the number of |
michael@0 | 30 | * arguments */ |
michael@0 | 31 | #define MOZ_CHOOSE_LOG(...) \ |
michael@0 | 32 | MOZ_MACRO_GLUE(MOZ_CONCAT(LOG, MOZ_ONE_OR_MORE_ARGS(__VA_ARGS__)), \ |
michael@0 | 33 | (__VA_ARGS__)) |
michael@0 | 34 | |
michael@0 | 35 | #define LOG1(format) fprintf(stderr, format "\n") |
michael@0 | 36 | #define LOGm(format, ...) fprintf(stderr, format "\n", __VA_ARGS__) |
michael@0 | 37 | #define LOG(...) MOZ_CHOOSE_LOG(__VA_ARGS__) |
michael@0 | 38 | |
michael@0 | 39 | #endif |
michael@0 | 40 | |
michael@0 | 41 | class Logging |
michael@0 | 42 | { |
michael@0 | 43 | public: |
michael@0 | 44 | static bool isVerbose() |
michael@0 | 45 | { |
michael@0 | 46 | return Singleton.verbose; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | private: |
michael@0 | 50 | bool verbose; |
michael@0 | 51 | |
michael@0 | 52 | public: |
michael@0 | 53 | static void Init() |
michael@0 | 54 | { |
michael@0 | 55 | const char *env = getenv("MOZ_DEBUG_LINKER"); |
michael@0 | 56 | if (env && *env == '1') |
michael@0 | 57 | Singleton.verbose = true; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | private: |
michael@0 | 61 | static Logging Singleton; |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | #define DEBUG_LOG(...) \ |
michael@0 | 65 | do { \ |
michael@0 | 66 | if (MOZ_UNLIKELY(Logging::isVerbose())) { \ |
michael@0 | 67 | LOG(__VA_ARGS__); \ |
michael@0 | 68 | } \ |
michael@0 | 69 | } while(0) |
michael@0 | 70 | |
michael@0 | 71 | #if defined(__LP64__) |
michael@0 | 72 | # define PRIxAddr "lx" |
michael@0 | 73 | # define PRIxSize "lx" |
michael@0 | 74 | # define PRIdSize "ld" |
michael@0 | 75 | # define PRIuSize "lu" |
michael@0 | 76 | #else |
michael@0 | 77 | # define PRIxAddr "x" |
michael@0 | 78 | # define PRIxSize "x" |
michael@0 | 79 | # define PRIdSize "d" |
michael@0 | 80 | # define PRIuSize "u" |
michael@0 | 81 | #endif |
michael@0 | 82 | |
michael@0 | 83 | #endif /* Logging_h */ |