[88] | 1 | #ifndef Morpheo_Debug_h |
---|
| 2 | #define Morpheo_Debug_h |
---|
[2] | 3 | |
---|
[82] | 4 | /* |
---|
| 5 | * $Id: Debug.h 109 2009-02-16 20:28:31Z 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; |
---|
[100] | 49 | extern bool debug_cycle_test; |
---|
| 50 | extern double debug_cycle_start; |
---|
| 51 | extern double debug_cycle_stop ; |
---|
[109] | 52 | extern double debug_cycle_idle; |
---|
[82] | 53 | |
---|
[100] | 54 | void debug_init (void); |
---|
| 55 | void debug_init (debug_verbosity_t level, |
---|
| 56 | double cycle_start, |
---|
[109] | 57 | double cycle_stop , |
---|
| 58 | double cycle_idle); |
---|
[100] | 59 | |
---|
| 60 | #ifdef SYSTEMC |
---|
| 61 | #define debug_test_simulation_time \ |
---|
| 62 | (not debug_cycle_test or \ |
---|
| 63 | ( (sc_simulation_time() >= debug_cycle_start) and \ |
---|
| 64 | ((sc_simulation_time() <= debug_cycle_stop) or \ |
---|
| 65 | (debug_cycle_stop == -1)))) |
---|
| 66 | #else |
---|
| 67 | #define debug_test_simulation_time true |
---|
| 68 | #endif |
---|
| 69 | |
---|
[2] | 70 | #ifdef DEBUG |
---|
[78] | 71 | # define log_printf(level, component, func, str... ) \ |
---|
[71] | 72 | do \ |
---|
| 73 | { \ |
---|
[97] | 74 | debug_init(); \ |
---|
| 75 | \ |
---|
[100] | 76 | if (debug_test_simulation_time) \ |
---|
| 77 | if ((debug == DEBUG_ALL ) or \ |
---|
| 78 | (DEBUG_ ## level == DEBUG_NONE) or \ |
---|
| 79 | (( DEBUG_ ## level <= debug) and \ |
---|
| 80 | ( DEBUG_ ## component == true )) ) \ |
---|
| 81 | { \ |
---|
| 82 | if (DEBUG_ ## level <= DEBUG_INFO) \ |
---|
| 83 | { \ |
---|
| 84 | msg("%s ",MSG_INFORMATION); \ |
---|
| 85 | } \ |
---|
| 86 | else \ |
---|
| 87 | { \ |
---|
| 88 | msg("%s ",MSG_DEBUG); \ |
---|
| 89 | } \ |
---|
[88] | 90 | \ |
---|
[100] | 91 | if (debug >= DEBUG_ALL ) \ |
---|
| 92 | { \ |
---|
| 93 | switch (DEBUG_ ## level) \ |
---|
| 94 | { \ |
---|
| 95 | case DEBUG_NONE : msg(_("(none ) ")); break; \ |
---|
| 96 | case DEBUG_INFO : msg(_("(information) ")); break; \ |
---|
| 97 | case DEBUG_TRACE : msg(_("(trace ) ")); break; \ |
---|
| 98 | case DEBUG_FUNC : msg(_("(function ) ")); break; \ |
---|
| 99 | case DEBUG_ALL : msg(_("(all ) ")); break; \ |
---|
| 100 | default : msg(_("(undefine ) ")); break; \ |
---|
| 101 | } \ |
---|
| 102 | } \ |
---|
| 103 | if (debug >= DEBUG_FUNC) \ |
---|
| 104 | { \ |
---|
| 105 | msg( "<%s> " ,func); \ |
---|
| 106 | msg(_("In file %s, "),__FILE__); \ |
---|
| 107 | msg(_("at line %d " ),__LINE__); \ |
---|
| 108 | msg( ": " ); \ |
---|
| 109 | } \ |
---|
| 110 | msg(str); \ |
---|
| 111 | msg("\n"); \ |
---|
| 112 | } \ |
---|
[71] | 113 | } while(0) |
---|
[82] | 114 | |
---|
| 115 | # define log_begin(component, func) \ |
---|
| 116 | do \ |
---|
| 117 | { \ |
---|
[88] | 118 | log_printf(FUNC,component,func,_("Begin")); \ |
---|
[82] | 119 | } while(0) |
---|
| 120 | |
---|
| 121 | # define log_end(component, func) \ |
---|
| 122 | do \ |
---|
| 123 | { \ |
---|
[88] | 124 | log_printf(FUNC,component,func,_("End")); \ |
---|
[82] | 125 | } while(0) |
---|
| 126 | |
---|
[2] | 127 | #else |
---|
[78] | 128 | # define log_printf(level, component, func, str... ) \ |
---|
| 129 | do \ |
---|
| 130 | { \ |
---|
| 131 | } while(0) |
---|
[81] | 132 | |
---|
[82] | 133 | # define log_begin(component, func) \ |
---|
| 134 | do \ |
---|
| 135 | { \ |
---|
| 136 | } while(0) |
---|
| 137 | |
---|
| 138 | # define log_end(component, func) \ |
---|
| 139 | do \ |
---|
| 140 | { \ |
---|
| 141 | } while(0) |
---|
| 142 | |
---|
[2] | 143 | #endif // DEBUG |
---|
[81] | 144 | |
---|
[88] | 145 | # define log_function(component,func,name) \ |
---|
| 146 | do \ |
---|
| 147 | { \ |
---|
| 148 | log_printf(TRACE,component,func,_("[%d] %s.%s"),static_cast<uint32_t>(sc_simulation_time()),name,func); \ |
---|
| 149 | } while(0) |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | #define msg_printf(type,str...) \ |
---|
| 153 | do \ |
---|
| 154 | { \ |
---|
| 155 | msg("%s ",MSG_ ## type); \ |
---|
| 156 | msg(str); \ |
---|
| 157 | msg("\n"); \ |
---|
| 158 | } while(0) |
---|
| 159 | |
---|
| 160 | |
---|
[81] | 161 | #define breakpoint(str...) \ |
---|
| 162 | do \ |
---|
| 163 | { \ |
---|
[88] | 164 | fprintf(stdout,_("%s "),MSG_BREAKPOINT); \ |
---|
| 165 | fprintf(stdout,_("Breakpoint in file %s, line %d.\n"),__FILE__,__LINE__); \ |
---|
| 166 | fprintf(stdout,_("%s "),MSG_NONE); \ |
---|
| 167 | fprintf(stdout,str); \ |
---|
| 168 | fprintf(stdout,_("\n")); \ |
---|
| 169 | fprintf(stdout,_("%s "),MSG_NONE); \ |
---|
| 170 | fprintf(stdout,_("Enter any key to continue\n")); \ |
---|
[81] | 171 | getchar(); \ |
---|
| 172 | } while(0) |
---|
| 173 | |
---|
[82] | 174 | #ifdef DEBUG_TEST |
---|
| 175 | #define TEST_PTR(x) \ |
---|
| 176 | do \ |
---|
| 177 | { \ |
---|
| 178 | if (x == NULL) \ |
---|
[88] | 179 | err(_("File %s, Line %d, this pointeur is null\n"),__FILE__,__LINE__); \ |
---|
[82] | 180 | } \ |
---|
| 181 | while (0) |
---|
| 182 | #else |
---|
| 183 | #define TEST_PTR(x) \ |
---|
| 184 | do \ |
---|
| 185 | { \ |
---|
| 186 | } \ |
---|
| 187 | while (0) |
---|
| 188 | #endif |
---|
| 189 | |
---|
[97] | 190 | |
---|
| 191 | template<> inline debug_verbosity_t fromString<debug_verbosity_t> (const std::string& x) |
---|
| 192 | { |
---|
| 193 | std::string y=x; |
---|
| 194 | LowerCase(y); |
---|
| 195 | |
---|
| 196 | if ( (y.compare("0") == 0) or |
---|
| 197 | (y.compare("none") == 0)) |
---|
| 198 | return DEBUG_NONE ; |
---|
| 199 | if ( (y.compare("1") == 0) or |
---|
| 200 | (y.compare("info") == 0)) |
---|
| 201 | return DEBUG_INFO ; |
---|
| 202 | if ( (y.compare("2") == 0) or |
---|
| 203 | (y.compare("trace") == 0)) |
---|
| 204 | return DEBUG_TRACE; |
---|
| 205 | if ( (y.compare("3") == 0) or |
---|
| 206 | (y.compare("func") == 0)) |
---|
| 207 | return DEBUG_FUNC ; |
---|
| 208 | if ( (y.compare("4") == 0) or |
---|
| 209 | (y.compare("all") == 0)) |
---|
| 210 | return DEBUG_ALL ; |
---|
| 211 | |
---|
| 212 | #ifdef DEBUG |
---|
| 213 | return DEBUG; |
---|
| 214 | #else |
---|
| 215 | return DEBUG_NONE ; |
---|
| 216 | #endif |
---|
| 217 | } |
---|
| 218 | |
---|
[88] | 219 | }; // end namespace morpheo |
---|
[2] | 220 | #endif // !DEBUG_H |
---|