1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 25 #ifndef _OSL_DIAGNOSE_H_ 26 #define _OSL_DIAGNOSE_H_ 27 28 #include <sal/types.h> 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif /* __cplusplus */ 33 34 /* ////////////////////////////////////////////////////////////////////////// 35 Diagnostic support 36 */ 37 38 void SAL_CALL osl_breakDebug(void); 39 sal_Bool SAL_CALL osl_assertFailedLine(const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage); 40 void SAL_CALL osl_trace(const sal_Char* pszFormat, ...); 41 sal_Int32 SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszErrorMessage); 42 43 /* 44 For message delivery 45 */ 46 47 /** a message delivery function which receives a pre-formatted message string 48 */ 49 typedef void (SAL_CALL *pfunc_osl_printDebugMessage)( const sal_Char * pszMessage ); 50 51 /** a message delivery function which receives detailed information about where the message was triggered 52 */ 53 typedef void (SAL_CALL *pfunc_osl_printDetailedDebugMessage)( const sal_Char * pszFileName, sal_Int32 nLine, const sal_Char* pszMessage ); 54 55 /** sets a message delivery function 56 57 The function set here is ignored if a function for detailed message information 58 (pfunc_osl_printDetailedDebugMessage) has been set. 59 60 The given message handler must be able to cope with a <NULL/> message. 61 */ 62 pfunc_osl_printDebugMessage SAL_CALL osl_setDebugMessageFunc( pfunc_osl_printDebugMessage pNewFunc ); 63 64 /** sets a delivery function for detailed message information. 65 66 The given message handler must be able to cope with a <NULL/> message. 67 */ 68 pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pfunc_osl_printDetailedDebugMessage pNewFunc ); 69 70 #ifdef __cplusplus 71 } 72 #endif 73 74 #define OSL_THIS_FILE __FILE__ 75 76 /* the macro OSL_THIS_FUNC is intended to be an office internal macro for now */ 77 #define OSL_THIS_FUNC "<unknown>" 78 79 /* the macro OSL_TO_STRING is intended to be an office internal macro for now */ 80 #define OSL_TO_STRING( x ) #x 81 82 /* the macro OSL_MACRO_VALUE_TO_STRING is intended to be an office internal macro for now */ 83 #define OSL_MACRO_VALUE_TO_STRING( x ) OSL_TO_STRING( x ) 84 85 /* the macro OSL_LOG_PREFIX is intended to be an office internal macro for now */ 86 #define OSL_LOG_PREFIX OSL_THIS_FILE ":" OSL_THIS_FUNC ":" OSL_MACRO_VALUE_TO_STRING( __LINE__ ) "; " 87 88 #define OSL_DEBUG_ONLY(s) _OSL_DEBUG_ONLY(s) 89 #define OSL_TRACE _OSL_TRACE 90 #define OSL_ASSERT(c) _OSL_ASSERT(c, OSL_THIS_FILE, __LINE__) 91 #define OSL_ENSURE(c, m) _OSL_ENSURE(c, OSL_THIS_FILE, __LINE__, m) 92 93 #define OSL_VERIFY(c) do { if (!(c)) OSL_ASSERT(0); } while (0) 94 #define OSL_PRECOND(c, m) OSL_ENSURE(c, m) 95 #define OSL_POSTCOND(c, m) OSL_ENSURE(c, m) 96 97 98 #ifdef __cplusplus 99 #define _OSL_GLOBAL :: 100 #else 101 #define _OSL_GLOBAL 102 #endif /* __cplusplus */ 103 104 #ifdef _WIN16 105 #if OSL_DEBUG_LEVEL > 0 106 #undef OSL_DEBUG_LEVEL 107 #define OSL_DEBUG_LEVEL 0 108 #endif 109 #endif 110 111 112 113 #if OSL_DEBUG_LEVEL > 0 114 115 #define _OSL_DEBUG_ONLY(f) (f) 116 #define _OSL_ASSERT(c, f, l) \ 117 do \ 118 { \ 119 if (!(c) && _OSL_GLOBAL osl_assertFailedLine(f, l, 0)) \ 120 _OSL_GLOBAL osl_breakDebug(); \ 121 } while (0) 122 123 #define _OSL_ENSURE(c, f, l, m) \ 124 do \ 125 { \ 126 if (!(c) && _OSL_GLOBAL osl_assertFailedLine(f, l, m)) \ 127 _OSL_GLOBAL osl_breakDebug(); \ 128 } while (0) 129 130 #else 131 132 #define _OSL_DEBUG_ONLY(f) ((void)0) 133 #define _OSL_ASSERT(c, f, l) ((void)0) 134 #define _OSL_ENSURE(c, f, l, m) ((void)0) 135 136 #endif /* OSL_DEBUG_LEVEL */ 137 138 #if OSL_DEBUG_LEVEL > 1 139 140 #define _OSL_TRACE _OSL_GLOBAL osl_trace 141 142 #else 143 144 #define _OSL_TRACE 1 ? ((void)0) : _OSL_GLOBAL osl_trace 145 146 #endif /* OSL_DEBUG_LEVEL */ 147 148 #endif /* _OSL_DIAGNOSE_H_ */ 149