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