1 | #ifndef Morpheo_Debug_h |
---|
2 | #define Morpheo_Debug_h |
---|
3 | |
---|
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 |
---|
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/Systemc.h" |
---|
27 | #include "Common/include/Message.h" |
---|
28 | #include "Common/include/FromString.h" |
---|
29 | #include "Common/include/ChangeCase.h" |
---|
30 | #include "Behavioural/include/Debug_component.h" |
---|
31 | #include <systemc.h> |
---|
32 | #include <stdio.h> |
---|
33 | #include <string.h> |
---|
34 | #include <iostream> |
---|
35 | #include <sstream> |
---|
36 | #include <string> |
---|
37 | #include "Common/include/MemCheck.h" |
---|
38 | |
---|
39 | namespace morpheo { |
---|
40 | |
---|
41 | typedef enum |
---|
42 | { |
---|
43 | DEBUG_NONE , |
---|
44 | DEBUG_INFO , |
---|
45 | DEBUG_TRACE, |
---|
46 | DEBUG_FUNC , |
---|
47 | DEBUG_ALL |
---|
48 | } debug_verbosity_t; |
---|
49 | |
---|
50 | extern debug_verbosity_t debug; |
---|
51 | extern bool debug_cycle_test; |
---|
52 | extern double debug_cycle_start; |
---|
53 | extern double debug_cycle_stop ; |
---|
54 | extern double debug_idle_cycle; |
---|
55 | extern uint32_t debug_idle_time; |
---|
56 | |
---|
57 | void debug_init (void); |
---|
58 | void debug_init (debug_verbosity_t level, |
---|
59 | double cycle_start, |
---|
60 | double cycle_stop , |
---|
61 | double idle_cycle , |
---|
62 | uint32_t idle_time ); |
---|
63 | |
---|
64 | #ifdef SYSTEMC |
---|
65 | #define debug_test_simulation_time \ |
---|
66 | (not debug_cycle_test or \ |
---|
67 | ( (simulation_cycle() >= debug_cycle_start) and \ |
---|
68 | ((simulation_cycle() <= debug_cycle_stop) or \ |
---|
69 | (debug_cycle_stop == -1)))) |
---|
70 | #else |
---|
71 | #define debug_test_simulation_time true |
---|
72 | #endif |
---|
73 | |
---|
74 | #ifdef DEBUG |
---|
75 | # define log_printf(level, component, func, str... ) \ |
---|
76 | do \ |
---|
77 | { \ |
---|
78 | debug_init(); \ |
---|
79 | \ |
---|
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 | } \ |
---|
94 | \ |
---|
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 | } \ |
---|
117 | } while(0) |
---|
118 | |
---|
119 | # define log_begin(component, func) \ |
---|
120 | do \ |
---|
121 | { \ |
---|
122 | log_printf(FUNC,component,func,_("Begin")); \ |
---|
123 | } while(0) |
---|
124 | |
---|
125 | # define log_end(component, func) \ |
---|
126 | do \ |
---|
127 | { \ |
---|
128 | log_printf(FUNC,component,func,_("End")); \ |
---|
129 | } while(0) |
---|
130 | |
---|
131 | #else |
---|
132 | # define log_printf(level, component, func, str... ) \ |
---|
133 | do \ |
---|
134 | { \ |
---|
135 | } while(0) |
---|
136 | |
---|
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 | |
---|
147 | #endif // DEBUG |
---|
148 | |
---|
149 | # define log_function(component,func,name) \ |
---|
150 | do \ |
---|
151 | { \ |
---|
152 | log_printf(TRACE,component,func,_("[%d] %s.%s"),static_cast<uint32_t>(simulation_cycle()),name,func); \ |
---|
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 | |
---|
165 | #define breakpoint(str...) \ |
---|
166 | do \ |
---|
167 | { \ |
---|
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")); \ |
---|
175 | getchar(); \ |
---|
176 | } while(0) |
---|
177 | |
---|
178 | #ifdef DEBUG_TEST |
---|
179 | #define TEST_PTR(x) \ |
---|
180 | do \ |
---|
181 | { \ |
---|
182 | if (x == NULL) \ |
---|
183 | err(_("File %s, Line %d, this pointeur is null\n"),__FILE__,__LINE__); \ |
---|
184 | } \ |
---|
185 | while (0) |
---|
186 | #else |
---|
187 | #define TEST_PTR(x) \ |
---|
188 | do \ |
---|
189 | { \ |
---|
190 | } \ |
---|
191 | while (0) |
---|
192 | #endif |
---|
193 | |
---|
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 | |
---|
223 | }; // end namespace morpheo |
---|
224 | #endif // !DEBUG_H |
---|