Mercurial > ecos
annotate packages/infra/current/src/buffer.cxx @ 115:6ed91473a1cd ecos-sw-2000-08-21
Merge from eCos master repository on 2000-08-21-22:40:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 25 Aug 2000 17:32:38 +0000 |
| parents | 02ea4320376c |
| children | f62680ef1804 |
| 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) | |
|
112
02ea4320376c
Merge from eCos master repository on 2000-07-21-21:01:39-BST
jlarmour
parents:
78
diff
changeset
|
377 cyg_infra_trace_buffer_pos = 0; |
| 0 | 378 print_trace_buffer(); |
|
112
02ea4320376c
Merge from eCos master repository on 2000-07-21-21:01:39-BST
jlarmour
parents:
78
diff
changeset
|
379 #else |
|
02ea4320376c
Merge from eCos master repository on 2000-07-21-21:01:39-BST
jlarmour
parents:
78
diff
changeset
|
380 #error No trace buffer full mode set |
| 0 | 381 #endif |
| 382 } | |
| 383 | |
| 384 } | |
| 385 | |
| 386 // ------------------------------------------------------------------------- | |
| 387 | |
| 388 externC void | |
|
78
59d97b6ba612
Merge from eCos master repository on 2000-03-28-19:50:47-BST
jlarmour
parents:
76
diff
changeset
|
389 cyg_tracenomsg( const char *psz_func, const char *psz_file, cyg_uint32 linenum ) |
| 0 | 390 { |
| 391 cyg_uint32 old_ints; | |
| 392 | |
| 393 if( !cyg_infra_trace_buffer_enable ) return; | |
| 394 | |
| 395 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 396 | |
| 397 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 398 | |
| 399 rec->what = 0; | |
| 400 rec->tid = get_tid(); | |
| 401 rec->function = psz_func; | |
| 402 rec->file = psz_file; | |
| 403 rec->line = linenum; | |
| 404 rec->message = 0; | |
| 405 rec->narg = 0; | |
| 406 | |
| 407 increment_buffer_pos(); | |
| 408 | |
| 409 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 410 | |
| 411 }; | |
| 412 | |
| 413 // provide every other one of these as a space/caller bloat compromise. | |
| 414 | |
| 415 externC void | |
| 416 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
|
417 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 418 char *psz_msg ) |
| 419 { | |
| 420 cyg_uint32 old_ints; | |
| 421 | |
| 422 if( !cyg_infra_trace_buffer_enable ) return; | |
| 423 | |
| 424 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 425 | |
| 426 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 427 | |
| 428 rec->what = what; | |
| 429 rec->tid = get_tid(); | |
| 430 rec->function = psz_func; | |
| 431 rec->file = psz_file; | |
| 432 rec->line = linenum; | |
| 433 rec->message = psz_msg; | |
| 434 rec->narg = 0; | |
| 435 | |
| 436 increment_buffer_pos(); | |
| 437 | |
| 438 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 439 | |
| 440 }; | |
| 441 | |
| 442 externC void | |
| 443 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
|
444 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 445 char *psz_msg, |
| 446 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1 ) | |
| 447 { | |
| 448 cyg_uint32 old_ints; | |
| 449 | |
| 450 if( !cyg_infra_trace_buffer_enable ) return; | |
| 451 | |
| 452 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 453 | |
| 454 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 455 | |
| 456 rec->what = what; | |
| 457 rec->tid = get_tid(); | |
| 458 rec->function = psz_func; | |
| 459 rec->file = psz_file; | |
| 460 rec->line = linenum; | |
| 461 rec->message = psz_msg; | |
| 462 rec->narg = 2; | |
| 463 | |
| 464 rec->arg[0] = arg0; | |
| 465 rec->arg[1] = arg1; | |
| 466 | |
| 467 increment_buffer_pos(); | |
| 468 | |
| 469 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 470 }; | |
| 471 | |
| 472 externC void | |
| 473 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
|
474 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 475 char *psz_msg, |
| 476 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, | |
| 477 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3 ) | |
| 478 { | |
| 479 cyg_uint32 old_ints; | |
| 480 | |
| 481 if( !cyg_infra_trace_buffer_enable ) return; | |
| 482 | |
| 483 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 484 | |
| 485 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 486 | |
| 487 rec->what = what; | |
| 488 rec->tid = get_tid(); | |
| 489 rec->function = psz_func; | |
| 490 rec->file = psz_file; | |
| 491 rec->line = linenum; | |
| 492 rec->message = psz_msg; | |
| 493 rec->narg = 4; | |
| 494 | |
| 495 rec->arg[0] = arg0; | |
| 496 rec->arg[1] = arg1; | |
| 497 rec->arg[2] = arg2; | |
| 498 rec->arg[3] = arg3; | |
| 499 | |
| 500 increment_buffer_pos(); | |
| 501 | |
| 502 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 503 }; | |
| 504 | |
| 505 externC void | |
| 506 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
|
507 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 508 char *psz_msg, |
| 509 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, | |
| 510 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3, | |
| 511 CYG_ADDRWORD arg4, CYG_ADDRWORD arg5 ) | |
| 512 { | |
| 513 cyg_uint32 old_ints; | |
| 514 | |
| 515 if( !cyg_infra_trace_buffer_enable ) return; | |
| 516 | |
| 517 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 518 | |
| 519 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 520 | |
| 521 rec->what = what; | |
| 522 rec->tid = get_tid(); | |
| 523 rec->function = psz_func; | |
| 524 rec->file = psz_file; | |
| 525 rec->line = linenum; | |
| 526 rec->message = psz_msg; | |
| 527 rec->narg = 6; | |
| 528 | |
| 529 rec->arg[0] = arg0; | |
| 530 rec->arg[1] = arg1; | |
| 531 rec->arg[2] = arg2; | |
| 532 rec->arg[3] = arg3; | |
| 533 rec->arg[4] = arg4; | |
| 534 rec->arg[5] = arg5; | |
| 535 | |
| 536 increment_buffer_pos(); | |
| 537 | |
| 538 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 539 }; | |
| 540 | |
| 541 externC void | |
| 542 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
|
543 const char *psz_func, const char *psz_file, cyg_uint32 linenum, |
| 0 | 544 char *psz_msg, |
| 545 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, | |
| 546 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3, | |
| 547 CYG_ADDRWORD arg4, CYG_ADDRWORD arg5, | |
| 548 CYG_ADDRWORD arg6, CYG_ADDRWORD arg7 ) | |
| 549 { | |
| 550 cyg_uint32 old_ints; | |
| 551 | |
| 552 if( !cyg_infra_trace_buffer_enable ) return; | |
| 553 | |
| 554 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 555 | |
| 556 Cyg_TraceRecord *rec = &cyg_infra_trace_buffer[cyg_infra_trace_buffer_pos]; | |
| 557 | |
| 558 rec->what = what; | |
| 559 rec->tid = get_tid(); | |
| 560 rec->function = psz_func; | |
| 561 rec->file = psz_file; | |
| 562 rec->line = linenum; | |
| 563 rec->message = psz_msg; | |
| 564 rec->narg = 6; | |
| 565 | |
| 566 rec->arg[0] = arg0; | |
| 567 rec->arg[1] = arg1; | |
| 568 rec->arg[2] = arg2; | |
| 569 rec->arg[3] = arg3; | |
| 570 rec->arg[4] = arg4; | |
| 571 rec->arg[5] = arg5; | |
| 572 rec->arg[6] = arg6; | |
| 573 rec->arg[7] = arg7; | |
| 574 | |
| 575 increment_buffer_pos(); | |
| 576 | |
| 577 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 578 }; | |
| 579 | |
| 580 // ------------------------------------------------------------------------- | |
| 581 | |
| 582 externC void | |
| 583 cyg_trace_print(void) | |
| 584 { | |
| 585 cyg_bool old_enable = cyg_infra_trace_buffer_enable; | |
| 586 cyg_infra_trace_buffer_enable = false; | |
| 587 print_trace_buffer(); | |
| 588 cyg_infra_trace_buffer_pos = 0; | |
| 589 cyg_infra_trace_buffer_wrap = false; | |
| 590 cyg_infra_trace_buffer_enable = old_enable; | |
| 591 } | |
| 592 | |
| 593 | |
| 594 // ------------------------------------------------------------------------- | |
| 595 | |
| 596 externC void | |
| 597 cyg_trace_dump(void) | |
| 598 { | |
| 599 #if defined(CYGPKG_KERNEL) && defined(CYG_DIAG_PRINTF) | |
| 600 | |
| 601 { | |
| 602 diag_printf("\nScheduler:\n\n"); | |
| 603 | |
| 604 Cyg_Scheduler *sched = &Cyg_Scheduler::scheduler; | |
| 605 | |
| 606 diag_printf("Lock: %d\n",sched->get_sched_lock() ); | |
| 607 | |
| 608 # ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 609 | |
| 610 diag_printf("Current Thread: %s\n",sched->get_current_thread()->get_name()); | |
| 611 | |
| 612 # else | |
| 613 | |
| 614 diag_printf("Current Thread: %d\n",sched->get_current_thread()->get_unique_id()); | |
| 615 | |
| 616 # endif | |
| 617 | |
| 618 } | |
| 619 | |
| 620 # ifdef CYGVAR_KERNEL_THREADS_LIST | |
| 621 | |
| 622 { | |
| 623 Cyg_Thread *t = Cyg_Thread::get_list_head(); | |
| 624 | |
| 625 diag_printf("\nThreads:\n\n"); | |
| 626 | |
| 627 while( NULL != t ) | |
| 628 { | |
| 629 cyg_uint32 state = t->get_state(); | |
| 630 char tstate[7]; | |
| 631 char *tstate1 = "SCUKX"; | |
| 632 static char *(reasons[8]) = | |
| 633 { | |
| 634 "NONE", // No recorded reason | |
| 635 "WAIT", // Wait with no timeout | |
| 636 "DELAY", // Simple time delay | |
| 637 "TIMEOUT", // Wait with timeout/timeout expired | |
| 638 "BREAK", // forced break out of sleep | |
| 639 "DESTRUCT", // wait object destroyed[note] | |
| 640 "EXIT", // forced termination | |
| 641 "DONE" // Wait/delay complete | |
| 642 }; | |
| 643 | |
| 644 if( 0 != state ) | |
| 645 { | |
| 646 // Knock out chars that do not correspond to set bits. | |
| 647 for( int i = 0; i < 6 ; i++ ) | |
| 648 if( 0 == (state & (1<<i)) ) | |
| 649 tstate[i] = ' '; | |
| 650 else tstate[i] = tstate1[i]; | |
| 651 tstate[6] = 0; | |
| 652 } | |
| 653 else tstate[0] = 'R', tstate[1] = 0; | |
| 654 | |
| 655 # ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 656 | |
| 657 diag_printf( "%20s pri = %3d state = %6s id = %3d\n", | |
| 658 t->get_name(), | |
| 659 t->get_priority(), | |
| 660 tstate, | |
| 661 t->get_unique_id() | |
| 662 ); | |
| 663 # else | |
| 664 | |
| 665 diag_printf( "Thread %3d pri = %3d state = %6s\n", | |
| 666 t->get_unique_id(), | |
| 667 t->get_priority(), | |
| 668 tstate | |
| 669 ); | |
| 670 | |
| 671 # endif | |
| 672 diag_printf( "%20s stack base = %08x ptr = %08x size = %08x\n", | |
| 673 "", | |
| 674 t->get_stack_base(), | |
| 675 #ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT | |
| 676 t->get_saved_context(), | |
| 677 #else | |
| 678 0, | |
| 679 #endif | |
| 680 t->get_stack_size() | |
| 681 ); | |
| 682 | |
| 683 diag_printf( "%20s sleep reason %8s wake reason %8s\n", | |
| 684 "", | |
| 685 reasons[t->get_sleep_reason()], | |
| 686 reasons[t->get_wake_reason()] | |
| 687 ); | |
| 688 | |
| 689 diag_printf( "%20s queue = %08x wait info = %08x\n", | |
| 690 "", | |
| 691 t->get_current_queue(), | |
| 692 t->get_wait_info() | |
| 693 ); | |
| 694 | |
| 695 diag_printf("\n"); | |
| 696 t = t->get_list_next(); | |
| 697 } | |
| 698 | |
| 699 } | |
| 700 # endif // CYGVAR_KERNEL_THREADS_LIST | |
| 701 | |
| 702 #endif // CYG_DIAG_PRINTF | |
| 703 } | |
| 704 | |
| 705 #endif // CYGDBG_USE_TRACING | |
| 706 | |
| 707 // ------------------------------------------------------------------------- | |
| 708 // Assert functions: | |
| 709 | |
| 710 #ifdef CYGDBG_USE_ASSERTS | |
| 711 | |
| 712 externC void | |
| 2 | 713 cyg_assert_fail( const char *psz_func, const char *psz_file, |
| 714 cyg_uint32 linenum, const char *psz_msg ) | |
| 0 | 715 { |
| 716 cyg_uint32 old_ints; | |
| 717 | |
| 718 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 719 DIAG_DEVICE_START_SYNC(); | |
| 720 | |
| 721 diag_write_string("ASSERT FAIL: "); | |
| 722 write_thread_id(); | |
| 723 diag_write_string(trim_file(psz_file)); | |
| 724 write_lnum(linenum); | |
| 725 diag_write_string(trim_func(psz_func)); | |
| 726 diag_write_char(' '); | |
| 727 diag_write_string(psz_msg); | |
| 728 diag_write_char('\n'); | |
| 729 | |
| 730 #ifdef CYGDBG_INFRA_DEBUG_TRACE_BUFFER_PRINT_ON_ASSERT | |
| 731 | |
| 732 cyg_trace_print(); | |
| 733 cyg_trace_dump(); | |
| 734 | |
| 735 #endif | |
| 736 | |
|
74
9c122302a886
Merge from eCos master repository on 2000-02-18-15:21:53-GMT
jlarmour
parents:
66
diff
changeset
|
737 #ifdef CYGHWR_TEST_PROGRAM_EXIT |
|
9c122302a886
Merge from eCos master repository on 2000-02-18-15:21:53-GMT
jlarmour
parents:
66
diff
changeset
|
738 CYGHWR_TEST_PROGRAM_EXIT(); |
|
9c122302a886
Merge from eCos master repository on 2000-02-18-15:21:53-GMT
jlarmour
parents:
66
diff
changeset
|
739 #endif |
| 0 | 740 for(;;); |
| 741 | |
| 742 // DIAG_DEVICE_END_SYNC(); | |
| 743 // HAL_RESTORE_INTERRUPTS(old_ints); | |
| 744 }; | |
| 745 | |
| 746 extern "C" | |
| 747 { | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
112
diff
changeset
|
748 extern unsigned long _stext; |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
112
diff
changeset
|
749 extern unsigned long _etext; |
| 0 | 750 |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
112
diff
changeset
|
751 unsigned long stext_addr = (unsigned long)&_stext; |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
112
diff
changeset
|
752 unsigned long etext_addr = (unsigned long)&_etext; |
| 0 | 753 }; |
| 754 | |
| 755 externC cyg_bool cyg_check_data_ptr(void *ptr) | |
| 756 { | |
| 757 unsigned long p = (unsigned long)ptr; | |
| 758 | |
| 759 if( p == 0 ) return false; | |
| 760 | |
| 761 if( p > stext_addr && p < etext_addr ) return false; | |
| 762 | |
| 763 return true; | |
| 764 } | |
| 765 | |
| 766 externC cyg_bool cyg_check_func_ptr(void (*ptr)(void)) | |
| 767 { | |
| 768 unsigned long p = (unsigned long)ptr; | |
| 769 | |
| 770 if( p == 0 ) return false; | |
| 771 | |
| 772 if( p < stext_addr && p > etext_addr ) return false; | |
| 773 | |
| 774 return true; | |
| 775 } | |
| 776 | |
| 777 #endif // CYGDBG_USE_ASSERTS | |
| 778 | |
| 779 #endif // CYGDBG_INFRA_DEBUG_TRACE_ASSERT_BUFFER | |
| 780 | |
| 781 // ------------------------------------------------------------------------- | |
| 782 // EOF buffer.cxx |
