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