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