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