Mercurial > flash_v2
annotate packages/infra/current/src/buffer.cxx @ 78:59d97b6ba612 ecos-sw-2000-03-28
Merge from eCos master repository on 2000-03-28-19:50:47-BST
| author | jlarmour |
|---|---|
| date | Tue, 28 Mar 2000 20:13:29 +0000 |
| parents | 435cced73e2f |
| children | 02ea4320376c |
| 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; | |
|
78
59d97b6ba612
Merge from eCos master repository on 2000-03-28-19:50:47-BST
jlarmour
parents:
76
diff
changeset
|
104 const char *function; |
|
59d97b6ba612
Merge from eCos master repository on 2000-03-28-19:50:47-BST
jlarmour
parents:
76
diff
changeset
|
105 const char *file; |
| 0 | 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 | |
|
76
435cced73e2f
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
jlarmour
parents:
74
diff
changeset
|
179 #if defined(CYGDBG_USE_TRACING) || defined(CYGDBG_USE_ASSERTS) |
|
435cced73e2f
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
jlarmour
parents:
74
diff
changeset
|
180 |
| 2 | 181 static const char *trim_file(const char *file) |
| 0 | 182 { |
| 183 #if CYG_FILENAME | |
| 184 if ( NULL == file ) | |
| 185 file = "<nofile>"; | |
| 186 | |
| 187 #if 1 == CYG_FILENAME | |
| 2 | 188 const char *f = file; |
| 0 | 189 while( *f ) f++; |
| 190 while( *f != '/' && f != file ) f--; | |
| 191 return f==file?f:(f+1); | |
| 192 #else | |
| 193 static char fbuf2[100]; | |
| 2 | 194 const char *f = file; |
| 195 char *g = fbuf2; | |
| 0 | 196 while( *f ) f++; |
| 197 while( *f != '/' && f != file ) f--; | |
| 198 if ( f > file ) f++; | |
| 199 while( *f ) *g++ = *f++; | |
| 200 while( CYG_FILENAME > (g - fbuf2) ) *g++ = ' '; | |
| 201 *g = 0; | |
| 202 return fbuf2; | |
| 203 #endif | |
| 204 #else | |
| 205 return ""; | |
| 206 #endif | |
| 207 } | |
| 208 | |
| 2 | 209 static const char *trim_func(const char *func) |
| 0 | 210 { |
| 211 #if CYG_FUNCNAME | |
| 212 static char fbuf[CYG_FBUF_SIZE]; | |
| 213 cyg_count32 i; | |
| 214 | |
| 215 if ( NULL == func ) | |
| 216 func = "<nofunc>"; | |
| 217 | |
| 218 for( i = 0; func[i] && func[i] != '(' && i < CYG_FBUF_SIZE-4 ; i++ ) | |
| 219 fbuf[i] = func[i]; | |
| 220 | |
| 221 fbuf[i++] = '('; | |
| 222 fbuf[i++] = ')'; | |
| 223 fbuf[i ] = 0; | |
| 2 | 224 i=0; |
| 0 | 225 #if 1 == CYG_FUNCNAME |
| 226 return &fbuf[i]; | |
| 227 #else | |
| 228 char *p = &fbuf[i]; | |
| 229 while ( *p ) p++; | |
| 230 while ( CYG_FUNCNAME > (p - (&fbuf[i])) ) *p++ = ' '; | |
| 231 *p = 0; | |
| 232 return &fbuf[i]; | |
| 233 #endif | |
| 234 #else | |
| 235 return ""; | |
| 236 #endif | |
| 237 } | |
| 238 | |
| 239 static void write_lnum( cyg_uint32 lnum) | |
| 240 { | |
| 241 #if CYG_LINENUM | |
| 242 diag_write_char('['); | |
| 243 #if 1 < CYG_LINENUM | |
| 244 cyg_uint32 i, j; | |
| 245 for ( i = 2, j = 100; i < CYG_LINENUM ; i++, j *= 10 ) | |
| 246 if ( lnum < j ) | |
| 247 diag_write_char(' '); | |
| 248 #endif | |
| 249 diag_write_dec(lnum); | |
| 250 diag_write_char(']'); | |
| 251 diag_write_char(' '); | |
| 252 #endif | |
| 253 } | |
| 254 | |
|
76
435cced73e2f
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
jlarmour
parents:
74
diff
changeset
|
255 #endif // defined(CYGDBG_USE_TRACING) || defined(CYGDBG_USE_ASSERTS) |
|
435cced73e2f
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
jlarmour
parents:
74
diff
changeset
|
256 |
| 0 | 257 // ------------------------------------------------------------------------- |
| 258 | |
|
76
435cced73e2f
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
jlarmour
parents:
74
diff
changeset
|
259 #if defined(CYGDBG_USE_TRACING) || defined(CYGDBG_USE_ASSERTS) |
|
435cced73e2f
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
jlarmour
parents:
74
diff
changeset
|
260 |
| 0 | 261 #if CYG_THREADID |
| 262 static cyg_uint32 get_tid(void) | |
| 263 { | |
| 264 | |
| 265 Cyg_Thread *t = Cyg_Thread::self(); | |
| 266 cyg_uint16 tid = 0xFFFF; | |
| 267 | |
| 268 if( t != NULL ) tid = t->get_unique_id(); | |
| 269 | |
| 270 return tid; | |
| 271 } | |
| 272 #else | |
| 273 # define get_tid() (0xFFFF) | |
| 274 #endif | |
| 275 | |
|
76
435cced73e2f
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
jlarmour
parents:
74
diff
changeset
|
276 #endif // defined(CYGDBG_USE_TRACING) || defined(CYGDBG_USE_ASSERTS) |
|
435cced73e2f
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
jlarmour
parents:
74
diff
changeset
|
277 |
| 2 | 278 #ifdef CYGDBG_USE_ASSERTS |
| 0 | 279 static void write_thread_id() |
| 280 { | |
| 281 #if CYG_THREADID | |
| 282 cyg_uint16 tid = get_tid(); | |
| 283 | |
| 284 diag_write_char('<'); | |
| 285 diag_write_hex(tid); | |
| 286 diag_write_char('>'); | |
| 287 #endif | |
| 288 } | |
| 2 | 289 #endif |
| 0 | 290 |
| 291 // ------------------------------------------------------------------------- | |
| 292 // Trace functions: | |
| 293 | |
| 294 #ifdef CYGDBG_USE_TRACING | |
| 295 | |
| 296 static void print_trace_buffer(void) | |
| 297 { | |
| 298 cyg_count32 start = cyg_infra_trace_buffer_pos; | |
| 299 cyg_count32 end = start; | |
| 300 cyg_count32 i; | |
| 301 | |
| 302 // If the buffer has wrapped we want to display the records from | |
| 303 // the current pos and around back to the same place. If the buffer | |
| 304 // has not wrapped, we want to display from the start to pos. | |
| 305 | |
| 306 if( !cyg_infra_trace_buffer_wrap ) | |
| 307 start = 0; | |
| 308 | |
| 309 i = start; | |
| 310 do | |
| 311 { | |
| 312 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[i]; | |
| 313 cyg_uint32 old_ints; | |
| 314 | |
| 315 char *psz_msg = rec->message; | |
| 316 | |
| 317 | |
| 318 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 319 DIAG_DEVICE_START_SYNC(); | |
| 320 | |
| 321 if ( NULL == psz_msg ) | |
| 322 psz_msg = "<nomsg>"; | |
| 323 | |
| 324 diag_write_string( "TRACE: " ); | |
| 325 #if CYG_THREADID | |
| 326 diag_write_char('<'); | |
| 327 diag_write_hex(rec->tid); | |
| 328 diag_write_char('>'); | |
| 329 #endif | |
| 330 diag_write_string(trim_file(rec->file)); | |
| 331 write_lnum(rec->line); | |
| 332 diag_write_string(trim_func(rec->function)); | |
| 333 diag_write_char(' '); | |
| 334 write_whattrace( rec->what ); | |
| 335 #if CYG_DIAG_PRINTF | |
| 336 diag_printf( psz_msg, | |
| 337 rec->arg[0], rec->arg[1], | |
| 338 rec->arg[2], rec->arg[3], | |
| 339 rec->arg[4], rec->arg[5], | |
| 340 rec->arg[6], rec->arg[7] ); | |
| 341 #else | |
| 342 diag_write_string(psz_msg); | |
| 343 diag_write_char(' '); | |
| 344 | |
| 345 for( cyg_count8 j = 0; j < rec->narg ; j++ ) | |
| 346 { | |
| 347 diag_write_hex(rec->arg[j]); | |
| 348 diag_write_char(' '); | |
| 349 } | |
| 350 #endif | |
| 351 write_whattracepost( rec->what ); | |
| 352 diag_write_char('\n'); | |
| 353 | |
| 354 DIAG_DEVICE_END_SYNC(); | |
| 355 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 356 | |
| 357 i++; | |
| 358 if( i == CYGDBG_INFRA_DEBUG_TRACE_BUFFER_SIZE ) | |
| 359 i = 0; | |
| 360 | |
| 361 } while( i != end ); | |
| 362 | |
| 363 } | |
| 364 | |
| 365 static void increment_buffer_pos() | |
| 366 { | |
| 367 cyg_infra_trace_buffer_pos++; | |
| 368 | |
| 369 if( cyg_infra_trace_buffer_pos == CYGDBG_INFRA_DEBUG_TRACE_BUFFER_SIZE ) | |
| 370 { | |
| 371 #if defined(CYGDBG_INFRA_DEBUG_TRACE_BUFFER_WRAP) | |
| 372 cyg_infra_trace_buffer_pos = 0; | |
| 373 cyg_infra_trace_buffer_wrap = true; | |
| 374 #elif defined(CYGDBG_INFRA_DEBUG_TRACE_BUFFER_HALT) | |
| 375 cyg_infra_trace_buffer_enable = false; | |
| 376 #elif defined(CYGDBG_INFRA_DEBUG_TRACE_BUFFER_PRINT) | |
| 377 print_trace_buffer(); | |
| 378 cyg_infra_trace_buffer_pos = 0; | |
| 379 cyg_infra_trace_buffer_wrap = false; | |
| 380 #else | |
| 381 #error No trace buffer full mode set | |
| 382 #endif | |
| 383 } | |
| 384 | |
| 385 } | |
| 386 | |
| 387 // ------------------------------------------------------------------------- | |
| 388 | |
| 389 externC void | |
|
78
59d97b6ba612
Merge from eCos master repository on 2000-03-28-19:50:47-BST
jlarmour
parents:
76
diff
changeset
|
390 cyg_tracenomsg( const char *psz_func, const char *psz_file, cyg_uint32 linenum ) |
| 0 | 391 { |
| 392 cyg_uint32 old_ints; | |
| 393 | |
| 394 if( !cyg_infra_trace_buffer_enable ) return; | |
| 395 | |
| 396 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 397 | |
| 398 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 399 | |
| 400 rec->what = 0; | |
| 401 rec->tid = get_tid(); | |
| 402 rec->function = psz_func; | |
| 403 rec->file = psz_file; | |
| 404 rec->line = linenum; | |
| 405 rec->message = 0; | |
| 406 rec->narg = 0; | |
| 407 | |
| 408 increment_buffer_pos(); | |
| 409 | |
| 410 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 411 | |
| 412 }; | |
| 413 | |
| 414 // provide every other one of these as a space/caller bloat compromise. | |
| 415 | |
| 416 externC void | |
| 417 cyg_tracemsg( cyg_uint32 what, | |
|
78
59d97b6ba612
Merge from eCos master repository on 2000-03-28-19:50:47-BST
jlarmour
parents:
76
diff
changeset
|
418 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 419 char *psz_msg ) |
| 420 { | |
| 421 cyg_uint32 old_ints; | |
| 422 | |
| 423 if( !cyg_infra_trace_buffer_enable ) return; | |
| 424 | |
| 425 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 426 | |
| 427 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 428 | |
| 429 rec->what = what; | |
| 430 rec->tid = get_tid(); | |
| 431 rec->function = psz_func; | |
| 432 rec->file = psz_file; | |
| 433 rec->line = linenum; | |
| 434 rec->message = psz_msg; | |
| 435 rec->narg = 0; | |
| 436 | |
| 437 increment_buffer_pos(); | |
| 438 | |
| 439 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 440 | |
| 441 }; | |
| 442 | |
| 443 externC void | |
| 444 cyg_tracemsg2( cyg_uint32 what, | |
|
78
59d97b6ba612
Merge from eCos master repository on 2000-03-28-19:50:47-BST
jlarmour
parents:
76
diff
changeset
|
445 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 446 char *psz_msg, |
| 447 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1 ) | |
| 448 { | |
| 449 cyg_uint32 old_ints; | |
| 450 | |
| 451 if( !cyg_infra_trace_buffer_enable ) return; | |
| 452 | |
| 453 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 454 | |
| 455 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 456 | |
| 457 rec->what = what; | |
| 458 rec->tid = get_tid(); | |
| 459 rec->function = psz_func; | |
| 460 rec->file = psz_file; | |
| 461 rec->line = linenum; | |
| 462 rec->message = psz_msg; | |
| 463 rec->narg = 2; | |
| 464 | |
| 465 rec->arg[0] = arg0; | |
| 466 rec->arg[1] = arg1; | |
| 467 | |
| 468 increment_buffer_pos(); | |
| 469 | |
| 470 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 471 }; | |
| 472 | |
| 473 externC void | |
| 474 cyg_tracemsg4( cyg_uint32 what, | |
|
78
59d97b6ba612
Merge from eCos master repository on 2000-03-28-19:50:47-BST
jlarmour
parents:
76
diff
changeset
|
475 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 476 char *psz_msg, |
| 477 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, | |
| 478 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3 ) | |
| 479 { | |
| 480 cyg_uint32 old_ints; | |
| 481 | |
| 482 if( !cyg_infra_trace_buffer_enable ) return; | |
| 483 | |
| 484 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 485 | |
| 486 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 487 | |
| 488 rec->what = what; | |
| 489 rec->tid = get_tid(); | |
| 490 rec->function = psz_func; | |
| 491 rec->file = psz_file; | |
| 492 rec->line = linenum; | |
| 493 rec->message = psz_msg; | |
| 494 rec->narg = 4; | |
| 495 | |
| 496 rec->arg[0] = arg0; | |
| 497 rec->arg[1] = arg1; | |
| 498 rec->arg[2] = arg2; | |
| 499 rec->arg[3] = arg3; | |
| 500 | |
| 501 increment_buffer_pos(); | |
| 502 | |
| 503 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 504 }; | |
| 505 | |
| 506 externC void | |
| 507 cyg_tracemsg6( cyg_uint32 what, | |
|
78
59d97b6ba612
Merge from eCos master repository on 2000-03-28-19:50:47-BST
jlarmour
parents:
76
diff
changeset
|
508 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 509 char *psz_msg, |
| 510 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, | |
| 511 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3, | |
| 512 CYG_ADDRWORD arg4, CYG_ADDRWORD arg5 ) | |
| 513 { | |
| 514 cyg_uint32 old_ints; | |
| 515 | |
| 516 if( !cyg_infra_trace_buffer_enable ) return; | |
| 517 | |
| 518 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 519 | |
| 520 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 521 | |
| 522 rec->what = what; | |
| 523 rec->tid = get_tid(); | |
| 524 rec->function = psz_func; | |
| 525 rec->file = psz_file; | |
| 526 rec->line = linenum; | |
| 527 rec->message = psz_msg; | |
| 528 rec->narg = 6; | |
| 529 | |
| 530 rec->arg[0] = arg0; | |
| 531 rec->arg[1] = arg1; | |
| 532 rec->arg[2] = arg2; | |
| 533 rec->arg[3] = arg3; | |
| 534 rec->arg[4] = arg4; | |
| 535 rec->arg[5] = arg5; | |
| 536 | |
| 537 increment_buffer_pos(); | |
| 538 | |
| 539 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 540 }; | |
| 541 | |
| 542 externC void | |
| 543 cyg_tracemsg8( cyg_uint32 what, | |
|
78
59d97b6ba612
Merge from eCos master repository on 2000-03-28-19:50:47-BST
jlarmour
parents:
76
diff
changeset
|
544 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 545 char *psz_msg, |
| 546 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, | |
| 547 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3, | |
| 548 CYG_ADDRWORD arg4, CYG_ADDRWORD arg5, | |
| 549 CYG_ADDRWORD arg6, CYG_ADDRWORD arg7 ) | |
| 550 { | |
| 551 cyg_uint32 old_ints; | |
| 552 | |
| 553 if( !cyg_infra_trace_buffer_enable ) return; | |
| 554 | |
| 555 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 556 | |
| 557 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 558 | |
| 559 rec->what = what; | |
| 560 rec->tid = get_tid(); | |
| 561 rec->function = psz_func; | |
| 562 rec->file = psz_file; | |
| 563 rec->line = linenum; | |
| 564 rec->message = psz_msg; | |
| 565 rec->narg = 6; | |
| 566 | |
| 567 rec->arg[0] = arg0; | |
| 568 rec->arg[1] = arg1; | |
| 569 rec->arg[2] = arg2; | |
| 570 rec->arg[3] = arg3; | |
| 571 rec->arg[4] = arg4; | |
| 572 rec->arg[5] = arg5; | |
| 573 rec->arg[6] = arg6; | |
| 574 rec->arg[7] = arg7; | |
| 575 | |
| 576 increment_buffer_pos(); | |
| 577 | |
| 578 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 579 }; | |
| 580 | |
| 581 // ------------------------------------------------------------------------- | |
| 582 | |
| 583 externC void | |
| 584 cyg_trace_print(void) | |
| 585 { | |
| 586 cyg_bool old_enable = cyg_infra_trace_buffer_enable; | |
| 587 cyg_infra_trace_buffer_enable = false; | |
| 588 print_trace_buffer(); | |
| 589 cyg_infra_trace_buffer_pos = 0; | |
| 590 cyg_infra_trace_buffer_wrap = false; | |
| 591 cyg_infra_trace_buffer_enable = old_enable; | |
| 592 } | |
| 593 | |
| 594 | |
| 595 // ------------------------------------------------------------------------- | |
| 596 | |
| 597 externC void | |
| 598 cyg_trace_dump(void) | |
| 599 { | |
| 600 #if defined(CYGPKG_KERNEL) && defined(CYG_DIAG_PRINTF) | |
| 601 | |
| 602 { | |
| 603 diag_printf("\nScheduler:\n\n"); | |
| 604 | |
| 605 Cyg_Scheduler *sched = &Cyg_Scheduler::scheduler; | |
| 606 | |
| 607 diag_printf("Lock: %d\n",sched->get_sched_lock() ); | |
| 608 | |
| 609 # ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 610 | |
| 611 diag_printf("Current Thread: %s\n",sched->get_current_thread()->get_name()); | |
| 612 | |
| 613 # else | |
| 614 | |
| 615 diag_printf("Current Thread: %d\n",sched->get_current_thread()->get_unique_id()); | |
| 616 | |
| 617 # endif | |
| 618 | |
| 619 } | |
| 620 | |
| 621 # ifdef CYGVAR_KERNEL_THREADS_LIST | |
| 622 | |
| 623 { | |
| 624 Cyg_Thread *t = Cyg_Thread::get_list_head(); | |
| 625 | |
| 626 diag_printf("\nThreads:\n\n"); | |
| 627 | |
| 628 while( NULL != t ) | |
| 629 { | |
| 630 cyg_uint32 state = t->get_state(); | |
| 631 char tstate[7]; | |
| 632 char *tstate1 = "SCUKX"; | |
| 633 static char *(reasons[8]) = | |
| 634 { | |
| 635 "NONE", // No recorded reason | |
| 636 "WAIT", // Wait with no timeout | |
| 637 "DELAY", // Simple time delay | |
| 638 "TIMEOUT", // Wait with timeout/timeout expired | |
| 639 "BREAK", // forced break out of sleep | |
| 640 "DESTRUCT", // wait object destroyed[note] | |
| 641 "EXIT", // forced termination | |
| 642 "DONE" // Wait/delay complete | |
| 643 }; | |
| 644 | |
| 645 if( 0 != state ) | |
| 646 { | |
| 647 // Knock out chars that do not correspond to set bits. | |
| 648 for( int i = 0; i < 6 ; i++ ) | |
| 649 if( 0 == (state & (1<<i)) ) | |
| 650 tstate[i] = ' '; | |
| 651 else tstate[i] = tstate1[i]; | |
| 652 tstate[6] = 0; | |
| 653 } | |
| 654 else tstate[0] = 'R', tstate[1] = 0; | |
| 655 | |
| 656 # ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 657 | |
| 658 diag_printf( "%20s pri = %3d state = %6s id = %3d\n", | |
| 659 t->get_name(), | |
| 660 t->get_priority(), | |
| 661 tstate, | |
| 662 t->get_unique_id() | |
| 663 ); | |
| 664 # else | |
| 665 | |
| 666 diag_printf( "Thread %3d pri = %3d state = %6s\n", | |
| 667 t->get_unique_id(), | |
| 668 t->get_priority(), | |
| 669 tstate | |
| 670 ); | |
| 671 | |
| 672 # endif | |
| 673 diag_printf( "%20s stack base = %08x ptr = %08x size = %08x\n", | |
| 674 "", | |
| 675 t->get_stack_base(), | |
| 676 #ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT | |
| 677 t->get_saved_context(), | |
| 678 #else | |
| 679 0, | |
| 680 #endif | |
| 681 t->get_stack_size() | |
| 682 ); | |
| 683 | |
| 684 diag_printf( "%20s sleep reason %8s wake reason %8s\n", | |
| 685 "", | |
| 686 reasons[t->get_sleep_reason()], | |
| 687 reasons[t->get_wake_reason()] | |
| 688 ); | |
| 689 | |
| 690 diag_printf( "%20s queue = %08x wait info = %08x\n", | |
| 691 "", | |
| 692 t->get_current_queue(), | |
| 693 t->get_wait_info() | |
| 694 ); | |
| 695 | |
| 696 diag_printf("\n"); | |
| 697 t = t->get_list_next(); | |
| 698 } | |
| 699 | |
| 700 } | |
| 701 # endif // CYGVAR_KERNEL_THREADS_LIST | |
| 702 | |
| 703 #endif // CYG_DIAG_PRINTF | |
| 704 } | |
| 705 | |
| 706 #endif // CYGDBG_USE_TRACING | |
| 707 | |
| 708 // ------------------------------------------------------------------------- | |
| 709 // Assert functions: | |
| 710 | |
| 711 #ifdef CYGDBG_USE_ASSERTS | |
| 712 | |
| 713 externC void | |
| 2 | 714 cyg_assert_fail( const char *psz_func, const char *psz_file, |
| 715 cyg_uint32 linenum, const char *psz_msg ) | |
| 0 | 716 { |
| 717 cyg_uint32 old_ints; | |
| 718 | |
| 719 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 720 DIAG_DEVICE_START_SYNC(); | |
| 721 | |
| 722 diag_write_string("ASSERT FAIL: "); | |
| 723 write_thread_id(); | |
| 724 diag_write_string(trim_file(psz_file)); | |
| 725 write_lnum(linenum); | |
| 726 diag_write_string(trim_func(psz_func)); | |
| 727 diag_write_char(' '); | |
| 728 diag_write_string(psz_msg); | |
| 729 diag_write_char('\n'); | |
| 730 | |
| 731 #ifdef CYGDBG_INFRA_DEBUG_TRACE_BUFFER_PRINT_ON_ASSERT | |
| 732 | |
| 733 cyg_trace_print(); | |
| 734 cyg_trace_dump(); | |
| 735 | |
| 736 #endif | |
| 737 | |
|
74
9c122302a886
Merge from eCos master repository on 2000-02-18-15:21:53-GMT
jlarmour
parents:
66
diff
changeset
|
738 #ifdef CYGHWR_TEST_PROGRAM_EXIT |
|
9c122302a886
Merge from eCos master repository on 2000-02-18-15:21:53-GMT
jlarmour
parents:
66
diff
changeset
|
739 CYGHWR_TEST_PROGRAM_EXIT(); |
|
9c122302a886
Merge from eCos master repository on 2000-02-18-15:21:53-GMT
jlarmour
parents:
66
diff
changeset
|
740 #endif |
| 0 | 741 for(;;); |
| 742 | |
| 743 // DIAG_DEVICE_END_SYNC(); | |
| 744 // HAL_RESTORE_INTERRUPTS(old_ints); | |
| 745 }; | |
| 746 | |
| 747 extern "C" | |
| 748 { | |
| 749 extern unsigned long CYG_LABEL_NAME(stext); | |
| 750 extern unsigned long CYG_LABEL_NAME(etext); | |
| 751 | |
| 752 unsigned long stext_addr = (unsigned long)&CYG_LABEL_NAME(stext); | |
| 753 unsigned long etext_addr = (unsigned long)&CYG_LABEL_NAME(etext); | |
| 754 }; | |
| 755 | |
| 756 externC cyg_bool cyg_check_data_ptr(void *ptr) | |
| 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 externC cyg_bool cyg_check_func_ptr(void (*ptr)(void)) | |
| 768 { | |
| 769 unsigned long p = (unsigned long)ptr; | |
| 770 | |
| 771 if( p == 0 ) return false; | |
| 772 | |
| 773 if( p < stext_addr && p > etext_addr ) return false; | |
| 774 | |
| 775 return true; | |
| 776 } | |
| 777 | |
| 778 #endif // CYGDBG_USE_ASSERTS | |
| 779 | |
| 780 #endif // CYGDBG_INFRA_DEBUG_TRACE_ASSERT_BUFFER | |
| 781 | |
| 782 // ------------------------------------------------------------------------- | |
| 783 // EOF buffer.cxx |
