|
0
|
1 //========================================================================== |
|
|
2 // |
|
2
|
3 // buffer.cxx |
|
0
|
4 // |
|
|
5 // Memory buffered trace and assert functions |
|
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
2
|
32 // Author(s): nickg |
|
|
33 // Contributors: nickg |
|
|
34 // Date: 1998-10-16 |
|
|
35 // Purpose: Buffered Trace and assert functions |
|
|
36 // Description: The functions in this file are a buffered implementation |
|
0
|
37 // of the standard trace and assert functions. These store |
|
|
38 // trace messages in a memory buffer and emit them when an |
|
|
39 // assert is hit, or when requested to. |
|
|
40 // |
|
|
41 //####DESCRIPTIONEND#### |
|
|
42 // |
|
|
43 //========================================================================== |
|
|
44 |
|
|
45 #include <pkgconf/system.h> |
|
|
46 #include <pkgconf/infra.h> |
|
|
47 |
|
|
48 #ifdef CYGDBG_INFRA_DEBUG_TRACE_ASSERT_BUFFER |
|
|
49 |
|
|
50 #include <cyg/infra/cyg_type.h> // base types |
|
|
51 #include <cyg/infra/cyg_trac.h> // tracing macros |
|
|
52 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
53 |
|
|
54 #include <pkgconf/hal.h> // HAL configury |
|
|
55 #include <cyg/infra/diag.h> // HAL polled output |
|
|
56 #include <cyg/hal/hal_arch.h> // architectural stuff for... |
|
|
57 #include <cyg/hal/hal_intr.h> // interrupt control |
|
|
58 |
|
|
59 #ifdef CYGPKG_KERNEL |
|
|
60 #include <pkgconf/kernel.h> // kernel configury |
|
|
61 #include <cyg/kernel/thread.hxx> // thread id to print |
|
|
62 #include <cyg/kernel/sched.hxx> // ancillaries for above |
|
|
63 #include <cyg/kernel/thread.inl> // ancillaries for above |
|
|
64 #endif |
|
|
65 |
|
|
66 // ------------------------------------------------------------------------- |
|
|
67 // Local Configuration: hack me! |
|
|
68 |
|
|
69 // these are generally: |
|
2
|
70 // if 0, feature is disabled |
|
|
71 // if 1, feature is enabled, printing is default width |
|
|
72 // if >1, field is padded up to that width if necessary |
|
|
73 // (not truncated ever) |
|
0
|
74 |
|
2
|
75 #define CYG_FILENAME 20 |
|
|
76 #define CYG_THREADID 1 |
|
|
77 #define CYG_LINENUM 4 |
|
|
78 #define CYG_FUNCNAME 100 |
|
0
|
79 #define CYG_DIAG_PRINTF 1 |
|
|
80 #define CYG_FUNC_INDENT 2 |
|
|
81 |
|
|
82 #ifndef CYGPKG_KERNEL |
|
|
83 # undef CYG_THREADID |
|
|
84 # define CYG_THREADID 0 |
|
|
85 #endif |
|
|
86 |
|
|
87 #if CYG_FUNCNAME == 1 |
|
|
88 #define CYG_FBUF_SIZE 100 |
|
|
89 #else |
|
|
90 #define CYG_FBUF_SIZE (CYG_FUNCNAME+20) |
|
|
91 #endif |
|
|
92 |
|
|
93 // ------------------------------------------------------------------------- |
|
|
94 // Trace buffer |
|
|
95 |
|
|
96 #ifdef CYGDBG_USE_TRACING |
|
|
97 |
|
|
98 struct Cyg_TraceRecord |
|
|
99 { |
|
|
100 cyg_uint32 what; |
|
|
101 cyg_uint32 tid; |
|
|
102 char *function; |
|
|
103 char *file; |
|
|
104 char *message; |
|
|
105 cyg_uint32 line; |
|
|
106 cyg_uint32 narg; |
|
|
107 CYG_ADDRWORD arg[8]; |
|
|
108 }; |
|
|
109 |
|
|
110 Cyg_TraceRecord cyg_infra_trace_buffer[CYGDBG_INFRA_DEBUG_TRACE_BUFFER_SIZE]; |
|
|
111 |
|
|
112 static cyg_uint32 cyg_infra_trace_buffer_pos = 0; |
|
|
113 |
|
|
114 static cyg_bool cyg_infra_trace_buffer_enable = true; |
|
|
115 |
|
|
116 static cyg_bool cyg_infra_trace_buffer_wrap = false; |
|
|
117 |
|
|
118 // ------------------------------------------------------------------------- |
|
|
119 // Functions to trim file names and function names down to printable lengths |
|
|
120 // (these are shared between trace and assert functions) |
|
|
121 |
|
|
122 #if 0 |
|
|
123 static char * tracepremsgs[] = { |
|
|
124 " INFO:", |
|
|
125 "ENTER :", |
|
|
126 "ARGS :", |
|
|
127 "RETURN:", |
|
|
128 "bad code" |
|
|
129 }; |
|
|
130 #endif |
|
|
131 |
|
|
132 static char * tracepremsgs[] = { |
|
|
133 "'", |
|
|
134 "{{", |
|
|
135 "((", |
|
|
136 "}}", |
|
|
137 "bad code" |
|
|
138 }; |
|
|
139 |
|
|
140 static char * tracepostmsgs[] = { |
|
|
141 "'", |
|
|
142 "", |
|
|
143 "))", |
|
|
144 "", |
|
|
145 "bad code" |
|
|
146 }; |
|
|
147 |
|
|
148 static void |
|
|
149 write_whattrace( cyg_uint32 what ) |
|
|
150 { |
|
|
151 #if CYG_FUNC_INDENT |
|
|
152 static cyg_int32 cyg_indent = 0; |
|
|
153 if ( 3 == what ) |
|
|
154 cyg_indent -= CYG_FUNC_INDENT; |
|
|
155 cyg_int32 i = cyg_indent; |
|
|
156 for ( ; i > 0; i-- ) |
|
|
157 diag_write_string( " " ); |
|
|
158 #endif // CYG_FUNC_INDENT |
|
|
159 diag_write_string( tracepremsgs[ what > 4 ? 4 : what ] ); |
|
|
160 #if CYG_FUNC_INDENT |
|
|
161 if ( 1 == what ) |
|
|
162 cyg_indent += CYG_FUNC_INDENT; |
|
|
163 #endif // CYG_FUNC_INDENT |
|
|
164 } |
|
|
165 |
|
|
166 static void |
|
|
167 write_whattracepost( cyg_uint32 what ) |
|
|
168 { |
|
|
169 diag_write_string( tracepostmsgs[ what > 4 ? 4 : what ] ); |
|
|
170 } |
|
|
171 |
|
|
172 |
|
|
173 #endif // CYGDBG_USE_TRACING |
|
|
174 |
|
|
175 // ------------------------------------------------------------------------- |
|
|
176 |
|
2
|
177 static const char *trim_file(const char *file) |
|
0
|
178 { |
|
|
179 #if CYG_FILENAME |
|
|
180 if ( NULL == file ) |
|
|
181 file = "<nofile>"; |
|
|
182 |
|
|
183 #if 1 == CYG_FILENAME |
|
2
|
184 const char *f = file; |
|
0
|
185 while( *f ) f++; |
|
|
186 while( *f != '/' && f != file ) f--; |
|
|
187 return f==file?f:(f+1); |
|
|
188 #else |
|
|
189 static char fbuf2[100]; |
|
2
|
190 const char *f = file; |
|
|
191 char *g = fbuf2; |
|
0
|
192 while( *f ) f++; |
|
|
193 while( *f != '/' && f != file ) f--; |
|
|
194 if ( f > file ) f++; |
|
|
195 while( *f ) *g++ = *f++; |
|
|
196 while( CYG_FILENAME > (g - fbuf2) ) *g++ = ' '; |
|
|
197 *g = 0; |
|
|
198 return fbuf2; |
|
|
199 #endif |
|
|
200 #else |
|
|
201 return ""; |
|
|
202 #endif |
|
|
203 } |
|
|
204 |
|
2
|
205 static const char *trim_func(const char *func) |
|
0
|
206 { |
|
|
207 #if CYG_FUNCNAME |
|
|
208 static char fbuf[CYG_FBUF_SIZE]; |
|
|
209 cyg_count32 i; |
|
|
210 |
|
|
211 if ( NULL == func ) |
|
|
212 func = "<nofunc>"; |
|
|
213 |
|
|
214 for( i = 0; func[i] && func[i] != '(' && i < CYG_FBUF_SIZE-4 ; i++ ) |
|
|
215 fbuf[i] = func[i]; |
|
|
216 |
|
|
217 fbuf[i++] = '('; |
|
|
218 fbuf[i++] = ')'; |
|
|
219 fbuf[i ] = 0; |
|
2
|
220 i=0; |
|
0
|
221 #if 1 == CYG_FUNCNAME |
|
|
222 return &fbuf[i]; |
|
|
223 #else |
|
|
224 char *p = &fbuf[i]; |
|
|
225 while ( *p ) p++; |
|
|
226 while ( CYG_FUNCNAME > (p - (&fbuf[i])) ) *p++ = ' '; |
|
|
227 *p = 0; |
|
|
228 return &fbuf[i]; |
|
|
229 #endif |
|
|
230 #else |
|
|
231 return ""; |
|
|
232 #endif |
|
|
233 } |
|
|
234 |
|
|
235 static void write_lnum( cyg_uint32 lnum) |
|
|
236 { |
|
|
237 #if CYG_LINENUM |
|
|
238 diag_write_char('['); |
|
|
239 #if 1 < CYG_LINENUM |
|
|
240 cyg_uint32 i, j; |
|
|
241 for ( i = 2, j = 100; i < CYG_LINENUM ; i++, j *= 10 ) |
|
|
242 if ( lnum < j ) |
|
|
243 diag_write_char(' '); |
|
|
244 #endif |
|
|
245 diag_write_dec(lnum); |
|
|
246 diag_write_char(']'); |
|
|
247 diag_write_char(' '); |
|
|
248 #endif |
|
|
249 } |
|
|
250 |
|
|
251 // ------------------------------------------------------------------------- |
|
|
252 |
|
|
253 #if CYG_THREADID |
|
|
254 static cyg_uint32 get_tid(void) |
|
|
255 { |
|
|
256 |
|
|
257 Cyg_Thread *t = Cyg_Thread::self(); |
|
|
258 cyg_uint16 tid = 0xFFFF; |
|
|
259 |
|
|
260 if( t != NULL ) tid = t->get_unique_id(); |
|
|
261 |
|
|
262 return tid; |
|
|
263 } |
|
|
264 #else |
|
|
265 # define get_tid() (0xFFFF) |
|
|
266 #endif |
|
|
267 |
|
2
|
268 #ifdef CYGDBG_USE_ASSERTS |
|
0
|
269 static void write_thread_id() |
|
|
270 { |
|
|
271 #if CYG_THREADID |
|
|
272 cyg_uint16 tid = get_tid(); |
|
|
273 |
|
|
274 diag_write_char('<'); |
|
|
275 diag_write_hex(tid); |
|
|
276 diag_write_char('>'); |
|
|
277 #endif |
|
|
278 } |
|
2
|
279 #endif |
|
0
|
280 |
|
|
281 // ------------------------------------------------------------------------- |
|
|
282 // Trace functions: |
|
|
283 |
|
|
284 #ifdef CYGDBG_USE_TRACING |
|
|
285 |
|
|
286 static void print_trace_buffer(void) |
|
|
287 { |
|
|
288 cyg_count32 start = cyg_infra_trace_buffer_pos; |
|
|
289 cyg_count32 end = start; |
|
|
290 cyg_count32 i; |
|
|
291 |
|
|
292 // If the buffer has wrapped we want to display the records from |
|
|
293 // the current pos and around back to the same place. If the buffer |
|
|
294 // has not wrapped, we want to display from the start to pos. |
|
|
295 |
|
|
296 if( !cyg_infra_trace_buffer_wrap ) |
|
|
297 start = 0; |
|
|
298 |
|
|
299 i = start; |
|
|
300 do |
|
|
301 { |
|
|
302 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[i]; |
|
|
303 cyg_uint32 old_ints; |
|
|
304 |
|
|
305 char *psz_msg = rec->message; |
|
|
306 |
|
|
307 |
|
|
308 HAL_DISABLE_INTERRUPTS(old_ints); |
|
|
309 DIAG_DEVICE_START_SYNC(); |
|
|
310 |
|
|
311 if ( NULL == psz_msg ) |
|
|
312 psz_msg = "<nomsg>"; |
|
|
313 |
|
|
314 diag_write_string( "TRACE: " ); |
|
|
315 #if CYG_THREADID |
|
|
316 diag_write_char('<'); |
|
|
317 diag_write_hex(rec->tid); |
|
|
318 diag_write_char('>'); |
|
|
319 #endif |
|
|
320 diag_write_string(trim_file(rec->file)); |
|
|
321 write_lnum(rec->line); |
|
|
322 diag_write_string(trim_func(rec->function)); |
|
|
323 diag_write_char(' '); |
|
|
324 write_whattrace( rec->what ); |
|
|
325 #if CYG_DIAG_PRINTF |
|
|
326 diag_printf( psz_msg, |
|
|
327 rec->arg[0], rec->arg[1], |
|
|
328 rec->arg[2], rec->arg[3], |
|
|
329 rec->arg[4], rec->arg[5], |
|
|
330 rec->arg[6], rec->arg[7] ); |
|
|
331 #else |
|
|
332 diag_write_string(psz_msg); |
|
|
333 diag_write_char(' '); |
|
|
334 |
|
|
335 for( cyg_count8 j = 0; j < rec->narg ; j++ ) |
|
|
336 { |
|
|
337 diag_write_hex(rec->arg[j]); |
|
|
338 diag_write_char(' '); |
|
|
339 } |
|
|
340 #endif |
|
|
341 write_whattracepost( rec->what ); |
|
|
342 diag_write_char('\n'); |
|
|
343 |
|
|
344 DIAG_DEVICE_END_SYNC(); |
|
|
345 HAL_RESTORE_INTERRUPTS(old_ints); |
|
|
346 |
|
|
347 i++; |
|
|
348 if( i == CYGDBG_INFRA_DEBUG_TRACE_BUFFER_SIZE ) |
|
|
349 i = 0; |
|
|
350 |
|
|
351 } while( i != end ); |
|
|
352 |
|
|
353 } |
|
|
354 |
|
|
355 static void increment_buffer_pos() |
|
|
356 { |
|
|
357 cyg_infra_trace_buffer_pos++; |
|
|
358 |
|
|
359 if( cyg_infra_trace_buffer_pos == CYGDBG_INFRA_DEBUG_TRACE_BUFFER_SIZE ) |
|
|
360 { |
|
|
361 #if defined(CYGDBG_INFRA_DEBUG_TRACE_BUFFER_WRAP) |
|
|
362 cyg_infra_trace_buffer_pos = 0; |
|
|
363 cyg_infra_trace_buffer_wrap = true; |
|
|
364 #elif defined(CYGDBG_INFRA_DEBUG_TRACE_BUFFER_HALT) |
|
|
365 cyg_infra_trace_buffer_enable = false; |
|
|
366 #elif defined(CYGDBG_INFRA_DEBUG_TRACE_BUFFER_PRINT) |
|
|
367 print_trace_buffer(); |
|
|
368 cyg_infra_trace_buffer_pos = 0; |
|
|
369 cyg_infra_trace_buffer_wrap = false; |
|
|
370 #else |
|
|
371 #error No trace buffer full mode set |
|
|
372 #endif |
|
|
373 } |
|
|
374 |
|
|
375 } |
|
|
376 |
|
|
377 // ------------------------------------------------------------------------- |
|
|
378 |
|
|
379 externC void |
|
|
380 cyg_tracenomsg( char *psz_func, char *psz_file, cyg_uint32 linenum ) |
|
|
381 { |
|
|
382 cyg_uint32 old_ints; |
|
|
383 |
|
|
384 if( !cyg_infra_trace_buffer_enable ) return; |
|
|
385 |
|
|
386 HAL_DISABLE_INTERRUPTS(old_ints); |
|
|
387 |
|
|
388 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; |
|
|
389 |
|
|
390 rec->what = 0; |
|
|
391 rec->tid = get_tid(); |
|
|
392 rec->function = psz_func; |
|
|
393 rec->file = psz_file; |
|
|
394 rec->line = linenum; |
|
|
395 rec->message = 0; |
|
|
396 rec->narg = 0; |
|
|
397 |
|
|
398 increment_buffer_pos(); |
|
|
399 |
|
|
400 HAL_RESTORE_INTERRUPTS(old_ints); |
|
|
401 |
|
|
402 }; |
|
|
403 |
|
|
404 // provide every other one of these as a space/caller bloat compromise. |
|
|
405 |
|
|
406 externC void |
|
|
407 cyg_tracemsg( cyg_uint32 what, |
|
|
408 char *psz_func, char *psz_file, cyg_uint32 linenum, |
|
|
409 char *psz_msg ) |
|
|
410 { |
|
|
411 cyg_uint32 old_ints; |
|
|
412 |
|
|
413 if( !cyg_infra_trace_buffer_enable ) return; |
|
|
414 |
|
|
415 HAL_DISABLE_INTERRUPTS(old_ints); |
|
|
416 |
|
|
417 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; |
|
|
418 |
|
|
419 rec->what = what; |
|
|
420 rec->tid = get_tid(); |
|
|
421 rec->function = psz_func; |
|
|
422 rec->file = psz_file; |
|
|
423 rec->line = linenum; |
|
|
424 rec->message = psz_msg; |
|
|
425 rec->narg = 0; |
|
|
426 |
|
|
427 increment_buffer_pos(); |
|
|
428 |
|
|
429 HAL_RESTORE_INTERRUPTS(old_ints); |
|
|
430 |
|
|
431 }; |
|
|
432 |
|
|
433 externC void |
|
|
434 cyg_tracemsg2( cyg_uint32 what, |
|
|
435 char *psz_func, char *psz_file, cyg_uint32 linenum, |
|
|
436 char *psz_msg, |
|
|
437 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1 ) |
|
|
438 { |
|
|
439 cyg_uint32 old_ints; |
|
|
440 |
|
|
441 if( !cyg_infra_trace_buffer_enable ) return; |
|
|
442 |
|
|
443 HAL_DISABLE_INTERRUPTS(old_ints); |
|
|
444 |
|
|
445 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; |
|
|
446 |
|
|
447 rec->what = what; |
|
|
448 rec->tid = get_tid(); |
|
|
449 rec->function = psz_func; |
|
|
450 rec->file = psz_file; |
|
|
451 rec->line = linenum; |
|
|
452 rec->message = psz_msg; |
|
|
453 rec->narg = 2; |
|
|
454 |
|
|
455 rec->arg[0] = arg0; |
|
|
456 rec->arg[1] = arg1; |
|
|
457 |
|
|
458 increment_buffer_pos(); |
|
|
459 |
|
|
460 HAL_RESTORE_INTERRUPTS(old_ints); |
|
|
461 }; |
|
|
462 |
|
|
463 externC void |
|
|
464 cyg_tracemsg4( cyg_uint32 what, |
|
|
465 char *psz_func, char *psz_file, cyg_uint32 linenum, |
|
|
466 char *psz_msg, |
|
|
467 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, |
|
|
468 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3 ) |
|
|
469 { |
|
|
470 cyg_uint32 old_ints; |
|
|
471 |
|
|
472 if( !cyg_infra_trace_buffer_enable ) return; |
|
|
473 |
|
|
474 HAL_DISABLE_INTERRUPTS(old_ints); |
|
|
475 |
|
|
476 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; |
|
|
477 |
|
|
478 rec->what = what; |
|
|
479 rec->tid = get_tid(); |
|
|
480 rec->function = psz_func; |
|
|
481 rec->file = psz_file; |
|
|
482 rec->line = linenum; |
|
|
483 rec->message = psz_msg; |
|
|
484 rec->narg = 4; |
|
|
485 |
|
|
486 rec->arg[0] = arg0; |
|
|
487 rec->arg[1] = arg1; |
|
|
488 rec->arg[2] = arg2; |
|
|
489 rec->arg[3] = arg3; |
|
|
490 |
|
|
491 increment_buffer_pos(); |
|
|
492 |
|
|
493 HAL_RESTORE_INTERRUPTS(old_ints); |
|
|
494 }; |
|
|
495 |
|
|
496 externC void |
|
|
497 cyg_tracemsg6( cyg_uint32 what, |
|
|
498 char *psz_func, char *psz_file, cyg_uint32 linenum, |
|
|
499 char *psz_msg, |
|
|
500 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, |
|
|
501 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3, |
|
|
502 CYG_ADDRWORD arg4, CYG_ADDRWORD arg5 ) |
|
|
503 { |
|
|
504 cyg_uint32 old_ints; |
|
|
505 |
|
|
506 if( !cyg_infra_trace_buffer_enable ) return; |
|
|
507 |
|
|
508 HAL_DISABLE_INTERRUPTS(old_ints); |
|
|
509 |
|
|
510 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; |
|
|
511 |
|
|
512 rec->what = what; |
|
|
513 rec->tid = get_tid(); |
|
|
514 rec->function = psz_func; |
|
|
515 rec->file = psz_file; |
|
|
516 rec->line = linenum; |
|
|
517 rec->message = psz_msg; |
|
|
518 rec->narg = 6; |
|
|
519 |
|
|
520 rec->arg[0] = arg0; |
|
|
521 rec->arg[1] = arg1; |
|
|
522 rec->arg[2] = arg2; |
|
|
523 rec->arg[3] = arg3; |
|
|
524 rec->arg[4] = arg4; |
|
|
525 rec->arg[5] = arg5; |
|
|
526 |
|
|
527 increment_buffer_pos(); |
|
|
528 |
|
|
529 HAL_RESTORE_INTERRUPTS(old_ints); |
|
|
530 }; |
|
|
531 |
|
|
532 externC void |
|
|
533 cyg_tracemsg8( cyg_uint32 what, |
|
|
534 char *psz_func, char *psz_file, cyg_uint32 linenum, |
|
|
535 char *psz_msg, |
|
|
536 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, |
|
|
537 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3, |
|
|
538 CYG_ADDRWORD arg4, CYG_ADDRWORD arg5, |
|
|
539 CYG_ADDRWORD arg6, CYG_ADDRWORD arg7 ) |
|
|
540 { |
|
|
541 cyg_uint32 old_ints; |
|
|
542 |
|
|
543 if( !cyg_infra_trace_buffer_enable ) return; |
|
|
544 |
|
|
545 HAL_DISABLE_INTERRUPTS(old_ints); |
|
|
546 |
|
|
547 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; |
|
|
548 |
|
|
549 rec->what = what; |
|
|
550 rec->tid = get_tid(); |
|
|
551 rec->function = psz_func; |
|
|
552 rec->file = psz_file; |
|
|
553 rec->line = linenum; |
|
|
554 rec->message = psz_msg; |
|
|
555 rec->narg = 6; |
|
|
556 |
|
|
557 rec->arg[0] = arg0; |
|
|
558 rec->arg[1] = arg1; |
|
|
559 rec->arg[2] = arg2; |
|
|
560 rec->arg[3] = arg3; |
|
|
561 rec->arg[4] = arg4; |
|
|
562 rec->arg[5] = arg5; |
|
|
563 rec->arg[6] = arg6; |
|
|
564 rec->arg[7] = arg7; |
|
|
565 |
|
|
566 increment_buffer_pos(); |
|
|
567 |
|
|
568 HAL_RESTORE_INTERRUPTS(old_ints); |
|
|
569 }; |
|
|
570 |
|
|
571 // ------------------------------------------------------------------------- |
|
|
572 |
|
|
573 externC void |
|
|
574 cyg_trace_print(void) |
|
|
575 { |
|
|
576 cyg_bool old_enable = cyg_infra_trace_buffer_enable; |
|
|
577 cyg_infra_trace_buffer_enable = false; |
|
|
578 print_trace_buffer(); |
|
|
579 cyg_infra_trace_buffer_pos = 0; |
|
|
580 cyg_infra_trace_buffer_wrap = false; |
|
|
581 cyg_infra_trace_buffer_enable = old_enable; |
|
|
582 } |
|
|
583 |
|
|
584 |
|
|
585 // ------------------------------------------------------------------------- |
|
|
586 |
|
|
587 externC void |
|
|
588 cyg_trace_dump(void) |
|
|
589 { |
|
|
590 #if defined(CYGPKG_KERNEL) && defined(CYG_DIAG_PRINTF) |
|
|
591 |
|
|
592 { |
|
|
593 diag_printf("\nScheduler:\n\n"); |
|
|
594 |
|
|
595 Cyg_Scheduler *sched = &Cyg_Scheduler::scheduler; |
|
|
596 |
|
|
597 diag_printf("Lock: %d\n",sched->get_sched_lock() ); |
|
|
598 |
|
|
599 # ifdef CYGVAR_KERNEL_THREADS_NAME |
|
|
600 |
|
|
601 diag_printf("Current Thread: %s\n",sched->get_current_thread()->get_name()); |
|
|
602 |
|
|
603 # else |
|
|
604 |
|
|
605 diag_printf("Current Thread: %d\n",sched->get_current_thread()->get_unique_id()); |
|
|
606 |
|
|
607 # endif |
|
|
608 |
|
|
609 } |
|
|
610 |
|
|
611 # ifdef CYGVAR_KERNEL_THREADS_LIST |
|
|
612 |
|
|
613 { |
|
|
614 Cyg_Thread *t = Cyg_Thread::get_list_head(); |
|
|
615 |
|
|
616 diag_printf("\nThreads:\n\n"); |
|
|
617 |
|
|
618 while( NULL != t ) |
|
|
619 { |
|
|
620 cyg_uint32 state = t->get_state(); |
|
|
621 char tstate[7]; |
|
|
622 char *tstate1 = "SCUKX"; |
|
|
623 static char *(reasons[8]) = |
|
|
624 { |
|
|
625 "NONE", // No recorded reason |
|
|
626 "WAIT", // Wait with no timeout |
|
|
627 "DELAY", // Simple time delay |
|
|
628 "TIMEOUT", // Wait with timeout/timeout expired |
|
|
629 "BREAK", // forced break out of sleep |
|
|
630 "DESTRUCT", // wait object destroyed[note] |
|
|
631 "EXIT", // forced termination |
|
|
632 "DONE" // Wait/delay complete |
|
|
633 }; |
|
|
634 |
|
|
635 if( 0 != state ) |
|
|
636 { |
|
|
637 // Knock out chars that do not correspond to set bits. |
|
|
638 for( int i = 0; i < 6 ; i++ ) |
|
|
639 if( 0 == (state & (1<<i)) ) |
|
|
640 tstate[i] = ' '; |
|
|
641 else tstate[i] = tstate1[i]; |
|
|
642 tstate[6] = 0; |
|
|
643 } |
|
|
644 else tstate[0] = 'R', tstate[1] = 0; |
|
|
645 |
|
|
646 # ifdef CYGVAR_KERNEL_THREADS_NAME |
|
|
647 |
|
|
648 diag_printf( "%20s pri = %3d state = %6s id = %3d\n", |
|
|
649 t->get_name(), |
|
|
650 t->get_priority(), |
|
|
651 tstate, |
|
|
652 t->get_unique_id() |
|
|
653 ); |
|
|
654 # else |
|
|
655 |
|
|
656 diag_printf( "Thread %3d pri = %3d state = %6s\n", |
|
|
657 t->get_unique_id(), |
|
|
658 t->get_priority(), |
|
|
659 tstate |
|
|
660 ); |
|
|
661 |
|
|
662 # endif |
|
|
663 diag_printf( "%20s stack base = %08x ptr = %08x size = %08x\n", |
|
|
664 "", |
|
|
665 t->get_stack_base(), |
|
|
666 #ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT |
|
|
667 t->get_saved_context(), |
|
|
668 #else |
|
|
669 0, |
|
|
670 #endif |
|
|
671 t->get_stack_size() |
|
|
672 ); |
|
|
673 |
|
|
674 diag_printf( "%20s sleep reason %8s wake reason %8s\n", |
|
|
675 "", |
|
|
676 reasons[t->get_sleep_reason()], |
|
|
677 reasons[t->get_wake_reason()] |
|
|
678 ); |
|
|
679 |
|
|
680 diag_printf( "%20s queue = %08x wait info = %08x\n", |
|
|
681 "", |
|
|
682 t->get_current_queue(), |
|
|
683 t->get_wait_info() |
|
|
684 ); |
|
|
685 |
|
|
686 diag_printf("\n"); |
|
|
687 t = t->get_list_next(); |
|
|
688 } |
|
|
689 |
|
|
690 } |
|
|
691 # endif // CYGVAR_KERNEL_THREADS_LIST |
|
|
692 |
|
|
693 #endif // CYG_DIAG_PRINTF |
|
|
694 } |
|
|
695 |
|
|
696 #endif // CYGDBG_USE_TRACING |
|
|
697 |
|
|
698 // ------------------------------------------------------------------------- |
|
|
699 // Assert functions: |
|
|
700 |
|
|
701 #ifdef CYGDBG_USE_ASSERTS |
|
|
702 |
|
|
703 externC void |
|
2
|
704 cyg_assert_fail( const char *psz_func, const char *psz_file, |
|
|
705 cyg_uint32 linenum, const char *psz_msg ) |
|
0
|
706 { |
|
|
707 cyg_uint32 old_ints; |
|
|
708 |
|
|
709 HAL_DISABLE_INTERRUPTS(old_ints); |
|
|
710 DIAG_DEVICE_START_SYNC(); |
|
|
711 |
|
|
712 diag_write_string("ASSERT FAIL: "); |
|
|
713 write_thread_id(); |
|
|
714 diag_write_string(trim_file(psz_file)); |
|
|
715 write_lnum(linenum); |
|
|
716 diag_write_string(trim_func(psz_func)); |
|
|
717 diag_write_char(' '); |
|
|
718 diag_write_string(psz_msg); |
|
|
719 diag_write_char('\n'); |
|
|
720 |
|
|
721 #ifdef CYGDBG_INFRA_DEBUG_TRACE_BUFFER_PRINT_ON_ASSERT |
|
|
722 |
|
|
723 cyg_trace_print(); |
|
|
724 cyg_trace_dump(); |
|
|
725 |
|
|
726 #endif |
|
|
727 |
|
|
728 for(;;); |
|
|
729 |
|
|
730 // DIAG_DEVICE_END_SYNC(); |
|
|
731 // HAL_RESTORE_INTERRUPTS(old_ints); |
|
|
732 }; |
|
|
733 |
|
|
734 extern "C" |
|
|
735 { |
|
|
736 extern unsigned long CYG_LABEL_NAME(stext); |
|
|
737 extern unsigned long CYG_LABEL_NAME(etext); |
|
|
738 |
|
|
739 unsigned long stext_addr = (unsigned long)&CYG_LABEL_NAME(stext); |
|
|
740 unsigned long etext_addr = (unsigned long)&CYG_LABEL_NAME(etext); |
|
|
741 }; |
|
|
742 |
|
|
743 externC cyg_bool cyg_check_data_ptr(void *ptr) |
|
|
744 { |
|
|
745 unsigned long p = (unsigned long)ptr; |
|
|
746 |
|
|
747 if( p == 0 ) return false; |
|
|
748 |
|
|
749 if( p > stext_addr && p < etext_addr ) return false; |
|
|
750 |
|
|
751 return true; |
|
|
752 } |
|
|
753 |
|
|
754 externC cyg_bool cyg_check_func_ptr(void (*ptr)(void)) |
|
|
755 { |
|
|
756 unsigned long p = (unsigned long)ptr; |
|
|
757 |
|
|
758 if( p == 0 ) return false; |
|
|
759 |
|
|
760 if( p < stext_addr && p > etext_addr ) return false; |
|
|
761 |
|
|
762 return true; |
|
|
763 } |
|
|
764 |
|
|
765 #endif // CYGDBG_USE_ASSERTS |
|
|
766 |
|
|
767 #endif // CYGDBG_INFRA_DEBUG_TRACE_ASSERT_BUFFER |
|
|
768 |
|
|
769 // ------------------------------------------------------------------------- |
|
|
770 // EOF buffer.cxx |