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