[88] | 1 | #ifndef Morpheo_Debug_h |
---|
| 2 | #define Morpheo_Debug_h |
---|
[2] | 3 | |
---|
[82] | 4 | /* |
---|
| 5 | * $Id: Debug.h 97 2008-12-19 15:34:00Z rosiere $ |
---|
| 6 | * |
---|
| 7 | * [ Description ] |
---|
| 8 | * |
---|
| 9 | * function to help the debugging : |
---|
| 10 | * |
---|
| 11 | * - log_printf |
---|
| 12 | * - log_begin |
---|
| 13 | * - log_end |
---|
[88] | 14 | * - log_function |
---|
| 15 | * - msg_print |
---|
[82] | 16 | * - breakpoint |
---|
| 17 | * |
---|
| 18 | * Debug's Level : |
---|
| 19 | * - None : print elementary information |
---|
| 20 | * - Info : print basic information |
---|
| 21 | * - Trace : trace internal variable |
---|
| 22 | * - Func : trace call and return function |
---|
| 23 | * - All : print all information |
---|
| 24 | */ |
---|
| 25 | |
---|
[71] | 26 | #include "Common/include/Message.h" |
---|
[97] | 27 | #include "Common/include/FromString.h" |
---|
| 28 | #include "Common/include/ChangeCase.h" |
---|
[2] | 29 | #include "Behavioural/include/Debug_component.h" |
---|
[88] | 30 | #include <systemc.h> |
---|
[2] | 31 | #include <stdio.h> |
---|
| 32 | #include <string.h> |
---|
| 33 | #include <iostream> |
---|
| 34 | #include <sstream> |
---|
| 35 | #include <string> |
---|
| 36 | |
---|
[88] | 37 | namespace morpheo { |
---|
| 38 | |
---|
[97] | 39 | typedef enum |
---|
[2] | 40 | { |
---|
| 41 | DEBUG_NONE , |
---|
| 42 | DEBUG_INFO , |
---|
| 43 | DEBUG_TRACE, |
---|
| 44 | DEBUG_FUNC , |
---|
| 45 | DEBUG_ALL |
---|
[97] | 46 | } debug_verbosity_t; |
---|
[2] | 47 | |
---|
[97] | 48 | extern debug_verbosity_t debug; |
---|
[82] | 49 | |
---|
[97] | 50 | void debug_init (void); |
---|
| 51 | void debug_init (debug_verbosity_t level); |
---|
[2] | 52 | #ifdef DEBUG |
---|
[97] | 53 | |
---|
[78] | 54 | # define log_printf(level, component, func, str... ) \ |
---|
[71] | 55 | do \ |
---|
| 56 | { \ |
---|
[97] | 57 | debug_init(); \ |
---|
| 58 | \ |
---|
| 59 | if ((debug == DEBUG_ALL ) or \ |
---|
[71] | 60 | (DEBUG_ ## level == DEBUG_NONE) or \ |
---|
[97] | 61 | (( DEBUG_ ## level <= debug) and \ |
---|
[71] | 62 | ( DEBUG_ ## component == true )) ) \ |
---|
| 63 | { \ |
---|
[88] | 64 | if (DEBUG_ ## level <= DEBUG_INFO) \ |
---|
| 65 | { \ |
---|
| 66 | msg("%s ",MSG_INFORMATION); \ |
---|
| 67 | } \ |
---|
| 68 | else \ |
---|
| 69 | { \ |
---|
| 70 | msg("%s ",MSG_DEBUG); \ |
---|
| 71 | } \ |
---|
| 72 | \ |
---|
[97] | 73 | if (debug >= DEBUG_ALL ) \ |
---|
[82] | 74 | { \ |
---|
[71] | 75 | switch (DEBUG_ ## level) \ |
---|
| 76 | { \ |
---|
| 77 | case DEBUG_NONE : msg(_("(none ) ")); break; \ |
---|
| 78 | case DEBUG_INFO : msg(_("(information) ")); break; \ |
---|
| 79 | case DEBUG_TRACE : msg(_("(trace ) ")); break; \ |
---|
| 80 | case DEBUG_FUNC : msg(_("(function ) ")); break; \ |
---|
| 81 | case DEBUG_ALL : msg(_("(all ) ")); break; \ |
---|
| 82 | default : msg(_("(undefine ) ")); break; \ |
---|
| 83 | } \ |
---|
| 84 | } \ |
---|
[97] | 85 | if (debug >= DEBUG_FUNC) \ |
---|
[71] | 86 | { \ |
---|
[88] | 87 | msg( "<%s> " ,func); \ |
---|
| 88 | msg(_("In file %s, "),__FILE__); \ |
---|
| 89 | msg(_("at line %d " ),__LINE__); \ |
---|
| 90 | msg( ": " ); \ |
---|
| 91 | } \ |
---|
| 92 | msg(str); \ |
---|
| 93 | msg("\n"); \ |
---|
[71] | 94 | } \ |
---|
| 95 | } while(0) |
---|
[82] | 96 | |
---|
| 97 | # define log_begin(component, func) \ |
---|
| 98 | do \ |
---|
| 99 | { \ |
---|
[88] | 100 | log_printf(FUNC,component,func,_("Begin")); \ |
---|
[82] | 101 | } while(0) |
---|
| 102 | |
---|
| 103 | # define log_end(component, func) \ |
---|
| 104 | do \ |
---|
| 105 | { \ |
---|
[88] | 106 | log_printf(FUNC,component,func,_("End")); \ |
---|
[82] | 107 | } while(0) |
---|
| 108 | |
---|
[2] | 109 | #else |
---|
[78] | 110 | # define log_printf(level, component, func, str... ) \ |
---|
| 111 | do \ |
---|
| 112 | { \ |
---|
| 113 | } while(0) |
---|
[81] | 114 | |
---|
[82] | 115 | # define log_begin(component, func) \ |
---|
| 116 | do \ |
---|
| 117 | { \ |
---|
| 118 | } while(0) |
---|
| 119 | |
---|
| 120 | # define log_end(component, func) \ |
---|
| 121 | do \ |
---|
| 122 | { \ |
---|
| 123 | } while(0) |
---|
| 124 | |
---|
[2] | 125 | #endif // DEBUG |
---|
[81] | 126 | |
---|
[88] | 127 | # define log_function(component,func,name) \ |
---|
| 128 | do \ |
---|
| 129 | { \ |
---|
| 130 | log_printf(TRACE,component,func,_("[%d] %s.%s"),static_cast<uint32_t>(sc_simulation_time()),name,func); \ |
---|
| 131 | } while(0) |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | #define msg_printf(type,str...) \ |
---|
| 135 | do \ |
---|
| 136 | { \ |
---|
| 137 | msg("%s ",MSG_ ## type); \ |
---|
| 138 | msg(str); \ |
---|
| 139 | msg("\n"); \ |
---|
| 140 | } while(0) |
---|
| 141 | |
---|
| 142 | |
---|
[81] | 143 | #define breakpoint(str...) \ |
---|
| 144 | do \ |
---|
| 145 | { \ |
---|
[88] | 146 | fprintf(stdout,_("%s "),MSG_BREAKPOINT); \ |
---|
| 147 | fprintf(stdout,_("Breakpoint in file %s, line %d.\n"),__FILE__,__LINE__); \ |
---|
| 148 | fprintf(stdout,_("%s "),MSG_NONE); \ |
---|
| 149 | fprintf(stdout,str); \ |
---|
| 150 | fprintf(stdout,_("\n")); \ |
---|
| 151 | fprintf(stdout,_("%s "),MSG_NONE); \ |
---|
| 152 | fprintf(stdout,_("Enter any key to continue\n")); \ |
---|
[81] | 153 | getchar(); \ |
---|
| 154 | } while(0) |
---|
| 155 | |
---|
[82] | 156 | #ifdef DEBUG_TEST |
---|
| 157 | #define TEST_PTR(x) \ |
---|
| 158 | do \ |
---|
| 159 | { \ |
---|
| 160 | if (x == NULL) \ |
---|
[88] | 161 | err(_("File %s, Line %d, this pointeur is null\n"),__FILE__,__LINE__); \ |
---|
[82] | 162 | } \ |
---|
| 163 | while (0) |
---|
| 164 | #else |
---|
| 165 | #define TEST_PTR(x) \ |
---|
| 166 | do \ |
---|
| 167 | { \ |
---|
| 168 | } \ |
---|
| 169 | while (0) |
---|
| 170 | #endif |
---|
| 171 | |
---|
[97] | 172 | |
---|
| 173 | template<> inline debug_verbosity_t fromString<debug_verbosity_t> (const std::string& x) |
---|
| 174 | { |
---|
| 175 | std::string y=x; |
---|
| 176 | LowerCase(y); |
---|
| 177 | |
---|
| 178 | if ( (y.compare("0") == 0) or |
---|
| 179 | (y.compare("none") == 0)) |
---|
| 180 | return DEBUG_NONE ; |
---|
| 181 | if ( (y.compare("1") == 0) or |
---|
| 182 | (y.compare("info") == 0)) |
---|
| 183 | return DEBUG_INFO ; |
---|
| 184 | if ( (y.compare("2") == 0) or |
---|
| 185 | (y.compare("trace") == 0)) |
---|
| 186 | return DEBUG_TRACE; |
---|
| 187 | if ( (y.compare("3") == 0) or |
---|
| 188 | (y.compare("func") == 0)) |
---|
| 189 | return DEBUG_FUNC ; |
---|
| 190 | if ( (y.compare("4") == 0) or |
---|
| 191 | (y.compare("all") == 0)) |
---|
| 192 | return DEBUG_ALL ; |
---|
| 193 | |
---|
| 194 | #ifdef DEBUG |
---|
| 195 | return DEBUG; |
---|
| 196 | #else |
---|
| 197 | return DEBUG_NONE ; |
---|
| 198 | #endif |
---|
| 199 | } |
---|
| 200 | |
---|
[88] | 201 | }; // end namespace morpheo |
---|
[2] | 202 | #endif // !DEBUG_H |
---|