2017-06-05 14:26:06 -07:00
|
|
|
/*
|
|
|
|
|
* ZeroTier SDK - Network Virtualization Everywhere
|
|
|
|
|
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* --
|
|
|
|
|
*
|
|
|
|
|
* You can be released from the requirements of the license by purchasing
|
|
|
|
|
* a commercial license. Buying such a license is mandatory as soon as you
|
|
|
|
|
* develop commercial closed-source software that incorporates or links
|
|
|
|
|
* directly against ZeroTier software without disclosing the source code
|
|
|
|
|
* of your own application.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-27 02:29:04 -07:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
*
|
|
|
|
|
* Debug macros
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef LIBZT_DEBUG_HPP
|
|
|
|
|
#define LIBZT_DEBUG_HPP
|
|
|
|
|
|
2017-06-05 14:26:06 -07:00
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
#include <sys/types.h>
|
2017-09-21 23:21:10 -07:00
|
|
|
#include <unistd.h>
|
2017-09-27 02:29:04 -07:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
#include "Platform.h"
|
2017-06-05 14:26:06 -07:00
|
|
|
|
2017-09-15 19:31:23 -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-09-27 02:29:04 -07:00
|
|
|
#define ZT_MSG_EXTRA true // If nothing in your world makes sense
|
2017-06-16 16:58:30 -07:00
|
|
|
|
2017-06-05 14:26:06 -07:00
|
|
|
#define ZT_COLOR true
|
|
|
|
|
|
|
|
|
|
// Debug output colors
|
|
|
|
|
#if defined(__APPLE__)
|
2017-08-02 14:54:29 -07:00
|
|
|
#include "TargetConditionals.h"
|
2017-06-05 14:26:06 -07:00
|
|
|
#endif
|
|
|
|
|
#if defined(ZT_COLOR) && !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
|
|
|
|
|
|
|
|
|
|
#define ZT_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // short
|
|
|
|
|
|
2017-09-21 23:21:10 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
extern unsigned int gettid(); // defined in libzt.cpp
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
#define ZT_THREAD_ID syscall(SYS_gettid)
|
|
|
|
|
#elif __APPLE__
|
2017-09-27 02:29:04 -07:00
|
|
|
#define ZT_THREAD_ID (long)0//(long)gettid()
|
2017-09-21 23:21:10 -07:00
|
|
|
#endif
|
|
|
|
|
|
2017-06-05 14:26:06 -07:00
|
|
|
#if defined(__JNI_LIB__)
|
2017-08-02 14:54:29 -07:00
|
|
|
#include <jni.h>
|
2017-06-05 14:26:06 -07:00
|
|
|
#endif
|
|
|
|
|
#if defined(__ANDROID__)
|
2017-08-02 14:54:29 -07:00
|
|
|
#include <android/log.h>
|
|
|
|
|
#define ZT_LOG_TAG "ZTSDK"
|
2017-06-05 14:26:06 -07:00
|
|
|
#endif
|
|
|
|
|
|
2017-09-13 16:26:27 -07:00
|
|
|
// Network stack debugging
|
2017-09-15 19:31:23 -07:00
|
|
|
#if defined(__ANDROID__)
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_STACK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
2017-09-21 23:21:10 -07:00
|
|
|
"STACK[%ld]: %17s:%5d:%20s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
2017-08-02 14:54:29 -07:00
|
|
|
#else
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_STACK(fmt, args...) fprintf(stderr, ZT_YEL "STACK[%ld]: %17s:%5d:%25s: " fmt \
|
2017-09-21 23:21:10 -07:00
|
|
|
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
2017-08-02 14:54:29 -07:00
|
|
|
#endif
|
|
|
|
|
|
2017-09-13 16:26:27 -07:00
|
|
|
// libzt POSIX socket emulation layer debugging
|
2017-09-15 19:31:23 -07:00
|
|
|
#if defined(LIBZT_DEBUG) || defined(__NATIVETEST__)
|
|
|
|
|
//
|
|
|
|
|
#if ZT_MSG_TEST == true
|
|
|
|
|
#if defined(__ANDROID__)
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_TEST(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
2017-09-21 23:21:10 -07:00
|
|
|
"TEST : %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
2017-09-15 19:31:23 -07:00
|
|
|
#else
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_TEST(fmt, args...) fprintf(stderr, ZT_CYN "TEST [%ld]: %17s:%5d:%25s: " fmt \
|
2017-09-21 23:21:10 -07:00
|
|
|
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
2017-09-15 19:31:23 -07:00
|
|
|
#endif
|
2017-09-13 16:26:27 -07:00
|
|
|
#else
|
2017-09-15 19:31:23 -07:00
|
|
|
#define DEBUG_TEST(fmt, args...)
|
2017-08-02 14:54:29 -07:00
|
|
|
#endif
|
|
|
|
|
|
2017-09-15 19:31:23 -07:00
|
|
|
//
|
|
|
|
|
#if ZT_MSG_ERROR == true
|
|
|
|
|
#if defined(__ANDROID__)
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_ERROR(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
2017-09-15 19:31:23 -07:00
|
|
|
"ERROR: %17s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
|
|
|
|
#else
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, ZT_RED \
|
2017-09-21 23:21:10 -07:00
|
|
|
"ERROR[%ld]: %17s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
2017-09-15 19:31:23 -07:00
|
|
|
#endif
|
2017-08-02 14:54:29 -07:00
|
|
|
#else
|
2017-09-13 16:26:27 -07:00
|
|
|
#define DEBUG_ERROR(fmt, args...)
|
|
|
|
|
#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__)
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
2017-09-13 16:26:27 -07:00
|
|
|
"INFO : %17s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
|
|
|
|
#else
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_INFO(fmt, args...) fprintf(stderr, \
|
2017-09-21 23:21:10 -07:00
|
|
|
"INFO [%ld]: %17s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, 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__)
|
2017-09-15 19:31:23 -07:00
|
|
|
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
2017-09-13 16:26:27 -07:00
|
|
|
"TRANS: %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
|
|
|
|
#else
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, ZT_GRN "TRANS[%ld]: %17s:%5d:%25s: " fmt \
|
2017-09-21 23:21:10 -07:00
|
|
|
"\n" ZT_RESET, ZT_THREAD_ID, 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
|
2017-09-13 16:26:27 -07:00
|
|
|
|
2017-09-15 19:31:23 -07:00
|
|
|
//
|
|
|
|
|
#if ZT_MSG_EXTRA == true
|
2017-09-13 16:26:27 -07:00
|
|
|
#if defined(__ANDROID__)
|
|
|
|
|
#define DEBUG_EXTRA(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
|
|
|
|
"EXTRA: %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
|
|
|
|
#else
|
2017-09-27 02:29:04 -07:00
|
|
|
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, \
|
2017-09-21 23:21:10 -07:00
|
|
|
"EXTRA[%ld]: %17s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, 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_EXTRA(fmt, args...)
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-09-15 19:31:23 -07:00
|
|
|
#else // !LIBZT_DEBUG || !__NATIVE_TEST__
|
2017-09-13 16:26:27 -07:00
|
|
|
#define DEBUG_ERROR(fmt, args...)
|
2017-09-15 19:31:23 -07:00
|
|
|
#define DEBUG_TEST(fmt, args...)
|
2017-09-13 16:26:27 -07:00
|
|
|
#define DEBUG_INFO(fmt, args...)
|
|
|
|
|
#define DEBUG_BLANK(fmt, args...)
|
|
|
|
|
#define DEBUG_ATTN(fmt, args...)
|
|
|
|
|
#define DEBUG_TRANS(fmt, args...)
|
|
|
|
|
#define DEBUG_EXTRA(fmt, args...)
|
2017-09-13 23:21:15 -07:00
|
|
|
#endif
|
2017-09-27 02:29:04 -07:00
|
|
|
|
2017-09-27 13:42:27 -07:00
|
|
|
#endif // _H
|