2017-06-05 14:26:06 -07:00
|
|
|
/*
|
2021-02-04 11:03:55 -08:00
|
|
|
* Copyright (c)2013-2021 ZeroTier, Inc.
|
2017-06-05 14:26:06 -07:00
|
|
|
*
|
2020-04-13 23:38:06 -07:00
|
|
|
* Use of this software is governed by the Business Source License included
|
|
|
|
|
* in the LICENSE.TXT file in the project's root directory.
|
2017-06-05 14:26:06 -07:00
|
|
|
*
|
2021-02-04 11:03:55 -08:00
|
|
|
* Change Date: 2025-01-01
|
2017-06-05 14:26:06 -07:00
|
|
|
*
|
2020-04-13 23:38:06 -07:00
|
|
|
* On the date above, in accordance with the Business Source License, use
|
|
|
|
|
* of this software will be governed by version 2.0 of the Apache License.
|
2017-06-05 14:26:06 -07:00
|
|
|
*/
|
2020-04-13 23:38:06 -07:00
|
|
|
/****/
|
2017-06-05 14:26:06 -07:00
|
|
|
|
2017-09-27 02:29:04 -07:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
*
|
|
|
|
|
* Debug macros
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef LIBZT_DEBUG_HPP
|
|
|
|
|
#define LIBZT_DEBUG_HPP
|
|
|
|
|
|
2019-01-14 12:01:29 -08:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Debugging Macros //
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2017-12-19 16:23:52 -08:00
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
2021-04-17 23:46:21 -07:00
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
#include <unistd.h>
|
2017-10-11 15:22:31 -07:00
|
|
|
#endif
|
2017-11-06 13:50:20 -08:00
|
|
|
#include <string.h>
|
2017-06-05 14:26:06 -07:00
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
#define ZT_MSG_ERROR true // Errors
|
|
|
|
|
#define ZT_MSG_INFO true // Information which is generally useful to any developer
|
|
|
|
|
#define ZT_MSG_TEST true // For use in selftest
|
|
|
|
|
#define ZT_MSG_TRANSFER true // RX/TX specific statements
|
2017-06-16 16:58:30 -07:00
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
#define ZT_COLOR true
|
2017-06-05 14:26:06 -07:00
|
|
|
|
|
|
|
|
// Debug output colors
|
|
|
|
|
#if defined(__APPLE__)
|
2021-04-17 23:46:21 -07:00
|
|
|
#include "TargetConditionals.h"
|
2017-06-05 14:26:06 -07:00
|
|
|
#endif
|
2021-04-17 23:46:21 -07:00
|
|
|
#if defined(ZT_COLOR) && ! defined(_WIN32) && ! defined(__ANDROID__) \
|
|
|
|
|
&& ! defined(TARGET_OS_IPHONE) && ! defined(TARGET_IPHONE_SIMULATOR) \
|
|
|
|
|
&& ! defined(__APP_FRAMEWORK__)
|
2017-08-02 14:54:29 -07:00
|
|
|
#define ZT_RED "\x1B[31m"
|
|
|
|
|
#define ZT_GRN "\x1B[32m"
|
|
|
|
|
#define ZT_YEL "\x1B[33m"
|
|
|
|
|
#define ZT_BLU "\x1B[34m"
|
|
|
|
|
#define ZT_MAG "\x1B[35m"
|
|
|
|
|
#define ZT_CYN "\x1B[36m"
|
|
|
|
|
#define ZT_WHT "\x1B[37m"
|
|
|
|
|
#define ZT_RESET "\x1B[0m"
|
2017-06-05 14:26:06 -07:00
|
|
|
#else
|
2017-08-02 14:54:29 -07:00
|
|
|
#define ZT_RED
|
|
|
|
|
#define ZT_GRN
|
|
|
|
|
#define ZT_YEL
|
|
|
|
|
#define ZT_BLU
|
|
|
|
|
#define ZT_MAG
|
|
|
|
|
#define ZT_CYN
|
|
|
|
|
#define ZT_WHT
|
|
|
|
|
#define ZT_RESET
|
2017-06-05 14:26:06 -07:00
|
|
|
#endif
|
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
#define ZT_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // short
|
2017-06-05 14:26:06 -07:00
|
|
|
|
|
|
|
|
#if defined(__JNI_LIB__)
|
2021-04-17 23:46:21 -07:00
|
|
|
#include <jni.h>
|
2017-06-05 14:26:06 -07:00
|
|
|
#endif
|
|
|
|
|
#if defined(__ANDROID__)
|
2021-04-17 23:46:21 -07:00
|
|
|
#include <android/log.h>
|
|
|
|
|
#define ZT_LOG_TAG "ZTSDK"
|
2017-06-05 14:26:06 -07:00
|
|
|
#endif
|
|
|
|
|
|
2017-11-29 17:06:06 -08:00
|
|
|
#if defined(LIBZT_DEBUG) || defined(LIBZT_TRACE) || defined(__NATIVETEST__)
|
2017-09-15 19:31:23 -07:00
|
|
|
//
|
2019-01-14 12:01:29 -08:00
|
|
|
#if ZT_MSG_ERROR == true
|
2017-09-15 19:31:23 -07:00
|
|
|
#if defined(__ANDROID__)
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_ERROR(fmt, args...) \
|
|
|
|
|
((void)__android_log_print( \
|
|
|
|
|
ANDROID_LOG_VERBOSE, \
|
|
|
|
|
ZT_LOG_TAG, \
|
|
|
|
|
"%17s:%5d:%20s: " fmt "\n", \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
##args))
|
2018-07-27 15:52:15 -07:00
|
|
|
#elif defined(_WIN32)
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_ERROR(fmt, ...) \
|
|
|
|
|
fprintf( \
|
|
|
|
|
stderr, \
|
|
|
|
|
ZT_RED "%17s:%5d:%25s: " fmt "\n" ZT_RESET, \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
__VA_ARGS__)
|
2017-09-15 19:31:23 -07:00
|
|
|
#else
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_ERROR(fmt, args...) \
|
|
|
|
|
fprintf( \
|
|
|
|
|
stderr, \
|
|
|
|
|
ZT_RED "%17s:%5d:%25s: " fmt "\n" ZT_RESET, \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
##args)
|
2017-09-15 19:31:23 -07:00
|
|
|
#endif
|
2017-09-13 16:26:27 -07:00
|
|
|
#else
|
2019-01-14 12:01:29 -08:00
|
|
|
#define DEBUG_ERROR(fmt, args...)
|
2017-08-02 14:54:29 -07:00
|
|
|
#endif
|
|
|
|
|
|
2017-09-15 19:31:23 -07:00
|
|
|
//
|
2019-01-14 12:01:29 -08:00
|
|
|
#if ZT_MSG_TEST == true
|
2017-09-15 19:31:23 -07:00
|
|
|
#if defined(__ANDROID__)
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_TEST(fmt, args...) \
|
|
|
|
|
((void)__android_log_print( \
|
|
|
|
|
ANDROID_LOG_VERBOSE, \
|
|
|
|
|
ZT_LOG_TAG, \
|
|
|
|
|
"%17s:%5d:%25s: " fmt "\n", \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
##args))
|
2018-07-19 17:19:06 -07:00
|
|
|
#elif defined(_WIN32)
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_TEST(fmt, ...) \
|
|
|
|
|
fprintf( \
|
|
|
|
|
stderr, \
|
|
|
|
|
ZT_CYN "%17s:%5d:%25s: " fmt "\n" ZT_RESET, \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
__VA_ARGS__)
|
2017-09-15 19:31:23 -07:00
|
|
|
#else
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_TEST(fmt, args...) \
|
|
|
|
|
fprintf( \
|
|
|
|
|
stderr, \
|
|
|
|
|
ZT_CYN "%17s:%5d:%25s: " fmt "\n" ZT_RESET, \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
##args)
|
2017-09-15 19:31:23 -07:00
|
|
|
#endif
|
2017-08-02 14:54:29 -07:00
|
|
|
#else
|
2019-01-14 12:01:29 -08:00
|
|
|
#define DEBUG_TEST(fmt, args...)
|
2017-09-13 16:26:27 -07:00
|
|
|
#endif
|
2017-09-13 23:21:15 -07:00
|
|
|
|
2017-09-15 19:31:23 -07:00
|
|
|
//
|
|
|
|
|
#if ZT_MSG_INFO == true
|
2017-09-13 16:26:27 -07:00
|
|
|
#if defined(__ANDROID__)
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_INFO(fmt, args...) \
|
|
|
|
|
((void)__android_log_print( \
|
|
|
|
|
ANDROID_LOG_VERBOSE, \
|
|
|
|
|
ZT_LOG_TAG, \
|
|
|
|
|
"%17s:%5d:%20s: " fmt "\n", \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
##args))
|
2018-07-27 15:52:15 -07:00
|
|
|
#elif defined(_WIN32)
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_INFO(fmt, ...) \
|
|
|
|
|
fprintf( \
|
|
|
|
|
stderr, \
|
|
|
|
|
ZT_WHT "%17s:%5d:%25s: " fmt "\n" ZT_RESET, \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
__VA_ARGS__)
|
2017-09-13 16:26:27 -07:00
|
|
|
#else
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_INFO(fmt, args...) \
|
|
|
|
|
fprintf( \
|
|
|
|
|
stderr, \
|
|
|
|
|
ZT_WHT "%17s:%5d:%25s: " fmt "\n" ZT_RESET, \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
##args)
|
2017-09-15 19:31:23 -07:00
|
|
|
#endif
|
2017-09-13 16:26:27 -07:00
|
|
|
#else
|
|
|
|
|
#define DEBUG_INFO(fmt, args...)
|
2017-08-02 14:54:29 -07:00
|
|
|
#endif
|
2017-06-05 14:26:06 -07:00
|
|
|
|
2017-09-15 19:31:23 -07:00
|
|
|
//
|
|
|
|
|
#if ZT_MSG_TRANSFER == true
|
2017-09-13 16:26:27 -07:00
|
|
|
#if defined(__ANDROID__)
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_TRANS(fmt, args...) \
|
|
|
|
|
((void)__android_log_print( \
|
|
|
|
|
ANDROID_LOG_VERBOSE, \
|
|
|
|
|
ZT_LOG_TAG, \
|
|
|
|
|
"%17s:%5d:%25s: " fmt "\n", \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
##args))
|
2018-07-27 15:52:15 -07:00
|
|
|
#elif defined(_WIN32)
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_TRANS(fmt, ...) \
|
|
|
|
|
fprintf( \
|
|
|
|
|
stderr, \
|
|
|
|
|
ZT_GRN "%17s:%5d:%25s: " fmt "\n" ZT_RESET, \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
__VA_ARGS__)
|
2017-09-13 16:26:27 -07:00
|
|
|
#else
|
2021-04-17 23:46:21 -07:00
|
|
|
#define DEBUG_TRANS(fmt, args...) \
|
|
|
|
|
fprintf( \
|
|
|
|
|
stderr, \
|
|
|
|
|
ZT_GRN "%17s:%5d:%25s: " fmt "\n" ZT_RESET, \
|
|
|
|
|
ZT_FILENAME, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
__FUNCTION__, \
|
|
|
|
|
##args)
|
2017-09-13 16:26:27 -07:00
|
|
|
#endif
|
2017-08-02 14:54:29 -07:00
|
|
|
#else
|
2017-09-13 16:26:27 -07:00
|
|
|
#define DEBUG_TRANS(fmt, args...)
|
2017-08-02 14:54:29 -07:00
|
|
|
#endif
|
2021-04-17 23:46:21 -07:00
|
|
|
#else // !LIBZT_DEBUG || !__NATIVE_TEST__
|
2017-12-19 16:23:52 -08:00
|
|
|
#if defined(_WIN32)
|
|
|
|
|
#define DEBUG_ERROR(...)
|
|
|
|
|
#define DEBUG_TEST(...)
|
|
|
|
|
#define DEBUG_INFO(...)
|
|
|
|
|
#define DEBUG_TRANS(...)
|
2017-10-11 15:22:31 -07:00
|
|
|
#else
|
|
|
|
|
#define DEBUG_ERROR(fmt, args...)
|
|
|
|
|
#define DEBUG_TEST(fmt, args...)
|
|
|
|
|
#define DEBUG_INFO(fmt, args...)
|
|
|
|
|
#define DEBUG_TRANS(fmt, args...)
|
|
|
|
|
#endif
|
2017-09-13 23:21:15 -07:00
|
|
|
#endif
|
2017-09-27 02:29:04 -07:00
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
#endif // _H
|