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