Mercurial > ecos
comparison packages/infra/current/src/tcdiag.cxx @ 208:e0c0827131d1 ecos
Merge from eCos master repository on 2002-05-20-20:11:54-BST
| author | jlarmour |
|---|---|
| date | Mon, 20 May 2002 22:19:26 +0000 |
| parents | 4c750ce71ae3 |
| children | d2c90368aeef |
comparison
equal
deleted
inserted
replaced
| 207:74c807ddde34 | 208:e0c0827131d1 |
|---|---|
| 3 // tcdiag.cxx | 3 // tcdiag.cxx |
| 4 // | 4 // |
| 5 // Infrastructure diag test harness. | 5 // Infrastructure diag test harness. |
| 6 // | 6 // |
| 7 //========================================================================== | 7 //========================================================================== |
| 8 //####COPYRIGHTBEGIN#### | 8 //####ECOSGPLCOPYRIGHTBEGIN#### |
| 9 // | 9 // ------------------------------------------- |
| 10 // ------------------------------------------- | 10 // This file is part of eCos, the Embedded Configurable Operating System. |
| 11 // The contents of this file are subject to the Red Hat eCos Public License | 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
| 12 // Version 1.1 (the "License"); you may not use this file except in | 12 // |
| 13 // compliance with the License. You may obtain a copy of the License at | 13 // eCos is free software; you can redistribute it and/or modify it under |
| 14 // http://www.redhat.com/ | 14 // the terms of the GNU General Public License as published by the Free |
| 15 // | 15 // Software Foundation; either version 2 or (at your option) any later version. |
| 16 // Software distributed under the License is distributed on an "AS IS" | 16 // |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | 17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
| 18 // License for the specific language governing rights and limitations under | 18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 19 // the License. | 19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 20 // | 20 // for more details. |
| 21 // The Original Code is eCos - Embedded Configurable Operating System, | 21 // |
| 22 // released September 30, 1998. | 22 // You should have received a copy of the GNU General Public License along |
| 23 // | 23 // with eCos; if not, write to the Free Software Foundation, Inc., |
| 24 // The Initial Developer of the Original Code is Red Hat. | 24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 25 // Portions created by Red Hat are | 25 // |
| 26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | 26 // As a special exception, if other files instantiate templates or use macros |
| 27 // All Rights Reserved. | 27 // or inline functions from this file, or you compile this file and link it |
| 28 // ------------------------------------------- | 28 // with other works to produce a work based on this file, this file does not |
| 29 // | 29 // by itself cause the resulting work to be covered by the GNU General Public |
| 30 //####COPYRIGHTEND#### | 30 // License. However the source code for this file must still be made available |
| 31 // in accordance with section (3) of the GNU General Public License. | |
| 32 // | |
| 33 // This exception does not invalidate any other reasons why a work based on | |
| 34 // this file might be covered by the GNU General Public License. | |
| 35 // | |
| 36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | |
| 37 // at http://sources.redhat.com/ecos/ecos-license | |
| 38 // ------------------------------------------- | |
| 39 //####ECOSGPLCOPYRIGHTEND#### | |
| 31 //========================================================================== | 40 //========================================================================== |
| 32 //#####DESCRIPTIONBEGIN#### | 41 //#####DESCRIPTIONBEGIN#### |
| 33 // | 42 // |
| 34 // Author(s): dsm | 43 // Author(s): dsm |
| 35 // Contributors: dsm, jlarmour | 44 // Contributors: dsm, jlarmour |
| 55 int cyg_test_is_simulator = 1; // set this anyway | 64 int cyg_test_is_simulator = 1; // set this anyway |
| 56 #else | 65 #else |
| 57 int cyg_test_is_simulator = 0; // infrastructure changes as necessary | 66 int cyg_test_is_simulator = 0; // infrastructure changes as necessary |
| 58 #endif | 67 #endif |
| 59 | 68 |
| 69 //---------------------------------------------------------------------------- | |
| 70 // Functions ensuring we get pretty printed assertion messages in the | |
| 71 // farm - regardless of configuration and GDB capabilities. | |
| 72 | |
| 73 #ifdef CYGPKG_KERNEL | |
| 74 # include <pkgconf/kernel.h> | |
| 75 # include <cyg/kernel/thread.hxx> // thread id to print | |
| 76 # include <cyg/kernel/thread.inl> // ancillaries for above | |
| 77 #endif | |
| 78 | |
| 79 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT | |
| 80 #include <cyg/hal/hal_if.h> | |
| 81 #endif | |
| 82 | |
| 83 static inline const char *trim_file(const char *file) | |
| 84 { | |
| 85 if ( NULL == file ) | |
| 86 file = "<nofile>"; | |
| 87 | |
| 88 const char *f = file; | |
| 89 | |
| 90 while( *f ) f++; | |
| 91 | |
| 92 while( *f != '/' && f != file ) f--; | |
| 93 | |
| 94 return f==file?f:(f+1); | |
| 95 } | |
| 96 | |
| 97 static inline const char *trim_func(const char *func) | |
| 98 { | |
| 99 static char fbuf[100]; | |
| 100 int i; | |
| 101 | |
| 102 if ( NULL == func ) | |
| 103 func = "<nofunc>"; | |
| 104 | |
| 105 for( i = 0; func[i] && func[i] != '(' ; i++ ) | |
| 106 fbuf[i] = func[i]; | |
| 107 | |
| 108 fbuf[i++] = '('; | |
| 109 fbuf[i++] = ')'; | |
| 110 fbuf[i ] = 0; | |
| 111 | |
| 112 return &fbuf[0]; | |
| 113 } | |
| 114 | |
| 115 static inline | |
| 116 void write_lnum( cyg_uint32 lnum) | |
| 117 { | |
| 118 diag_write_char('['); | |
| 119 diag_write_dec(lnum); | |
| 120 diag_write_char(']'); | |
| 121 } | |
| 122 | |
| 123 static inline | |
| 124 void write_thread_id() | |
| 125 { | |
| 126 #ifdef CYGPKG_KERNEL | |
| 127 Cyg_Thread *t = Cyg_Thread::self(); | |
| 128 cyg_uint16 tid = 0xFFFF; | |
| 129 | |
| 130 if( t != NULL ) tid = t->get_unique_id(); | |
| 131 | |
| 132 diag_write_char('<'); | |
| 133 diag_write_hex(tid); | |
| 134 diag_write_char('>'); | |
| 135 #endif | |
| 136 } | |
| 137 | |
| 138 // Called from the CYG_ASSERT_DOCALL macro | |
| 139 externC void | |
| 140 cyg_assert_msg( const char *psz_func, const char *psz_file, | |
| 141 cyg_uint32 linenum, const char *psz_msg ) __THROW | |
| 142 { | |
| 143 cyg_uint32 old_ints; | |
| 144 | |
| 145 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 146 DIAG_DEVICE_START_SYNC(); | |
| 147 | |
| 148 #ifdef CYG_HAL_DIAG_LOCK | |
| 149 CYG_HAL_DIAG_LOCK(); | |
| 150 #endif | |
| 151 | |
| 152 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT | |
| 153 { | |
| 154 int cur_console; | |
| 155 int i; | |
| 156 cur_console = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); | |
| 157 if ( CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET, | |
| 158 "info_console_force", &i, | |
| 159 CYGNUM_FLASH_CFG_OP_CONFIG_BOOL ) ) | |
| 160 if ( i ) | |
| 161 if ( CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET, | |
| 162 "info_console_number", &i, | |
| 163 CYGNUM_FLASH_CFG_OP_CONFIG_INT ) ) | |
| 164 // Then i is the console to force it to: | |
| 165 CYGACC_CALL_IF_SET_CONSOLE_COMM( i ); | |
| 166 #endif | |
| 167 diag_write_string("ASSERT FAIL: "); | |
| 168 write_thread_id(); | |
| 169 diag_write_string(trim_file(psz_file)); | |
| 170 write_lnum(linenum); | |
| 171 diag_write_string(trim_func(psz_func)); | |
| 172 diag_write_char(' '); | |
| 173 diag_write_string(psz_msg); | |
| 174 diag_write_char('\n'); | |
| 175 | |
| 176 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT | |
| 177 CYGACC_CALL_IF_SET_CONSOLE_COMM(cur_console); | |
| 178 } | |
| 179 #endif | |
| 180 #ifdef CYG_HAL_DIAG_UNLOCK | |
| 181 CYG_HAL_DIAG_UNLOCK(); | |
| 182 #endif | |
| 183 | |
| 184 DIAG_DEVICE_END_SYNC(); | |
| 185 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 186 } | |
| 60 | 187 |
| 61 externC void | 188 externC void |
| 62 cyg_test_init(void) | 189 cyg_test_init(void) |
| 63 { | 190 { |
| 64 // currently nothing | 191 // currently nothing |
| 119 | 246 |
| 120 // This is an appropriate function to set a breakpoint on | 247 // This is an appropriate function to set a breakpoint on |
| 121 externC void | 248 externC void |
| 122 cyg_test_exit(void) | 249 cyg_test_exit(void) |
| 123 { | 250 { |
| 251 // workaround SH dwarf2 gen problem | |
| 252 #if defined(CYGPKG_HAL_SH) && (__GNUC__ >= 3) | |
| 253 static volatile int i; | |
| 254 i++; | |
| 255 #endif | |
| 124 #ifdef CYGHWR_TEST_PROGRAM_EXIT | 256 #ifdef CYGHWR_TEST_PROGRAM_EXIT |
| 125 CYGHWR_TEST_PROGRAM_EXIT(); | 257 CYGHWR_TEST_PROGRAM_EXIT(); |
| 126 #endif | 258 #endif |
| 127 | 259 |
| 128 for(;;) | 260 for(;;) |
