[88] | 1 | #ifndef Morpheo_Debug_h |
---|
| 2 | #define Morpheo_Debug_h |
---|
[2] | 3 | |
---|
[82] | 4 | /* |
---|
| 5 | * $Id: Debug.h 138 2010-05-12 17:34:01Z 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/ChangeCase.h" |
---|
[2] | 30 | #include "Behavioural/include/Debug_component.h" |
---|
[118] | 31 | #include "Behavioural/include/Model.h" |
---|
| 32 | #include "Behavioural/include/Simulation.h" |
---|
[88] | 33 | #include <systemc.h> |
---|
[2] | 34 | #include <stdio.h> |
---|
| 35 | #include <string.h> |
---|
| 36 | #include <iostream> |
---|
| 37 | #include <sstream> |
---|
| 38 | #include <string> |
---|
[112] | 39 | #include "Common/include/MemCheck.h" |
---|
[2] | 40 | |
---|
[88] | 41 | namespace morpheo { |
---|
| 42 | |
---|
[118] | 43 | // typedef enum |
---|
| 44 | // { |
---|
| 45 | // DEBUG_NONE , |
---|
| 46 | // DEBUG_INFO , |
---|
| 47 | // DEBUG_TRACE, |
---|
| 48 | // DEBUG_FUNC , |
---|
| 49 | // DEBUG_ALL |
---|
| 50 | // } debug_verbosity_t; |
---|
[2] | 51 | |
---|
[97] | 52 | extern debug_verbosity_t debug; |
---|
[100] | 53 | extern bool debug_cycle_test; |
---|
| 54 | extern double debug_cycle_start; |
---|
| 55 | extern double debug_cycle_stop ; |
---|
[110] | 56 | extern double debug_idle_cycle; |
---|
| 57 | extern uint32_t debug_idle_time; |
---|
[82] | 58 | |
---|
[100] | 59 | void debug_init (void); |
---|
| 60 | void debug_init (debug_verbosity_t level, |
---|
| 61 | double cycle_start, |
---|
[109] | 62 | double cycle_stop , |
---|
[110] | 63 | double idle_cycle , |
---|
| 64 | uint32_t idle_time ); |
---|
[100] | 65 | |
---|
| 66 | #ifdef SYSTEMC |
---|
| 67 | #define debug_test_simulation_time \ |
---|
| 68 | (not debug_cycle_test or \ |
---|
[138] | 69 | ((simulation_cycle() >= debug_cycle_start) and \ |
---|
| 70 | ((simulation_cycle() <= debug_cycle_stop) or \ |
---|
| 71 | (debug_cycle_stop == -1)))) |
---|
[100] | 72 | #else |
---|
| 73 | #define debug_test_simulation_time true |
---|
| 74 | #endif |
---|
| 75 | |
---|
[2] | 76 | #ifdef DEBUG |
---|
[78] | 77 | # define log_printf(level, component, func, str... ) \ |
---|
[71] | 78 | do \ |
---|
| 79 | { \ |
---|
[97] | 80 | debug_init(); \ |
---|
| 81 | \ |
---|
[129] | 82 | if (debug_test_simulation_time and \ |
---|
[138] | 83 | (( DEBUG_ ## level <= debug) and \ |
---|
| 84 | ( morpheo::behavioural::_model.get_debug(NAME_ ## component)))) \ |
---|
[129] | 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 | \ |
---|
[129] | 95 | if (debug >= DEBUG_FUNC) \ |
---|
| 96 | { \ |
---|
| 97 | msg( "<%s> " ,func); \ |
---|
| 98 | msg(_("In file %s, "),__FILE__); \ |
---|
| 99 | msg(_("at line %d " ),__LINE__); \ |
---|
| 100 | msg( ": " ); \ |
---|
| 101 | } \ |
---|
| 102 | msg(str); \ |
---|
| 103 | msg("\n"); \ |
---|
| 104 | } \ |
---|
[71] | 105 | } while(0) |
---|
[82] | 106 | |
---|
| 107 | # define log_begin(component, func) \ |
---|
| 108 | do \ |
---|
| 109 | { \ |
---|
[88] | 110 | log_printf(FUNC,component,func,_("Begin")); \ |
---|
[82] | 111 | } while(0) |
---|
| 112 | |
---|
| 113 | # define log_end(component, func) \ |
---|
| 114 | do \ |
---|
| 115 | { \ |
---|
[88] | 116 | log_printf(FUNC,component,func,_("End")); \ |
---|
[82] | 117 | } while(0) |
---|
| 118 | |
---|
[2] | 119 | #else |
---|
[78] | 120 | # define log_printf(level, component, func, str... ) \ |
---|
| 121 | do \ |
---|
| 122 | { \ |
---|
| 123 | } while(0) |
---|
[81] | 124 | |
---|
[82] | 125 | # define log_begin(component, func) \ |
---|
| 126 | do \ |
---|
| 127 | { \ |
---|
| 128 | } while(0) |
---|
| 129 | |
---|
| 130 | # define log_end(component, func) \ |
---|
| 131 | do \ |
---|
| 132 | { \ |
---|
| 133 | } while(0) |
---|
| 134 | |
---|
[2] | 135 | #endif // DEBUG |
---|
[81] | 136 | |
---|
[88] | 137 | # define log_function(component,func,name) \ |
---|
| 138 | do \ |
---|
| 139 | { \ |
---|
[113] | 140 | log_printf(TRACE,component,func,_("[%d] %s.%s"),static_cast<uint32_t>(simulation_cycle()),name,func); \ |
---|
[88] | 141 | } while(0) |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | #define msg_printf(type,str...) \ |
---|
| 145 | do \ |
---|
| 146 | { \ |
---|
| 147 | msg("%s ",MSG_ ## type); \ |
---|
| 148 | msg(str); \ |
---|
| 149 | msg("\n"); \ |
---|
| 150 | } while(0) |
---|
| 151 | |
---|
| 152 | |
---|
[81] | 153 | #define breakpoint(str...) \ |
---|
| 154 | do \ |
---|
| 155 | { \ |
---|
[138] | 156 | fmsg(_("%s "),MSG_BREAKPOINT); \ |
---|
| 157 | fmsg(_("Breakpoint in file %s, line %d.\n"),__FILE__,__LINE__); \ |
---|
| 158 | fmsg(_("%s "),MSG_NONE); \ |
---|
| 159 | fmsg(str); \ |
---|
| 160 | fmsg(_("\n")); \ |
---|
| 161 | fmsg(_("%s "),MSG_NONE); \ |
---|
| 162 | fmsg(_("Enter any key to continue\n")); \ |
---|
[81] | 163 | getchar(); \ |
---|
| 164 | } while(0) |
---|
| 165 | |
---|
[82] | 166 | #ifdef DEBUG_TEST |
---|
| 167 | #define TEST_PTR(x) \ |
---|
| 168 | do \ |
---|
| 169 | { \ |
---|
| 170 | if (x == NULL) \ |
---|
[88] | 171 | err(_("File %s, Line %d, this pointeur is null\n"),__FILE__,__LINE__); \ |
---|
[82] | 172 | } \ |
---|
| 173 | while (0) |
---|
| 174 | #else |
---|
| 175 | #define TEST_PTR(x) \ |
---|
| 176 | do \ |
---|
| 177 | { \ |
---|
| 178 | } \ |
---|
| 179 | while (0) |
---|
| 180 | #endif |
---|
| 181 | |
---|
[88] | 182 | }; // end namespace morpheo |
---|
[2] | 183 | #endif // !DEBUG_H |
---|