1 #ifndef ctags_trace_h_ 2 #define ctags_trace_h_ 3 /* 4 * Copyright (c) 2016, Szymon Tomasz Stefanek 5 * 6 * This source code is released for free distribution under the terms of the 7 * GNU General Public License version 2 or (at your option) any later version. 8 * 9 * Tracing facility. 10 */ 11 12 #include "general.h" 13 #include "debug.h" 14 15 // 16 // Master tracing switch. 17 // 18 // Uncomment this to enable extensive debugging to stderr in code. 19 // Use only for development as tracing reduces performance. 20 // 21 // "./configure --enable-debugging" defines DEBUG. 22 // When running ctags, pass --_trace=<LANG>[,<LANG>]* option. 23 // 24 #ifdef DEBUG 25 #define DO_TRACING 26 #endif 27 28 bool isTraced (void); 29 void traceLanguage (langType language); 30 bool isLanguageTraced (langType language); 31 32 void traceEnter(const char * szFunction,const char * szFormat,...); 33 void traceLeave(const char * szFunction,const char * szFormat,...); 34 void tracePrint(const char * szFunction,const char * szFormat,...); 35 36 void tracePrintPrefix(const char * szFunction); 37 void tracePrintFmt(const char * szFormat,...); 38 void tracePrintNewline(void); 39 40 void traceMain(void); 41 bool isMainTraced(void); 42 43 #ifdef DO_TRACING 44 45 #define TRACE_ENTER() traceEnter(__func__,"") 46 #define TRACE_LEAVE() traceLeave(__func__,"") 47 48 #define TRACE_ENTER_TEXT(_szFormat,...) \ 49 traceEnter(__func__,_szFormat,## __VA_ARGS__) 50 51 #define TRACE_LEAVE_TEXT(_szFormat,...) \ 52 traceLeave(__func__,_szFormat,## __VA_ARGS__) 53 54 #define TRACE_PRINT(_szFormat,...) \ 55 tracePrint(__func__,_szFormat,## __VA_ARGS__) 56 57 /* TRACE_PRINT prints line at once. 58 * If you want to print a trace line incrementally, 59 * use following macros. 60 * 61 * TRACE_PRINT_PREFIX: just print a trace prefix. No newline. 62 * TRACE_PRINT_FMT: print as a format. No prefix, no newline. 63 * TRACE_PRINT_NEWLINE: just print a newline. 64 */ 65 #define TRACE_PRINT_PREFIX() \ 66 tracePrintPrefix(__func__) 67 #define TRACE_PRINT_FMT(_szFormat,...) \ 68 tracePrintFmt(_szFormat,## __VA_ARGS__) 69 #define TRACE_PRINT_NEWLINE() \ 70 tracePrintNewline() 71 72 #define TRACE_ASSERT(_condition,_szFormat,...) \ 73 do { \ 74 if(!(_condition)) \ 75 { \ 76 tracePrint(__func__,_szFormat,## __VA_ARGS__); \ 77 Assert(false); \ 78 } \ 79 } while(0) 80 81 #else //!DO_TRACING 82 83 #define TRACE_ENTER() do { } while(0) 84 #define TRACE_LEAVE() do { } while(0) 85 86 #define TRACE_ENTER_TEXT(_szFormat,...) do { } while(0) 87 #define TRACE_LEAVE_TEXT(_szFormat,...) do { } while(0) 88 89 #define TRACE_PRINT(_szFormat,...) do { } while(0) 90 91 #define TRACE_PRINT_PREFIX() do { } while(0) 92 #define TRACE_PRINT_FMT(_szFormat,...) do { } while(0) 93 #define TRACE_PRINT_NEWLINE() do { } while(0) 94 95 #define TRACE_ASSERT(_condition,_szFormat,...) do { } while(0) 96 97 #endif //!DO_TRACING 98 99 100 #endif //!ctags_trace_h_ 101