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