mozglue/linker/Logging.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mozglue/linker/Logging.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef Logging_h
     1.9 +#define Logging_h
    1.10 +
    1.11 +#include "mozilla/Likely.h"
    1.12 +
    1.13 +#ifdef ANDROID
    1.14 +#include <android/log.h>
    1.15 +#define LOG(...) __android_log_print(ANDROID_LOG_ERROR, "GeckoLinker", __VA_ARGS__)
    1.16 +#else
    1.17 +#include <cstdio>
    1.18 +
    1.19 +/* Expand to 1 or m depending on whether there is one argument or more
    1.20 + * given. */
    1.21 +#define MOZ_ONE_OR_MORE_ARGS_IMPL2(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) \
    1.22 +  N
    1.23 +#define MOZ_ONE_OR_MORE_ARGS_IMPL(args) MOZ_ONE_OR_MORE_ARGS_IMPL2 args
    1.24 +#define MOZ_ONE_OR_MORE_ARGS(...) \
    1.25 +  MOZ_ONE_OR_MORE_ARGS_IMPL((__VA_ARGS__, m, m, m, m, m, m, m, m, 1, 0))
    1.26 +
    1.27 +#define MOZ_MACRO_GLUE(a, b) a b
    1.28 +#define MOZ_CONCAT2(a, b) a ## b
    1.29 +#define MOZ_CONCAT1(a, b) MOZ_CONCAT2(a, b)
    1.30 +#define MOZ_CONCAT(a, b) MOZ_CONCAT1(a, b)
    1.31 +
    1.32 +/* Some magic to choose between LOG1 and LOGm depending on the number of
    1.33 + * arguments */
    1.34 +#define MOZ_CHOOSE_LOG(...) \
    1.35 +  MOZ_MACRO_GLUE(MOZ_CONCAT(LOG, MOZ_ONE_OR_MORE_ARGS(__VA_ARGS__)), \
    1.36 +                 (__VA_ARGS__))
    1.37 +
    1.38 +#define LOG1(format) fprintf(stderr, format "\n")
    1.39 +#define LOGm(format, ...) fprintf(stderr, format "\n", __VA_ARGS__)
    1.40 +#define LOG(...) MOZ_CHOOSE_LOG(__VA_ARGS__)
    1.41 +
    1.42 +#endif
    1.43 +
    1.44 +class Logging
    1.45 +{
    1.46 +public:
    1.47 +  static bool isVerbose()
    1.48 +  {
    1.49 +    return Singleton.verbose;
    1.50 +  }
    1.51 +
    1.52 +private:
    1.53 +  bool verbose;
    1.54 +
    1.55 +public:
    1.56 +  static void Init()
    1.57 +  {
    1.58 +    const char *env = getenv("MOZ_DEBUG_LINKER");
    1.59 +    if (env && *env == '1')
    1.60 +      Singleton.verbose = true;
    1.61 +  }
    1.62 +
    1.63 +private:
    1.64 +  static Logging Singleton;
    1.65 +};
    1.66 +
    1.67 +#define DEBUG_LOG(...)   \
    1.68 +  do {                   \
    1.69 +    if (MOZ_UNLIKELY(Logging::isVerbose())) {  \
    1.70 +      LOG(__VA_ARGS__);  \
    1.71 +    }                    \
    1.72 +  } while(0)
    1.73 +
    1.74 +#if defined(__LP64__)
    1.75 +#  define PRIxAddr "lx"
    1.76 +#  define PRIxSize "lx"
    1.77 +#  define PRIdSize "ld"
    1.78 +#  define PRIuSize "lu"
    1.79 +#else
    1.80 +#  define PRIxAddr "x"
    1.81 +#  define PRIxSize "x"
    1.82 +#  define PRIdSize "d"
    1.83 +#  define PRIuSize "u"
    1.84 +#endif
    1.85 +
    1.86 +#endif /* Logging_h */

mercurial