1 | #ifndef Morpheo_Debug_h |
---|
2 | #define Morpheo_Debug_h |
---|
3 | |
---|
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 |
---|
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 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 | } \ |
---|
96 | \ |
---|
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 | } \ |
---|
107 | } while(0) |
---|
108 | |
---|
109 | # define log_begin(component, func) \ |
---|
110 | do \ |
---|
111 | { \ |
---|
112 | log_printf(FUNC,component,func,_("Begin")); \ |
---|
113 | } while(0) |
---|
114 | |
---|
115 | # define log_end(component, func) \ |
---|
116 | do \ |
---|
117 | { \ |
---|
118 | log_printf(FUNC,component,func,_("End")); \ |
---|
119 | } while(0) |
---|
120 | |
---|
121 | #else |
---|
122 | # define log_printf(level, component, func, str... ) \ |
---|
123 | do \ |
---|
124 | { \ |
---|
125 | } while(0) |
---|
126 | |
---|
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 | |
---|
137 | #endif // DEBUG |
---|
138 | |
---|
139 | # define log_function(component,func,name) \ |
---|
140 | do \ |
---|
141 | { \ |
---|
142 | log_printf(TRACE,component,func,_("[%d] %s.%s"),static_cast<uint32_t>(simulation_cycle()),name,func); \ |
---|
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 | |
---|
155 | #define breakpoint(str...) \ |
---|
156 | do \ |
---|
157 | { \ |
---|
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")); \ |
---|
165 | getchar(); \ |
---|
166 | } while(0) |
---|
167 | |
---|
168 | #ifdef DEBUG_TEST |
---|
169 | #define TEST_PTR(x) \ |
---|
170 | do \ |
---|
171 | { \ |
---|
172 | if (x == NULL) \ |
---|
173 | err(_("File %s, Line %d, this pointeur is null\n"),__FILE__,__LINE__); \ |
---|
174 | } \ |
---|
175 | while (0) |
---|
176 | #else |
---|
177 | #define TEST_PTR(x) \ |
---|
178 | do \ |
---|
179 | { \ |
---|
180 | } \ |
---|
181 | while (0) |
---|
182 | #endif |
---|
183 | |
---|
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 | |
---|
213 | }; // end namespace morpheo |
---|
214 | #endif // !DEBUG_H |
---|