1 | #ifndef Morpheo_Debug_h |
---|
2 | #define Morpheo_Debug_h |
---|
3 | |
---|
4 | /* |
---|
5 | * $Id: Debug.h 142 2010-08-04 20:09:03Z 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/ChangeCase.h" |
---|
30 | #include "Behavioural/include/Debug_component.h" |
---|
31 | #include "Behavioural/include/Model.h" |
---|
32 | #include "Behavioural/include/Simulation.h" |
---|
33 | #include <systemc.h> |
---|
34 | #include <stdio.h> |
---|
35 | #include <string.h> |
---|
36 | #include <iostream> |
---|
37 | #include <sstream> |
---|
38 | #include <string> |
---|
39 | #include "Common/include/MemCheck.h" |
---|
40 | |
---|
41 | namespace morpheo { |
---|
42 | |
---|
43 | // typedef enum |
---|
44 | // { |
---|
45 | // DEBUG_NONE , |
---|
46 | // DEBUG_INFO , |
---|
47 | // DEBUG_TRACE, |
---|
48 | // DEBUG_FUNC , |
---|
49 | // DEBUG_ALL |
---|
50 | // } debug_verbosity_t; |
---|
51 | |
---|
52 | extern debug_verbosity_t debug; |
---|
53 | extern bool debug_cycle_test; |
---|
54 | extern double debug_cycle_start; |
---|
55 | extern double debug_cycle_stop ; |
---|
56 | extern double debug_idle_cycle; |
---|
57 | extern uint32_t debug_idle_time; |
---|
58 | |
---|
59 | void debug_init (void); |
---|
60 | void debug_init (debug_verbosity_t level, |
---|
61 | double cycle_start, |
---|
62 | double cycle_stop , |
---|
63 | double idle_cycle , |
---|
64 | uint32_t idle_time ); |
---|
65 | |
---|
66 | #ifdef SYSTEMC |
---|
67 | #define debug_test_simulation_time \ |
---|
68 | (not debug_cycle_test or \ |
---|
69 | ((simulation_cycle() >= debug_cycle_start) and \ |
---|
70 | ((simulation_cycle() <= debug_cycle_stop) or \ |
---|
71 | (debug_cycle_stop == -1)))) |
---|
72 | #else |
---|
73 | #define debug_test_simulation_time true |
---|
74 | #endif |
---|
75 | |
---|
76 | /* |
---|
77 | # define log_test(level, component) \ |
---|
78 | do \ |
---|
79 | { \ |
---|
80 | debug_init(); \ |
---|
81 | \ |
---|
82 | msgInformation("debug_test_simuation_time : %d",debug_test_simulation_time); \ |
---|
83 | msgInformation("level : %d",( DEBUG_ ## level <= debug)); \ |
---|
84 | msgInformation("component : %d", morpheo::behavioural::_model.get_debug(NAME_ ## component)); \ |
---|
85 | } while(0) |
---|
86 | */ |
---|
87 | |
---|
88 | #ifdef DEBUG |
---|
89 | # define log_printf(level, component, func, str... ) \ |
---|
90 | do \ |
---|
91 | { \ |
---|
92 | debug_init(); \ |
---|
93 | \ |
---|
94 | if (debug_test_simulation_time and \ |
---|
95 | (( DEBUG_ ## level <= debug) and \ |
---|
96 | ( morpheo::behavioural::_model.get_debug(NAME_ ## component)))) \ |
---|
97 | { \ |
---|
98 | if (DEBUG_ ## level <= DEBUG_INFO) \ |
---|
99 | { \ |
---|
100 | msg("%s ",MSG_INFORMATION); \ |
---|
101 | } \ |
---|
102 | else \ |
---|
103 | { \ |
---|
104 | msg("%s ",MSG_DEBUG); \ |
---|
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 | fmsg(_("%s "),MSG_BREAKPOINT); \ |
---|
169 | fmsg(_("Breakpoint in file %s, line %d.\n"),__FILE__,__LINE__); \ |
---|
170 | fmsg(_("%s "),MSG_NONE); \ |
---|
171 | fmsg(str); \ |
---|
172 | fmsg(_("\n")); \ |
---|
173 | fmsg(_("%s "),MSG_NONE); \ |
---|
174 | fmsg(_("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 | }; // end namespace morpheo |
---|
195 | #endif // !DEBUG_H |
---|