1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
/*
* This file is part of the Score-P software ecosystem (http://www.score-p.org)
*
* Copyright (c) 2009-2012,
* RWTH Aachen University, Germany
*
* Copyright (c) 2009-2012,
* Gesellschaft fuer numerische Simulation mbH Braunschweig, Germany
*
* Copyright (c) 2009-2012, 2014, 2017,
* Technische Universitaet Dresden, Germany
*
* Copyright (c) 2009-2012,
* University of Oregon, Eugene, USA
*
* Copyright (c) 2009-2012, 2016, 2021-2023,
* Forschungszentrum Juelich GmbH, Germany
*
* Copyright (c) 2009-2012,
* German Research School for Simulation Sciences GmbH, Juelich/Aachen, Germany
*
* Copyright (c) 2009-2012,
* Technische Universitaet Muenchen, Germany
*
* This software may be modified and distributed under the terms of
* a BSD-style license. See the COPYING file in the package base
* directory for details.
*
*/
#ifndef UTILS_ERROR_H
#define UTILS_ERROR_H
/**
* @file
* @ingroup UTILS_Exception_module
*
* @brief Module for error handling in SCOREP.
*
*/
#include <errno.h>
#include <stdint.h>
#include <UTILS_Portability.h>
/*
* Include the package specific error codes.
*/
#include PACKAGE_ERROR_CODES_HEADER
/*
* The package specific name for error codes.
*
* This should be private, but to make this header readable is here defined.
*/
#define PACKAGE_ErrorCode PACKAGE_MANGLE_NAME( ErrorCode )
UTILS_BEGIN_C_DECLS
/**
* @def UTILS_ERROR
* This is a prep function, which delegates error information to the error
* callback.
* @ingroup UTILS_Exception_module
*/
#define UTILS_ERROR( errCode, ... ) \
UTILS_Error_Handler( AFS_PACKAGE_SRCDIR, \
__FILE__, \
__LINE__, \
UTILS_FUNCTION_NAME, \
errCode, \
__VA_ARGS__ )
/**
* Emit a warning.
*/
#define UTILS_WARNING( ... ) \
UTILS_Error_Handler( AFS_PACKAGE_SRCDIR, \
__FILE__, \
__LINE__, \
UTILS_FUNCTION_NAME, \
PACKAGE_MANGLE_NAME( WARNING ), \
__VA_ARGS__ )
/**
* Emit a warning, but only on first occurrence
*/
#define UTILS_WARN_ONCE( ... ) \
do { \
static int utils_warn_once_##__LINE__; \
if ( !utils_warn_once_##__LINE__ ) \
{ \
utils_warn_once_##__LINE__ = 1; \
UTILS_WARNING( __VA_ARGS__ ); \
} \
} while ( 0 )
/**
* Inform the user about not yet implemented functions by printing the function name and the source file.
*/
#define UTILS_NOT_YET_IMPLEMENTED() UTILS_WARN_ONCE( "Not yet implemented" )
/**
* Use this to print a deprecation message once on first usage of the deprecated
* entity.
*/
#define UTILS_DEPRECATED( ... ) \
do { \
static int utils_deprecated_##__LINE__; \
if ( !utils_deprecated_##__LINE__ ) \
{ \
utils_deprecated_##__LINE__ = 1; \
UTILS_Error_Handler( AFS_PACKAGE_SRCDIR, \
__FILE__, \
__LINE__, \
UTILS_FUNCTION_NAME, \
PACKAGE_MANGLE_NAME( DEPRECATED ), \
__VA_ARGS__ ); \
} \
} while ( 0 )
/**
* Delegation error handler function, which is used by the prep UTILS_ERROR to
* to avert that external programmers use the function pointer directly.
*
* @param function : Name of the function where the error appeared
* @param file : Name of the source-code file where the error appeared
* @param line : Line number in the source-code where the error appeared
* @param errorCode : Error Code
* @param msgFormatString : Format string like it is used at the printf family.
*
* @returns Should return the ErrorCode
* @ingroup UTILS_Exception_module
*/
#define UTILS_Error_Handler PACKAGE_MANGLE_NAME( UTILS_Error_Handler )
PACKAGE_ErrorCode
UTILS_Error_Handler( const char* srcdir,
const char* file,
uint64_t line,
const char* function,
PACKAGE_ErrorCode errorCode,
const char* msgFormatString,
... );
/**
* @def UTILS_ERROR_POSIX
* This is a prep function, which is able to handle external POSIX
* error codes with the SCOREP error handling system.
*
* @param ... The first argument needs to be a string constant.
*
* @ingroup UTILS_Exception_module
*/
#define UTILS_ERROR_POSIX( ... ) \
UTILS_ERROR( UTILS_Error_FromPosix( errno ), "POSIX: " __VA_ARGS__ )
/**
* Translates a POSIX error code into a SCOREP error code.
*
* @param posixErrorCode : Error Code
*
* @returns Returns a UTILS error code (see the package depended ErrorCodes.h)
* @ingroup UTILS_Exception_module
*/
#define UTILS_Error_FromPosix PACKAGE_MANGLE_NAME( UTILS_Error_FromPosix )
PACKAGE_ErrorCode
UTILS_Error_FromPosix( int posixErrorCode );
#define HAVE_UTILS_NO_ASSERT UTILS_JOIN_SYMS( HAVE_, PACKAGE_MANGLE_NAME( NO_ASSERT ) )
/**
* @def UTILS_ASSERT
* Definition of the utils assertion macro. It evaluates an @a expression. If it is false,
* an error message is output and the program is aborted. To use the assertion,
* HAVE_PACKAGE_NO_ASSERT must not be defined.
* @param expression A logical expression which should be verified. If it is zero the
* assertion fails.
*/
#if !HAVE( UTILS_NO_ASSERT )
#define UTILS_ASSERT( expression ) \
( ( expression ) ? ( void )0 : \
UTILS_Error_Abort( AFS_PACKAGE_SRCDIR, \
__FILE__, \
__LINE__, \
UTILS_FUNCTION_NAME, \
"Assertion '" UTILS_STRINGIFY( expression ) "' failed" ) )
#else
#define UTILS_ASSERT( expression ) do { ( void )( expression ); } while ( 0 )
#endif
/**
* @def UTILS_FATAL
*
* Indicates a fatal condition. The program will abort immediately.
*
*/
#define UTILS_FATAL( ... ) \
UTILS_Error_Abort( AFS_PACKAGE_SRCDIR, \
__FILE__, \
__LINE__, \
UTILS_FUNCTION_NAME, \
__VA_ARGS__ )
/**
* @def UTILS_BUG
*
* Indicates an error in the software, not induced by wrong usage of an user.
* The program will abort immediately.
*
*/
#define UTILS_BUG( ... ) \
UTILS_Error_Abort( AFS_PACKAGE_SRCDIR, \
__FILE__, \
__LINE__, \
UTILS_FUNCTION_NAME, \
"Bug: " __VA_ARGS__ )
/**
* @def UTILS_BUG_ON
*
* Same as UTILS_BUG but with an condition.
*
*/
#define UTILS_BUG_ON( expression, ... ) \
( !( expression ) ? ( void )0 : \
UTILS_Error_Abort( AFS_PACKAGE_SRCDIR, \
__FILE__, \
__LINE__, \
UTILS_FUNCTION_NAME, \
"Bug '" #expression "': " __VA_ARGS__ ) )
/**
* This function implements the UTILS_ASSERT, UTILS_FATAL, UTILS_BUG, UTILS_BUG_ON macro.
* It prints an error message and aborts the program. Do not insert calls to this function
* directly, but use the macros instead.
* @param fileName The file name of the file which contains the source code where the
* message was created.
* @param line The line number of the source code line where the debug message
* was created.
* @param functionName A string containing the name of the function where the debug
* message was called.
* @param messageFormatString A printf-like format string.
*/
#define UTILS_Error_Abort PACKAGE_MANGLE_NAME( UTILS_Error_Abort )
UTILS_PREDECL_ATTR_NORETURN void
UTILS_Error_Abort( const char* srcdir,
const char* fileName,
uint64_t line,
const char* functionName,
const char* messageFormatString,
... ) UTILS_POSTDECL_ATTR_NORETURN;
UTILS_END_C_DECLS
#endif /* UTILS_ERROR_H */
|