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