kmp_debug.c

Go to the documentation of this file.
00001 /*
00002  * kmp_debug.c -- debug utilities for the Guide library
00003  * $Revision: 42150 $
00004  * $Date: 2013-03-15 15:40:38 -0500 (Fri, 15 Mar 2013) $
00005  */
00006 
00007 /* <copyright>
00008     Copyright (c) 1997-2013 Intel Corporation.  All Rights Reserved.
00009 
00010     Redistribution and use in source and binary forms, with or without
00011     modification, are permitted provided that the following conditions
00012     are met:
00013 
00014       * Redistributions of source code must retain the above copyright
00015         notice, this list of conditions and the following disclaimer.
00016       * Redistributions in binary form must reproduce the above copyright
00017         notice, this list of conditions and the following disclaimer in the
00018         documentation and/or other materials provided with the distribution.
00019       * Neither the name of Intel Corporation nor the names of its
00020         contributors may be used to endorse or promote products derived
00021         from this software without specific prior written permission.
00022 
00023     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027     HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 
00035 
00036 ------------------------------------------------------------------------
00037 
00038     Portions of this software are protected under the following patents:
00039         U.S. Patent 5,812,852
00040         U.S. Patent 6,792,599
00041         U.S. Patent 7,069,556
00042         U.S. Patent 7,328,433
00043         U.S. Patent 7,500,242
00044 
00045 </copyright> */
00046 
00047 #include "kmp.h"
00048 #include "kmp_debug.h" /* really necessary? */
00049 #include "kmp_i18n.h"
00050 #include "kmp_io.h"
00051 
00052 #ifdef KMP_DEBUG
00053 void
00054 __kmp_debug_printf_stdout( char const * format, ... )
00055 {
00056     va_list ap;
00057     va_start( ap, format );
00058 
00059     __kmp_vprintf( kmp_out, format, ap );
00060 
00061     va_end(ap);
00062 }
00063 #endif
00064 
00065 void
00066 __kmp_debug_printf( char const * format, ... )
00067 {
00068     va_list ap;
00069     va_start( ap, format );
00070 
00071     __kmp_vprintf( kmp_err, format, ap );
00072 
00073     va_end( ap );
00074 }
00075 
00076 #ifdef KMP_USE_ASSERT
00077     int
00078     __kmp_debug_assert(
00079         char const *  msg,
00080         char const *  file,
00081         int           line
00082     ) {
00083 
00084         if ( file == NULL ) {
00085             file = KMP_I18N_STR( UnknownFile );
00086         } else {
00087             // Remove directories from path, leave only file name. File name is enough, there is no need
00088             // in bothering developers and customers with full paths.
00089             char const * slash = strrchr( file, '/' );
00090             if ( slash != NULL ) {
00091                 file = slash + 1;
00092             }; // if
00093         }; // if
00094 
00095         #ifdef KMP_DEBUG
00096             __kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
00097             __kmp_debug_printf( "Assertion failure at %s(%d): %s.\n", file, line, msg );
00098             __kmp_release_bootstrap_lock( & __kmp_stdio_lock );
00099             #ifdef USE_ASSERT_BREAK
00100                 #if KMP_OS_WINDOWS
00101                     DebugBreak();
00102                 #endif
00103             #endif // USE_ASSERT_BREAK
00104             #ifdef USE_ASSERT_STALL
00105                 /*    __kmp_infinite_loop(); */
00106                 for(;;);
00107             #endif // USE_ASSERT_STALL
00108             #ifdef USE_ASSERT_SEG
00109                 {
00110                     int volatile * ZERO = (int*) 0;
00111                     ++ (*ZERO);
00112                 }
00113             #endif // USE_ASSERT_SEG
00114         #endif
00115 
00116         __kmp_msg(
00117             kmp_ms_fatal,
00118             KMP_MSG( AssertionFailure, file, line ),
00119             KMP_HNT( SubmitBugReport ),
00120             __kmp_msg_null
00121         );
00122 
00123         return 0;
00124 
00125     } // __kmp_debug_assert
00126 
00127 #endif // KMP_USE_ASSERT
00128 
00129 /* Dump debugging buffer to stderr */
00130 void
00131 __kmp_dump_debug_buffer( void )
00132 {
00133     if ( __kmp_debug_buffer != NULL ) {
00134         int i;
00135         int dc = __kmp_debug_count;
00136         char *db = & __kmp_debug_buffer[ (dc % __kmp_debug_buf_lines) * __kmp_debug_buf_chars ];
00137         char *db_end = & __kmp_debug_buffer[ __kmp_debug_buf_lines * __kmp_debug_buf_chars ];
00138         char *db2;
00139 
00140         __kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
00141         __kmp_printf_no_lock( "\nStart dump of debugging buffer (entry=%d):\n",
00142                  dc % __kmp_debug_buf_lines );
00143 
00144         for ( i = 0; i < __kmp_debug_buf_lines; i++ ) {
00145 
00146             if ( *db != '\0' ) {
00147                 /* Fix up where no carriage return before string termination char */
00148                 for ( db2 = db + 1; db2 < db + __kmp_debug_buf_chars - 1; db2 ++) {
00149                     if ( *db2 == '\0' ) {
00150                         if ( *(db2-1) != '\n' ) { *db2 = '\n'; *(db2+1) = '\0'; }
00151                         break;
00152                     }
00153                 }
00154                 /* Handle case at end by shortening the printed message by one char if necessary */
00155                 if ( db2 == db + __kmp_debug_buf_chars - 1 &&
00156                      *db2 == '\0' && *(db2-1) != '\n' ) {
00157                     *(db2-1) = '\n';
00158                 }
00159 
00160                 __kmp_printf_no_lock( "%4d: %.*s", i, __kmp_debug_buf_chars, db );
00161                 *db = '\0'; /* only let it print once! */
00162             }
00163 
00164             db += __kmp_debug_buf_chars;
00165             if ( db >= db_end )
00166                 db = __kmp_debug_buffer;
00167         }
00168 
00169         __kmp_printf_no_lock( "End dump of debugging buffer (entry=%d).\n\n",
00170                  ( dc+i-1 ) % __kmp_debug_buf_lines );
00171         __kmp_release_bootstrap_lock( & __kmp_stdio_lock );
00172     }
00173 }

Generated on 25 Aug 2013 for libomp_oss by  doxygen 1.6.1