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