📄 debug.h
字号:
/** @file debug.h defines methods to print debug messages * * Macros are not fitted for not GNUC compiler, disabling ALL debug messages !!! * (including error notifications !) *//** @todo comment debug.h */#ifndef DEBUG_H_HAS_BEEN_INCLUDED#define DEBUG_H_HAS_BEEN_INCLUDED#include "config.h"#include <stdlib.h>#include <stdio.h>#include <string.h>#include <errno.h>#include <sys/time.h>#define HUNTPLOGD() PLOGD_HUNT(__FILE__, __LINE__)void PLOGD_HUNT(char *file, int line);extern int errno;/** * The functions that begin with __ are internals functions. They have to never be called * by the user directly. User the functions without the prepending __ */#ifdef DEBUG# define SHOW_TIME(INSTR) \ do { \ struct timeval tv1, tv2; \ long long st1, st2; \ gettimeofday( &tv1, NULL ); \ INSTR; \ gettimeofday( &tv2, NULL ); \ st1 = (tv1.tv_sec) * 1000000 + (tv1.tv_usec); \ st2 = (tv2.tv_sec) * 1000000 + (tv2.tv_usec); \ printi( "TIME", #INSTR " %Ld\n", st2-st1);\ } while(0)#else# define SHOW_TIME(INSTR) INSTR#endif#ifdef DEBUG# define TAKE_TIME(TV_START, TV_END, INSTR) \ do { \ gettimeofday( &(TV_START), NULL ); \ INSTR; \ gettimeofday( &(TV_END), NULL ); \ } while(0)#else # define TAKE_TIME(TV_START, TV_END, INSTR) INSTR#endif#ifdef DEBUG# include <signal.h># define ASSERT(Inst) if( (Inst) == 0 ) printw("ASSERT("__STRING(Inst)") failed"), raise(SIGABRT)#else# define ASSERT(Inst)#endifextern void initLog(char *uid, char *logd);extern void closeLog(void);# define initDebug(uid, initline) initLog(uid, initline)# define closeDebug() closeLog()extern void __log_message(const char *lvl, const char *file, const char *func, const int lineno, const char *format, ...);extern void __log_error(const char *lvl, const char *file, const char *func, const int lineno, const char *format, ...);#ifndef __GNUC__#warning "Non GNU C Compiler detected, all debug messages are desactivated"static int printi(char *hdr, char *format, ...) {} static int printp(char *format, ...) {}static int printw(char *format, ...) {}static int printe(char *format, ...) {}static int printq(char *format, ...) { exit(-1); }static void qerror(char *format, ...) { exit(-1); }#else /* __GNUC__ */# define _printi(hdr, fmt...) __log_message(hdr, __FILE__, __FUNCTION__, __LINE__, fmt)# define _printe(hdr, fmt...) __log_error(hdr, __FILE__, __FUNCTION__, __LINE__, fmt)#define LVL_WARNING ((char*)0x01)#define LVL_ERROR ((char*)0x02)#define LVL_QUIT ((char*)0x03)#define LVL_QERROR ((char*)0x04)#define LVL_MAX 5# define printw(fmt...) _printi(LVL_WARNING, fmt)# define printe(fmt...) _printe(LVL_ERROR, fmt)# define printq(fmt...) (_printi(LVL_QUIT, fmt), exit(-1))# define qerror(fmt...) (_printe(LVL_QERROR, fmt), exit(-errno))# ifdef DEBUG# define printi(hdr, fmt...) _printi(hdr, fmt)# else# define printi(hdr, fmt...) do {} while(0)# endif# ifdef PROFILE# define printp(fmt...) _printi("P ", fmt)# else# define printp(fmt...) do {} while(0)# endif#endif /* GNUC */#ifdef HARDMALLOC#define MALLOCLIMIT(s) (1) //((s>1024) && (s<1024*1024))/*static void *mymalloc(int s){ if(MALLOCLIMIT(s)) printw("malloc(%d)", s); return malloc(s);}static void *mycalloc(int a, int b){ if(MALLOCLIMIT(a*b)) printw("calloc(%d, %d)", a, b); return calloc(a, b);}static void *myrealloc(void *p, int s){ if(MALLOCLIMIT(s)) printw("realloc(%p, %d)", p, s); return realloc(p, s);}*/extern unsigned long long totmalloc;#define malloc(s) (MALLOCLIMIT((s))?printw("malloc(%d) (total:%llu)", (s), totmalloc):0,totmalloc+=s,malloc((s)))#define calloc(a, b) (MALLOCLIMIT((a)*(b))?printw("calloc(%d,%d) (total:%llu)", (a), (b), totmalloc):0,totmalloc+=(a)*(b),calloc((a),(b)))#define realloc(p, s) (MALLOCLIMIT((s))?printw("realloc(%d, %d) (total:%llu)", (p), (s), totmalloc):0,totmalloc+=s,realloc((p), (s)))#endif#endif /* DEBUG_H_HAS_BEEN_INCLUDED */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -