2 #ifndef UVCC_DEBUG__HPP 3 #define UVCC_DEBUG__HPP 13 #define MAKE_LITERAL_STRING_VERBATIM(...) #__VA_ARGS__ 14 #define MAKE_LITERAL_STRING_AFTER_EXPANDING(...) MAKE_LITERAL_STRING_VERBATIM(__VA_ARGS__) 16 #define CONCATENATE_VERBATIM(left, right) left ## right 17 #define CONCATENATE_AFTER_EXPANDING(left, right) CONCATENATE_VERBATIM(left, right) 20 #define uvcc_debug_log_if(log_condition, printf_args...) do { 24 std::fprintf(stderr, "[debug]"); 25 int n = std::fprintf(stderr, " " printf_args); 27 std::fprintf(stderr, "\n"); 29 std::fprintf(stderr, "log: function=%s file=%s line=%i\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); 34 #define uvcc_debug_function_enter(printf_args...) do { 36 std::fprintf(stderr, "[debug] enter function: %s", __PRETTY_FUNCTION__); 37 if (sizeof(MAKE_LITERAL_STRING_AFTER_EXPANDING(printf_args)) > 1
) std::fprintf(stderr, ": " printf_args); 38 std::fprintf(stderr, "\n"); 42 #define uvcc_debug_function_return(printf_args...) do { 44 std::fprintf(stderr, "[debug] return from function: %s", __PRETTY_FUNCTION__); 45 if (sizeof(MAKE_LITERAL_STRING_AFTER_EXPANDING(printf_args)) > 1
) std::fprintf(stderr, ": " printf_args); 46 std::fprintf(stderr, "\n"); 50 #define uvcc_debug_condition(condition, context_printf_args...) do { 53 std::fprintf(stderr, "[debug] condition (%s):", MAKE_LITERAL_STRING_VERBATIM(condition)); 54 int n = std::fprintf(stderr, " " context_printf_args); 55 std::fprintf(stderr, "%s%s\n", (n > 1
)?": ":"", c?"TRUE":"false"); 59 #define uvcc_debug_do_if(log_condition, operators...) do { 68 #define uvcc_debug_log_if(log_condition, ...) (void)(log_condition) 69 #define uvcc_debug_function_enter(...) 70 #define uvcc_debug_function_return(...) 71 #define uvcc_debug_condition(condition, ...) (void)(condition) 72 #define uvcc_debug_do_if(log_condition, ...) (void)(log_condition) 77 #pragma GCC diagnostic push 78 #pragma GCC diagnostic ignored "-Wunused-function" 85 template<
class _UVCC_CLASS_ >
86 typename _UVCC_CLASS_::instance* instance(_UVCC_CLASS_ &_var)
noexcept 88 return _UVCC_CLASS_::instance::from(
static_cast<
typename _UVCC_CLASS_::uv_t* >(_var));
92 const char* handle_type_name(::uv_handle_t *_uv_handle)
noexcept 95 switch (_uv_handle->type)
97 case UV_UNKNOWN_HANDLE: ret =
"UNKNOWN";
break;
98 #define XX(X, x) case UV_##X: ret = #x; break; 99 UV_HANDLE_TYPE_MAP(XX)
101 case UV_FILE: ret =
"file";
break;
102 default: ret =
"<UNDEFINED>";
break;
108 void print_handle(::uv_handle_t* _uv_handle)
noexcept 111 "[debug] %s handle [0x%08tX]: has_ref=%i is_active=%i is_closing=%i\n",
112 handle_type_name(_uv_handle), (ptrdiff_t)_uv_handle,
113 ::uv_has_ref(_uv_handle), ::uv_is_active(_uv_handle), ::uv_is_closing(_uv_handle)
119 void print_loop_handles(::uv_loop_t *_uv_loop)
121 std::fprintf(stderr,
"[debug] handles associated with loop [0x%08tX]: {\n", (ptrdiff_t)_uv_loop);
123 static_cast< ::uv_loop_t* >(_uv_loop),
124 [](::uv_handle_t *_h,
void*){ print_handle(_h); },
127 std::fprintf(stderr,
"[debug] }\n");
133 #pragma GCC diagnostic pop Namespace for all uvcc definitions.