92 typedef const struct { |
91 typedef const struct { |
93 void *ptr; |
92 void *ptr; |
94 __IEC_types_enum type; |
93 __IEC_types_enum type; |
95 } dbgvardsc_t; |
94 } dbgvardsc_t; |
96 |
95 |
97 static dbgvardsc_t dbgvardsc[] = { |
96 static const dbgvardsc_t dbgvardsc[] = { |
98 %(variable_decl_array)s |
97 %(variable_decl_array)s |
99 }; |
98 }; |
|
99 |
|
100 static const dbgvardsc_index_t retain_list[] = { |
|
101 %(retain_vardsc_index_array)s |
|
102 }; |
|
103 static unsigned int retain_list_collect_cursor = 0; |
|
104 static const unsigned int retain_list_size = sizeof(retain_list)/sizeof(dbgvardsc_index_t); |
100 |
105 |
101 typedef void(*__for_each_variable_do_fp)(dbgvardsc_t*); |
106 typedef void(*__for_each_variable_do_fp)(dbgvardsc_t*); |
102 void __for_each_variable_do(__for_each_variable_do_fp fp) |
107 void __for_each_variable_do(__for_each_variable_do_fp fp) |
103 { |
108 { |
104 unsigned int i; |
109 unsigned int i; |
112 #define __Unpack_desc_type dbgvardsc_t |
117 #define __Unpack_desc_type dbgvardsc_t |
113 |
118 |
114 %(var_access_code)s |
119 %(var_access_code)s |
115 |
120 |
116 void Remind(unsigned int offset, unsigned int count, void * p); |
121 void Remind(unsigned int offset, unsigned int count, void * p); |
117 |
|
118 void RemindIterator(dbgvardsc_t *dsc) |
|
119 { |
|
120 void *value_p = NULL; |
|
121 char flags; |
|
122 size_t size; |
|
123 UnpackVar(dsc, &value_p, &flags, &size); |
|
124 |
|
125 if(flags & __IEC_RETAIN_FLAG){ |
|
126 /* compute next cursor positon*/ |
|
127 unsigned int next_retain_offset = retain_offset + size; |
|
128 /* if buffer not full */ |
|
129 Remind(retain_offset, size, value_p); |
|
130 /* increment cursor according size*/ |
|
131 retain_offset = next_retain_offset; |
|
132 } |
|
133 } |
|
134 |
122 |
135 extern int CheckRetainBuffer(void); |
123 extern int CheckRetainBuffer(void); |
136 extern void InitRetain(void); |
124 extern void InitRetain(void); |
137 |
125 |
138 void __init_debug(void) |
126 void __init_debug(void) |
147 force_buffer_cursor = force_buffer; |
135 force_buffer_cursor = force_buffer; |
148 force_list_addvar_cursor = force_list; |
136 force_list_addvar_cursor = force_list; |
149 force_list_apply_cursor = force_list; |
137 force_list_apply_cursor = force_list; |
150 #endif |
138 #endif |
151 |
139 |
152 retain_offset = 0; |
|
153 InitRetain(); |
140 InitRetain(); |
154 /* Iterate over all variables to fill debug buffer */ |
141 /* Iterate over all variables to fill debug buffer */ |
155 if(CheckRetainBuffer()){ |
142 if(CheckRetainBuffer()){ |
156 __for_each_variable_do(RemindIterator); |
143 static unsigned int retain_offset = 0; |
|
144 retain_list_collect_cursor = 0; |
|
145 |
|
146 /* iterate over retain list */ |
|
147 while(retain_list_collect_cursor < retain_list_size){ |
|
148 void *value_p = NULL; |
|
149 size_t size; |
|
150 char* next_cursor; |
|
151 |
|
152 dbgvardsc_t *dsc = &dbgvardsc[ |
|
153 retain_list[retain_list_collect_cursor]]; |
|
154 |
|
155 UnpackVar(dsc, &value_p, NULL, &size); |
|
156 |
|
157 printf("Reminding %%d %%ld \n", retain_list_collect_cursor, size); |
|
158 |
|
159 /* if buffer not full */ |
|
160 Remind(retain_offset, size, value_p); |
|
161 /* increment cursor according size*/ |
|
162 retain_offset += size; |
|
163 |
|
164 retain_list_collect_cursor++; |
|
165 } |
157 }else{ |
166 }else{ |
158 char mstr[] = "RETAIN memory invalid - defaults used"; |
167 char mstr[] = "RETAIN memory invalid - defaults used"; |
159 LogMessage(LOG_WARNING, mstr, sizeof(mstr)); |
168 LogMessage(LOG_WARNING, mstr, sizeof(mstr)); |
160 } |
169 } |
161 retain_offset = 0; |
|
162 } |
170 } |
163 |
171 |
164 extern void InitiateDebugTransfer(void); |
172 extern void InitiateDebugTransfer(void); |
165 extern void CleanupRetain(void); |
173 extern void CleanupRetain(void); |
166 |
174 |
178 |
186 |
179 void __retrieve_debug(void) |
187 void __retrieve_debug(void) |
180 { |
188 { |
181 } |
189 } |
182 |
190 |
183 |
|
184 void Retain(unsigned int offset, unsigned int count, void * p); |
191 void Retain(unsigned int offset, unsigned int count, void * p); |
185 |
|
186 static inline void BufferIterator(dbgvardsc_t *dsc, int do_debug) |
|
187 { |
|
188 void *value_p = NULL; |
|
189 char flags; |
|
190 size_t size; |
|
191 |
|
192 UnpackVar(dsc, &value_p, &flags, &size); |
|
193 |
|
194 if(flags & __IEC_RETAIN_FLAG){ |
|
195 |
|
196 /* compute next cursor positon*/ |
|
197 unsigned int next_retain_offset = retain_offset + size; |
|
198 /* if buffer not full */ |
|
199 Retain(retain_offset, size, value_p); |
|
200 /* increment cursor according size*/ |
|
201 retain_offset = next_retain_offset; |
|
202 } |
|
203 } |
|
204 |
|
205 void RetainIterator(dbgvardsc_t *dsc){ |
|
206 BufferIterator(dsc, 0); |
|
207 } |
|
208 |
|
209 |
|
210 unsigned int retain_size = 0; |
|
211 |
|
212 /* GetRetainSizeIterator */ |
|
213 void GetRetainSizeIterator(dbgvardsc_t *dsc) |
|
214 { |
|
215 char flags; |
|
216 size_t size; |
|
217 UnpackVar(dsc, NULL, &flags, &size); |
|
218 |
|
219 if(flags & __IEC_RETAIN_FLAG){ |
|
220 /* Calc retain buffer size */ |
|
221 retain_size += size; |
|
222 } |
|
223 } |
|
224 |
192 |
225 /* Return size of all retain variables */ |
193 /* Return size of all retain variables */ |
226 unsigned int GetRetainSize(void) |
194 unsigned int GetRetainSize(void) |
227 { |
195 { |
228 __for_each_variable_do(GetRetainSizeIterator); |
196 unsigned int retain_size = 0; |
|
197 retain_list_collect_cursor = 0; |
|
198 |
|
199 /* iterate over retain list */ |
|
200 while(retain_list_collect_cursor < retain_list_size){ |
|
201 void *value_p = NULL; |
|
202 size_t size; |
|
203 char* next_cursor; |
|
204 |
|
205 dbgvardsc_t *dsc = &dbgvardsc[ |
|
206 retain_list[retain_list_collect_cursor]]; |
|
207 |
|
208 UnpackVar(dsc, &value_p, NULL, &size); |
|
209 |
|
210 retain_size += size; |
|
211 retain_list_collect_cursor++; |
|
212 } |
|
213 |
|
214 printf("Retain size %%d \n", retain_size); |
|
215 |
229 return retain_size; |
216 return retain_size; |
230 } |
217 } |
231 |
218 |
232 |
219 |
233 extern void PLC_GetTime(IEC_TIME*); |
220 extern void PLC_GetTime(IEC_TIME*); |
256 } \ |
243 } \ |
257 } \ |
244 } \ |
258 break; |
245 break; |
259 void __publish_debug(void) |
246 void __publish_debug(void) |
260 { |
247 { |
261 retain_offset = 0; |
|
262 InValidateRetainBuffer(); |
248 InValidateRetainBuffer(); |
263 |
249 |
264 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
250 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
265 /* Check there is no running debugger re-configuration */ |
251 /* Check there is no running debugger re-configuration */ |
266 if(TryEnterDebugSection()){ |
252 if(TryEnterDebugSection()){ |
334 InitiateDebugTransfer(); /* size */ |
320 InitiateDebugTransfer(); /* size */ |
335 } |
321 } |
336 LeaveDebugSection(); |
322 LeaveDebugSection(); |
337 } |
323 } |
338 #endif |
324 #endif |
|
325 static unsigned int retain_offset = 0; |
339 /* when not debugging, do only retain */ |
326 /* when not debugging, do only retain */ |
340 __for_each_variable_do(RetainIterator); |
327 retain_list_collect_cursor = 0; |
|
328 |
|
329 /* iterate over retain list */ |
|
330 while(retain_list_collect_cursor < retain_list_size){ |
|
331 void *value_p = NULL; |
|
332 size_t size; |
|
333 char* next_cursor; |
|
334 |
|
335 dbgvardsc_t *dsc = &dbgvardsc[ |
|
336 retain_list[retain_list_collect_cursor]]; |
|
337 |
|
338 UnpackVar(dsc, &value_p, NULL, &size); |
|
339 |
|
340 printf("Retaining %%d %%ld \n", retain_list_collect_cursor, size); |
|
341 |
|
342 /* if buffer not full */ |
|
343 Retain(retain_offset, size, value_p); |
|
344 /* increment cursor according size*/ |
|
345 retain_offset += size; |
|
346 |
|
347 retain_list_collect_cursor++; |
|
348 } |
341 ValidateRetainBuffer(); |
349 ValidateRetainBuffer(); |
342 } |
350 } |
343 |
351 |
344 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
352 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
345 |
353 |