[2] | 1 | #ifndef DEBUG_H |
---|
| 2 | #define DEBUG_H |
---|
| 3 | |
---|
[82] | 4 | /* |
---|
| 5 | * $Id: Debug.h 83 2008-05-09 18:00:21Z rosiere $ |
---|
| 6 | * |
---|
| 7 | * [ Description ] |
---|
| 8 | * |
---|
| 9 | * function to help the debugging : |
---|
| 10 | * |
---|
| 11 | * - debug_tab |
---|
| 12 | * - log_printf |
---|
| 13 | * - log_begin |
---|
| 14 | * - log_end |
---|
| 15 | * - breakpoint |
---|
| 16 | * |
---|
| 17 | * Debug's Level : |
---|
| 18 | * - None : print elementary information |
---|
| 19 | * - Info : print basic information |
---|
| 20 | * - Trace : trace internal variable |
---|
| 21 | * - Func : trace call and return function |
---|
| 22 | * - All : print all information |
---|
| 23 | */ |
---|
| 24 | |
---|
[71] | 25 | #include "Common/include/Message.h" |
---|
[2] | 26 | #include "Behavioural/include/Debug_component.h" |
---|
[82] | 27 | #include "Behavioural/include/Environment.h" |
---|
[2] | 28 | #include <stdio.h> |
---|
| 29 | #include <string.h> |
---|
| 30 | #include <iostream> |
---|
| 31 | #include <sstream> |
---|
| 32 | #include <string> |
---|
| 33 | |
---|
| 34 | enum _debug_verbosity |
---|
| 35 | { |
---|
| 36 | DEBUG_NONE , |
---|
| 37 | DEBUG_INFO , |
---|
| 38 | DEBUG_TRACE, |
---|
| 39 | DEBUG_FUNC , |
---|
| 40 | DEBUG_ALL |
---|
| 41 | }; |
---|
| 42 | |
---|
[82] | 43 | std::string debug_tab (void); |
---|
| 44 | void debug_tab_inc (void); |
---|
| 45 | void debug_tab_dec (void); |
---|
| 46 | |
---|
[2] | 47 | #ifdef DEBUG |
---|
[78] | 48 | # define log_printf(level, component, func, str... ) \ |
---|
[71] | 49 | do \ |
---|
| 50 | { \ |
---|
| 51 | if ((DEBUG == DEBUG_ALL ) or \ |
---|
| 52 | (DEBUG_ ## level == DEBUG_NONE) or \ |
---|
| 53 | (( DEBUG_ ## level <= DEBUG) and \ |
---|
| 54 | ( DEBUG_ ## component == true )) ) \ |
---|
| 55 | { \ |
---|
[82] | 56 | if (DEBUG >= DEBUG_FUNC) \ |
---|
| 57 | { \ |
---|
| 58 | msg(_("%s"),debug_tab().c_str()); \ |
---|
| 59 | } \ |
---|
[71] | 60 | if (DEBUG >= DEBUG_ALL ) \ |
---|
| 61 | { \ |
---|
| 62 | switch (DEBUG_ ## level) \ |
---|
| 63 | { \ |
---|
| 64 | case DEBUG_NONE : msg(_("(none ) ")); break; \ |
---|
| 65 | case DEBUG_INFO : msg(_("(information) ")); break; \ |
---|
| 66 | case DEBUG_TRACE : msg(_("(trace ) ")); break; \ |
---|
| 67 | case DEBUG_FUNC : msg(_("(function ) ")); break; \ |
---|
| 68 | case DEBUG_ALL : msg(_("(all ) ")); break; \ |
---|
| 69 | default : msg(_("(undefine ) ")); break; \ |
---|
| 70 | } \ |
---|
| 71 | } \ |
---|
| 72 | if (DEBUG >= DEBUG_FUNC) \ |
---|
| 73 | { \ |
---|
[78] | 74 | msg(_("<%s> "),func); \ |
---|
[71] | 75 | msg(_("In file %s, "),__FILE__); \ |
---|
[78] | 76 | msg(_("at line %d " ),__LINE__); \ |
---|
| 77 | msg(_(": ")); \ |
---|
[71] | 78 | } \ |
---|
| 79 | msg(str); \ |
---|
| 80 | msg(_("\n")); \ |
---|
| 81 | fflush (stdout); \ |
---|
| 82 | } \ |
---|
| 83 | } while(0) |
---|
[82] | 84 | |
---|
| 85 | # define log_begin(component, func) \ |
---|
| 86 | do \ |
---|
| 87 | { \ |
---|
| 88 | debug_tab_inc (); \ |
---|
| 89 | log_printf(FUNC,component,func,"Begin"); \ |
---|
| 90 | } while(0) |
---|
| 91 | |
---|
| 92 | # define log_end(component, func) \ |
---|
| 93 | do \ |
---|
| 94 | { \ |
---|
| 95 | log_printf(FUNC,component,func,"End"); \ |
---|
| 96 | debug_tab_dec (); \ |
---|
| 97 | } while(0) |
---|
| 98 | |
---|
[2] | 99 | #else |
---|
[78] | 100 | # define log_printf(level, component, func, str... ) \ |
---|
| 101 | do \ |
---|
| 102 | { \ |
---|
| 103 | } while(0) |
---|
[81] | 104 | |
---|
[82] | 105 | # define log_begin(component, func) \ |
---|
| 106 | do \ |
---|
| 107 | { \ |
---|
| 108 | } while(0) |
---|
| 109 | |
---|
| 110 | # define log_end(component, func) \ |
---|
| 111 | do \ |
---|
| 112 | { \ |
---|
| 113 | } while(0) |
---|
| 114 | |
---|
[2] | 115 | #endif // DEBUG |
---|
[81] | 116 | |
---|
| 117 | #define breakpoint(str...) \ |
---|
| 118 | do \ |
---|
| 119 | { \ |
---|
| 120 | msg(_("Breakpoint : file %s, line %d. Enter Any key to continue\n"),__FILE__,__LINE__); \ |
---|
| 121 | msg(str); \ |
---|
| 122 | getchar(); \ |
---|
| 123 | } while(0) |
---|
| 124 | |
---|
[82] | 125 | #ifdef DEBUG_TEST |
---|
| 126 | #define TEST_PTR(x) \ |
---|
| 127 | do \ |
---|
| 128 | { \ |
---|
| 129 | if (x == NULL) \ |
---|
[83] | 130 | err(_("%s File %s, Line %d, this pointeur is null\n"),MSG_ERROR,__FILE__,__LINE__); \ |
---|
[82] | 131 | } \ |
---|
| 132 | while (0) |
---|
| 133 | #else |
---|
| 134 | #define TEST_PTR(x) \ |
---|
| 135 | do \ |
---|
| 136 | { \ |
---|
| 137 | } \ |
---|
| 138 | while (0) |
---|
| 139 | #endif |
---|
| 140 | |
---|
| 141 | |
---|
[2] | 142 | #endif // !DEBUG_H |
---|