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